Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
6216beb3
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
未验证
提交
6216beb3
编写于
7月 19, 2023
作者:
R
ronnywang
提交者:
GitHub
7月 19, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[CustomPass] add register_pass api (#55511)
上级
3f17596a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
1 deletion
+19
-1
paddle/fluid/framework/ir/pass.cc
paddle/fluid/framework/ir/pass.cc
+14
-1
paddle/fluid/framework/ir/pass.h
paddle/fluid/framework/ir/pass.h
+2
-0
paddle/fluid/pybind/pybind.cc
paddle/fluid/pybind/pybind.cc
+3
-0
未找到文件。
paddle/fluid/framework/ir/pass.cc
浏览文件 @
6216beb3
...
@@ -74,6 +74,16 @@ static const std::vector<std::string> xpu_support_subgraph_passes = {
...
@@ -74,6 +74,16 @@ static const std::vector<std::string> xpu_support_subgraph_passes = {
"xpu_delete_cast_op_pass"
,
"xpu_delete_cast_op_pass"
,
};
};
static
std
::
vector
<
std
::
string
>
support_subgraph_generate_passes
;
void
Pass
::
AddSupportSubgraphPass
(
const
std
::
string
&
pass_type
)
{
if
(
std
::
find
(
support_subgraph_generate_passes
.
begin
(),
support_subgraph_generate_passes
.
end
(),
pass_type
)
==
support_subgraph_generate_passes
.
end
())
{
support_subgraph_generate_passes
.
push_back
(
pass_type
);
}
}
Graph
*
Pass
::
Apply
(
Graph
*
graph
)
const
{
Graph
*
Pass
::
Apply
(
Graph
*
graph
)
const
{
VLOG
(
10
)
<<
"start to apply pass "
<<
Type
()
<<
" to graph"
;
VLOG
(
10
)
<<
"start to apply pass "
<<
Type
()
<<
" to graph"
;
CheckPrevPass
();
CheckPrevPass
();
...
@@ -117,7 +127,10 @@ Graph *Pass::Apply(Graph *graph) const {
...
@@ -117,7 +127,10 @@ Graph *Pass::Apply(Graph *graph) const {
subgraph_passes
=
support_subgraph_passes
;
subgraph_passes
=
support_subgraph_passes
;
}
}
if
(
graph
->
IsMainGraph
()
&&
if
(
graph
->
IsMainGraph
()
&&
std
::
count
(
subgraph_passes
.
begin
(),
subgraph_passes
.
end
(),
Type
()))
{
(
std
::
count
(
subgraph_passes
.
begin
(),
subgraph_passes
.
end
(),
Type
())
||
std
::
count
(
support_subgraph_generate_passes
.
begin
(),
support_subgraph_generate_passes
.
end
(),
Type
())))
{
for
(
size_t
i
=
1
;
i
<
graph
->
SubGraphsSize
();
i
++
)
{
for
(
size_t
i
=
1
;
i
<
graph
->
SubGraphsSize
();
i
++
)
{
auto
*
sub_graph
=
graph
->
GetSubGraph
(
i
);
auto
*
sub_graph
=
graph
->
GetSubGraph
(
i
);
if
(
!
sub_graph
->
Has
(
framework
::
ir
::
kParamScopeAttr
))
{
if
(
!
sub_graph
->
Has
(
framework
::
ir
::
kParamScopeAttr
))
{
...
...
paddle/fluid/framework/ir/pass.h
浏览文件 @
6216beb3
...
@@ -168,6 +168,8 @@ class Pass {
...
@@ -168,6 +168,8 @@ class Pass {
virtual
bool
SupportApplyProgramViaGraph
()
const
{
return
true
;
}
virtual
bool
SupportApplyProgramViaGraph
()
const
{
return
true
;
}
static
void
AddSupportSubgraphPass
(
const
std
::
string
&
pass_type
);
protected:
protected:
virtual
void
ApplyImpl
(
Graph
*
graph
UNUSED
)
const
{
virtual
void
ApplyImpl
(
Graph
*
graph
UNUSED
)
const
{
PADDLE_THROW
(
platform
::
errors
::
Unimplemented
(
PADDLE_THROW
(
platform
::
errors
::
Unimplemented
(
...
...
paddle/fluid/pybind/pybind.cc
浏览文件 @
6216beb3
...
@@ -2319,6 +2319,9 @@ All parameter, weight, gradient are variables in Paddle.
...
@@ -2319,6 +2319,9 @@ All parameter, weight, gradient are variables in Paddle.
auto
pass
=
framework
::
ir
::
PassRegistry
::
Instance
().
Get
(
pass_type
);
auto
pass
=
framework
::
ir
::
PassRegistry
::
Instance
().
Get
(
pass_type
);
return
std
::
shared_ptr
<
framework
::
ir
::
Pass
>
(
std
::
move
(
pass
));
return
std
::
shared_ptr
<
framework
::
ir
::
Pass
>
(
std
::
move
(
pass
));
});
});
m
.
def
(
"register_subgraph_pass"
,
[](
const
std
::
string
&
pass_type
)
{
framework
::
ir
::
Pass
::
AddSupportSubgraphPass
(
pass_type
);
});
m
.
def
(
"size_of_dtype"
,
framework
::
SizeOfType
);
m
.
def
(
"size_of_dtype"
,
framework
::
SizeOfType
);
py
::
class_
<
paddle
::
platform
::
ProfilerResult
>
(
m
,
"_ProfilerResult"
)
py
::
class_
<
paddle
::
platform
::
ProfilerResult
>
(
m
,
"_ProfilerResult"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录