Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
5406699d
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
5406699d
编写于
9月 06, 2023
作者:
Y
Yuanle Liu
提交者:
GitHub
9月 06, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[IR&PASS] fix constant_folding_pass and add use_count api for Value (#56967)
上级
d121cf29
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
28 addition
and
15 deletion
+28
-15
paddle/fluid/ir/transforms/constant_folding_pass.cc
paddle/fluid/ir/transforms/constant_folding_pass.cc
+6
-8
paddle/ir/core/value.cc
paddle/ir/core/value.cc
+9
-0
paddle/ir/core/value.h
paddle/ir/core/value.h
+2
-0
paddle/ir/pass/pass.h
paddle/ir/pass/pass.h
+1
-1
paddle/ir/pattern_rewrite/pattern_rewrite_driver.cc
paddle/ir/pattern_rewrite/pattern_rewrite_driver.cc
+9
-5
test/cpp/ir/pattern_rewrite/pattern_rewrite_test.cc
test/cpp/ir/pattern_rewrite/pattern_rewrite_test.cc
+1
-1
未找到文件。
paddle/fluid/ir/transforms/constant_folding_pass.cc
浏览文件 @
5406699d
...
@@ -92,14 +92,13 @@ class ConstantFoldingPattern : public ir::RewritePattern {
...
@@ -92,14 +92,13 @@ class ConstantFoldingPattern : public ir::RewritePattern {
}
}
// Execute program
// Execute program
paddle
::
framework
::
interpreter
::
ExecutionConfig
exe_config
;
exe_config_
.
create_local_scope
=
false
;
exe_config
.
create_local_scope
=
false
;
paddle
::
framework
::
InterpreterCore
core
(
paddle
::
framework
::
InterpreterCore
core
(
phi
::
CPUPlace
{},
phi
::
CPUPlace
{},
fetch_var_names
,
fetch_var_names
,
paddle
::
dialect
::
PdOpLowerToKernelPass
(
temp_program
.
get
()),
paddle
::
dialect
::
PdOpLowerToKernelPass
(
temp_program
.
get
()),
&
scope_
,
&
scope_
,
exe_config
);
exe_config
_
);
paddle
::
framework
::
FetchList
fetch_list
=
core
.
Run
({});
paddle
::
framework
::
FetchList
fetch_list
=
core
.
Run
({});
...
@@ -112,6 +111,7 @@ class ConstantFoldingPattern : public ir::RewritePattern {
...
@@ -112,6 +111,7 @@ class ConstantFoldingPattern : public ir::RewritePattern {
std
::
string
param_name
=
std
::
string
param_name
=
"@constant_folding_pass@_"
+
std
::
to_string
(
suffix_
++
);
"@constant_folding_pass@_"
+
std
::
to_string
(
suffix_
++
);
exe_config_
.
skip_gc_vars
.
insert
(
param_name
);
auto
*
param_var
=
scope_
.
Var
(
param_name
);
auto
*
param_var
=
scope_
.
Var
(
param_name
);
auto
*
param_tensor
=
param_var
->
GetMutable
<
phi
::
DenseTensor
>
();
auto
*
param_tensor
=
param_var
->
GetMutable
<
phi
::
DenseTensor
>
();
...
@@ -180,13 +180,11 @@ class ConstantFoldingPattern : public ir::RewritePattern {
...
@@ -180,13 +180,11 @@ class ConstantFoldingPattern : public ir::RewritePattern {
}
}
private:
private:
static
size_t
suffix_
;
inline
static
size_t
suffix_
{
0
};
static
paddle
::
framework
::
Scope
scope_
;
inline
static
paddle
::
framework
::
Scope
scope_
{};
inline
static
paddle
::
framework
::
interpreter
::
ExecutionConfig
exe_config_
{};
};
};
size_t
ConstantFoldingPattern
::
suffix_
=
0
;
paddle
::
framework
::
Scope
ConstantFoldingPattern
::
scope_
=
{};
class
ConstantFoldingPass
:
public
ir
::
Pass
{
class
ConstantFoldingPass
:
public
ir
::
Pass
{
public:
public:
// TODO(liuyuanle): Naming convention for pass.
// TODO(liuyuanle): Naming convention for pass.
...
...
paddle/ir/core/value.cc
浏览文件 @
5406699d
...
@@ -13,6 +13,9 @@
...
@@ -13,6 +13,9 @@
// limitations under the License.
// limitations under the License.
#include "paddle/ir/core/value.h"
#include "paddle/ir/core/value.h"
#include <cstddef>
#include "paddle/ir/core/enforce.h"
#include "paddle/ir/core/enforce.h"
#include "paddle/ir/core/operation.h"
#include "paddle/ir/core/operation.h"
#include "paddle/ir/core/value_impl.h"
#include "paddle/ir/core/value_impl.h"
...
@@ -128,6 +131,12 @@ bool Value::HasOneUse() const {
...
@@ -128,6 +131,12 @@ bool Value::HasOneUse() const {
return
impl_
->
HasOneUse
();
return
impl_
->
HasOneUse
();
}
}
size_t
Value
::
use_count
()
const
{
size_t
count
=
0
;
for
(
auto
it
=
use_begin
();
it
!=
use_end
();
++
it
)
count
++
;
return
count
;
}
void
Value
::
ReplaceUsesWithIf
(
void
Value
::
ReplaceUsesWithIf
(
Value
new_value
,
Value
new_value
,
const
std
::
function
<
bool
(
OpOperand
)
>
&
should_replace
)
const
{
const
std
::
function
<
bool
(
OpOperand
)
>
&
should_replace
)
const
{
...
...
paddle/ir/core/value.h
浏览文件 @
5406699d
...
@@ -123,6 +123,8 @@ class IR_API Value {
...
@@ -123,6 +123,8 @@ class IR_API Value {
bool
HasOneUse
()
const
;
bool
HasOneUse
()
const
;
size_t
use_count
()
const
;
friend
struct
std
::
hash
<
Value
>
;
friend
struct
std
::
hash
<
Value
>
;
void
ReplaceUsesWithIf
(
void
ReplaceUsesWithIf
(
...
...
paddle/ir/pass/pass.h
浏览文件 @
5406699d
...
@@ -78,7 +78,7 @@ class IR_API Pass {
...
@@ -78,7 +78,7 @@ class IR_API Pass {
virtual
~
Pass
();
virtual
~
Pass
();
std
::
string
name
()
const
{
return
pass_info
().
name
;
}
const
std
::
string
&
name
()
const
{
return
pass_info
().
name
;
}
const
detail
::
PassInfo
&
pass_info
()
const
{
return
pass_info_
;
}
const
detail
::
PassInfo
&
pass_info
()
const
{
return
pass_info_
;
}
...
...
paddle/ir/pattern_rewrite/pattern_rewrite_driver.cc
浏览文件 @
5406699d
...
@@ -131,6 +131,9 @@ class GreedyPatternRewriteDriver : public ir::PatternRewriter {
...
@@ -131,6 +131,9 @@ class GreedyPatternRewriteDriver : public ir::PatternRewriter {
for
(
uint32_t
i
=
0
;
i
<
op
->
num_operands
();
++
i
)
{
for
(
uint32_t
i
=
0
;
i
<
op
->
num_operands
();
++
i
)
{
AddOperandToWorklist
(
op
->
operand_source
(
i
));
AddOperandToWorklist
(
op
->
operand_source
(
i
));
}
}
if
(
op
->
num_regions
()
==
0
)
{
RemoveFromWorklist
(
op
);
}
else
{
for
(
uint32_t
i
=
0
;
i
<
op
->
num_regions
();
++
i
)
{
for
(
uint32_t
i
=
0
;
i
<
op
->
num_regions
();
++
i
)
{
auto
&
region
=
op
->
region
(
i
);
auto
&
region
=
op
->
region
(
i
);
for
(
auto
&
block
:
region
)
{
for
(
auto
&
block
:
region
)
{
...
@@ -139,6 +142,7 @@ class GreedyPatternRewriteDriver : public ir::PatternRewriter {
...
@@ -139,6 +142,7 @@ class GreedyPatternRewriteDriver : public ir::PatternRewriter {
}
}
}
}
}
}
}
if
(
config_
.
strict_mode
!=
ir
::
GreedyRewriteStrictness
::
AnyOp
)
{
if
(
config_
.
strict_mode
!=
ir
::
GreedyRewriteStrictness
::
AnyOp
)
{
strict_mode_filtered_ops_
.
erase
(
op
);
strict_mode_filtered_ops_
.
erase
(
op
);
...
...
test/cpp/ir/pattern_rewrite/pattern_rewrite_test.cc
浏览文件 @
5406699d
...
@@ -1097,7 +1097,7 @@ TEST(pattern_rewrite, Patterns) {
...
@@ -1097,7 +1097,7 @@ TEST(pattern_rewrite, Patterns) {
ir
::
PassManager
pm
(
ctx
);
ir
::
PassManager
pm
(
ctx
);
pm
.
AddPass
(
std
::
make_unique
<
TestPass
>
());
pm
.
AddPass
(
std
::
make_unique
<
TestPass
>
());
//
pm.AddPass(ir::CreateConstantFoldingPass());
pm
.
AddPass
(
ir
::
CreateConstantFoldingPass
());
pm
.
AddPass
(
ir
::
CreateDeadCodeEliminationPass
());
pm
.
AddPass
(
ir
::
CreateDeadCodeEliminationPass
());
pm
.
EnablePassTiming
();
pm
.
EnablePassTiming
();
pm
.
EnableIRPrinting
();
pm
.
EnableIRPrinting
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录