Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
dffc331f
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
dffc331f
编写于
6月 10, 2021
作者:
王
王明冬
提交者:
GitHub
6月 10, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make the compatiable pass only check op has pbtxt, test=develop (#33397)
上级
a526b3e0
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
54 addition
and
20 deletion
+54
-20
paddle/fluid/framework/ir/op_compat_sensible_pass.cc
paddle/fluid/framework/ir/op_compat_sensible_pass.cc
+26
-0
paddle/fluid/framework/ir/op_compat_sensible_pass.h
paddle/fluid/framework/ir/op_compat_sensible_pass.h
+1
-20
paddle/fluid/framework/ir/op_compat_sensible_pass_tester.cc
paddle/fluid/framework/ir/op_compat_sensible_pass_tester.cc
+21
-0
paddle/fluid/framework/op_def_api.cc
paddle/fluid/framework/op_def_api.cc
+4
-0
paddle/fluid/framework/op_def_api.h
paddle/fluid/framework/op_def_api.h
+2
-0
未找到文件。
paddle/fluid/framework/ir/op_compat_sensible_pass.cc
浏览文件 @
dffc331f
...
@@ -250,6 +250,32 @@ OpCompat& OpCompatSensiblePass::AddOpCompat(OpCompat&& op_compat) {
...
@@ -250,6 +250,32 @@ OpCompat& OpCompatSensiblePass::AddOpCompat(OpCompat&& op_compat) {
return
*
(
op_compat_judgers_
[
name
]);
return
*
(
op_compat_judgers_
[
name
]);
}
}
//! Tell the Op compability of a subgraph.
bool
OpCompatSensiblePass
::
IsCompat
(
const
GraphPatternDetector
::
subgraph_t
&
subgraph
,
Graph
*
)
const
{
PADDLE_ENFORCE_EQ
(
op_compat_judgers_
.
empty
(),
false
,
platform
::
errors
::
InvalidArgument
(
"At least one OpCompat instance should be added"
));
// Check the all the ops in the subgraph are contained in the
// op_compat.
for
(
auto
&
node_pair
:
subgraph
)
{
if
(
!
node_pair
.
second
->
IsOp
())
continue
;
auto
op_type
=
node_pair
.
second
->
Op
()
->
Type
();
if
(
!
op_compat_judgers_
.
count
(
op_type
))
{
if
(
HasOpDef
(
op_type
))
{
LOG
(
WARNING
)
<<
op_type
<<
"compat not registered!"
;
return
false
;
}
continue
;
}
auto
&
judger
=
*
op_compat_judgers_
.
at
(
op_type
);
if
(
!
judger
.
Judge
(
*
(
node_pair
.
second
->
Op
())))
{
return
false
;
}
}
return
true
;
}
}
// namespace ir
}
// namespace ir
}
// namespace framework
}
// namespace framework
}
// namespace paddle
}
// namespace paddle
paddle/fluid/framework/ir/op_compat_sensible_pass.h
浏览文件 @
dffc331f
...
@@ -195,26 +195,7 @@ class OpCompatSensiblePass : public Pass {
...
@@ -195,26 +195,7 @@ class OpCompatSensiblePass : public Pass {
//! Tell the Op compability of a subgraph.
//! Tell the Op compability of a subgraph.
bool
IsCompat
(
const
GraphPatternDetector
::
subgraph_t
&
subgraph
,
bool
IsCompat
(
const
GraphPatternDetector
::
subgraph_t
&
subgraph
,
Graph
*
g
)
const
{
Graph
*
g
)
const
;
CHECK
(
!
op_compat_judgers_
.
empty
())
<<
"At least one OpCompat instance should be added in the "
"OpCompatSensiblePass."
;
// Check the all the ops in the subgraph are contained in the
// op_compat.
for
(
auto
&
node_pair
:
subgraph
)
{
if
(
!
node_pair
.
second
->
IsOp
())
continue
;
auto
op_type
=
node_pair
.
second
->
Op
()
->
Type
();
if
(
!
op_compat_judgers_
.
count
(
op_type
))
{
LOG
(
WARNING
)
<<
op_type
<<
"compat not registered!"
;
return
false
;
}
auto
&
judger
=
*
op_compat_judgers_
.
at
(
op_type
);
if
(
!
judger
.
Judge
(
*
(
node_pair
.
second
->
Op
())))
{
return
false
;
}
}
return
true
;
}
//! Tell the op compatibility of a single Op.
//! Tell the op compatibility of a single Op.
bool
IsCompat
(
const
OpDesc
&
op_desc
)
const
{
bool
IsCompat
(
const
OpDesc
&
op_desc
)
const
{
...
...
paddle/fluid/framework/ir/op_compat_sensible_pass_tester.cc
浏览文件 @
dffc331f
...
@@ -151,6 +151,10 @@ class OpCompatSensiblePassTest : public OpCompatSensiblePass {
...
@@ -151,6 +151,10 @@ class OpCompatSensiblePassTest : public OpCompatSensiblePass {
public:
public:
OpCompatSensiblePassTest
();
OpCompatSensiblePassTest
();
bool
TestIsCompat
(
const
OpDesc
&
op_desc
)
{
return
IsCompat
(
op_desc
);
}
bool
TestIsCompat
(
const
OpDesc
&
op_desc
)
{
return
IsCompat
(
op_desc
);
}
bool
TestIsCompat
(
const
GraphPatternDetector
::
subgraph_t
&
subgraph
,
Graph
*
g
)
{
return
IsCompat
(
subgraph
,
g
);
}
};
};
OpCompatSensiblePassTest
::
OpCompatSensiblePassTest
()
{
OpCompatSensiblePassTest
::
OpCompatSensiblePassTest
()
{
...
@@ -192,6 +196,23 @@ TEST(OpCompatSensiblePass, IsCompat) {
...
@@ -192,6 +196,23 @@ TEST(OpCompatSensiblePass, IsCompat) {
EXPECT_TRUE
(
test
.
TestIsCompat
(
fc_op
));
EXPECT_TRUE
(
test
.
TestIsCompat
(
fc_op
));
}
}
TEST
(
OpCompatSensiblePass
,
IsCompatFail
)
{
OpCompatSensiblePassTest
test
;
GraphPatternDetector
::
subgraph_t
subgraph
;
PDPattern
pattern
;
PDNode
*
pd_node
=
pattern
.
NewNode
();
ProgramDesc
prog
;
Graph
g
(
prog
);
OpDesc
fc_op
;
fc_op
.
SetType
(
"op1"
);
subgraph
[
pd_node
]
=
g
.
CreateOpNode
(
&
fc_op
);
EXPECT_TRUE
(
test
.
TestIsCompat
(
subgraph
,
&
g
));
fc_op
.
SetType
(
"mul"
);
subgraph
[
pd_node
]
=
g
.
CreateOpNode
(
&
fc_op
);
EXPECT_FALSE
(
test
.
TestIsCompat
(
subgraph
,
&
g
));
}
}
// namespace ir
}
// namespace ir
}
// namespace framework
}
// namespace framework
}
// namespace paddle
}
// namespace paddle
paddle/fluid/framework/op_def_api.cc
浏览文件 @
dffc331f
...
@@ -68,5 +68,9 @@ const proto::OpDef& GetOpDef(const std::string& op_name) {
...
@@ -68,5 +68,9 @@ const proto::OpDef& GetOpDef(const std::string& op_name) {
}
}
return
ops_definition
.
at
(
op_name
);
return
ops_definition
.
at
(
op_name
);
}
}
bool
HasOpDef
(
const
std
::
string
&
op_name
)
{
return
op_def_map
.
find
(
op_name
)
!=
op_def_map
.
end
();
}
}
// namespace framework
}
// namespace framework
}
// namespace paddle
}
// namespace paddle
paddle/fluid/framework/op_def_api.h
浏览文件 @
dffc331f
...
@@ -19,5 +19,7 @@
...
@@ -19,5 +19,7 @@
namespace
paddle
{
namespace
paddle
{
namespace
framework
{
namespace
framework
{
const
proto
::
OpDef
&
GetOpDef
(
const
std
::
string
&
op_name
);
const
proto
::
OpDef
&
GetOpDef
(
const
std
::
string
&
op_name
);
bool
HasOpDef
(
const
std
::
string
&
op_name
);
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录