Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
8f29e724
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
8f29e724
编写于
6月 19, 2020
作者:
B
BowenK
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add pass to eliminate depend value
上级
d638578d
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
39 addition
and
0 deletion
+39
-0
mindspore/ccsrc/optimizer/irpass.cc
mindspore/ccsrc/optimizer/irpass.cc
+1
-0
mindspore/ccsrc/optimizer/irpass.h
mindspore/ccsrc/optimizer/irpass.h
+1
-0
mindspore/ccsrc/optimizer/irpass/special_op_eliminate.h
mindspore/ccsrc/optimizer/irpass/special_op_eliminate.h
+13
-0
mindspore/ccsrc/pipeline/pass.cc
mindspore/ccsrc/pipeline/pass.cc
+1
-0
tests/ut/cpp/optimizer/lib_test.cc
tests/ut/cpp/optimizer/lib_test.cc
+8
-0
tests/ut/cpp/python_input/gtest_input/optimizer/opt_test.py
tests/ut/cpp/python_input/gtest_input/optimizer/opt_test.py
+15
-0
未找到文件。
mindspore/ccsrc/optimizer/irpass.cc
浏览文件 @
8f29e724
...
...
@@ -70,6 +70,7 @@ OptimizeIRPassLib::OptimizeIRPassLib() {
same_eliminate_
=
MakeSubstitution
(
SameEliminater
(),
"same_eliminate"
,
prim
::
kPrimSameTypeShape
);
check_bprop_eliminate_
=
MakeSubstitution
(
CheckBpropEliminater
(),
"check_bprop_eliminate"
,
prim
::
kPrimCheckBprop
);
reset_defer_inline_
=
MakeSubstitution
(
ResetDeferInline
(),
"reset_defer_inline"
,
IsValueNode
<
FuncGraph
>
);
depend_value_elim_
=
MakeSubstitution
(
DependValueElim
(),
"depend_value_elim"
,
prim
::
kPrimDepend
);
// Env Item Eliminate
env_get_item_eliminate_
=
MakeSubstitution
(
EnvGetItemEliminater
(),
"env_get_item_eliminate"
,
prim
::
kPrimEnvGetItem
);
...
...
mindspore/ccsrc/optimizer/irpass.h
浏览文件 @
8f29e724
...
...
@@ -48,6 +48,7 @@ class OptimizeIRPassLib {
SubstitutionPtr
same_eliminate_
;
SubstitutionPtr
check_bprop_eliminate_
;
SubstitutionPtr
reset_defer_inline_
;
SubstitutionPtr
depend_value_elim_
;
// Env Item Eliminate
SubstitutionPtr
env_get_item_eliminate_
;
...
...
mindspore/ccsrc/optimizer/irpass/special_op_eliminate.h
浏览文件 @
8f29e724
...
...
@@ -24,9 +24,11 @@
#include "optimizer/optimizer.h"
#include "optimizer/irpass.h"
#include "ir/optimizer_caller.h"
#include "optimizer/irpass/prim_eliminate.h"
#include "ir/visitor.h"
#include "operator/ops.h"
#include "ir/pattern_matcher.h"
namespace
mindspore
{
namespace
opt
{
...
...
@@ -191,6 +193,17 @@ class ZeroLikeFillZero : public AnfVisitor {
AnfNodePtr
y_
{
nullptr
};
PrimitivePtr
PrimFill_
,
PrimShape_
,
PrimDType_
;
};
// {prim::kPrimDepend, X, ValueCond}->X
class
DependValueElim
:
public
OptimizerCaller
{
public:
AnfNodePtr
operator
()(
const
OptimizerPtr
&
,
const
AnfNodePtr
&
node
)
override
{
PatternNode
<
AnfNodePtr
>
x
,
cond
;
MATCH_REPLACE_IF
(
node
,
PPrimitive
(
prim
::
kPrimDepend
,
x
,
cond
),
x
,
IsVNode
(
cond
.
GetNode
(
node
)));
return
nullptr
;
}
};
}
// namespace irpass
}
// namespace opt
}
// namespace mindspore
...
...
mindspore/ccsrc/pipeline/pass.cc
浏览文件 @
8f29e724
...
...
@@ -108,6 +108,7 @@ OptPassGroupMap GetOptPassesA(const opt::irpass::OptimizeIRPassLib &irpass) {
irpass
.
incorporate_env_getitem_
,
irpass
.
incorporate_env_getitem_switch_
,
irpass
.
new_env_get_item_
,
irpass
.
depend_value_elim_
,
});
opt
::
OptPassConfig
a_3
=
opt
::
OptPassConfig
({
irpass
.
same_eliminate_
,
...
...
tests/ut/cpp/optimizer/lib_test.cc
浏览文件 @
8f29e724
...
...
@@ -257,6 +257,14 @@ TEST_F(TestOptLib, test_elim_transpose) {
ASSERT_TRUE
(
CheckOpt
(
before
,
after
,
patterns
));
}
TEST_F
(
TestOptLib
,
test_elim_depend_value
)
{
FuncGraphPtr
before
=
getPyFun
.
CallAndParseRet
(
"test_elim_depend_value"
,
"before"
);
FuncGraphPtr
after
=
getPyFun
.
CallAndParseRet
(
"test_elim_depend_value"
,
"after"
);
auto
patterns
=
std
::
vector
<
SubstitutionPtr
>
({
irpass
.
depend_value_elim_
});
ASSERT_TRUE
(
CheckOpt
(
before
,
after
,
patterns
));
}
TEST_F
(
TestOptLib
,
test_elim_tile_multiply_one
)
{
FuncGraphPtr
before
=
getPyFun
.
CallAndParseRet
(
"test_elim_tile_multiply_one"
,
"before"
);
FuncGraphPtr
after
=
getPyFun
.
CallAndParseRet
(
"test_elim_tile_multiply_one"
,
"after"
);
...
...
tests/ut/cpp/python_input/gtest_input/optimizer/opt_test.py
浏览文件 @
8f29e724
...
...
@@ -494,6 +494,21 @@ def test_elim_transpose(tag):
return
fns
[
tag
]
def
test_elim_depend_value
(
tag
):
""" test_elim_depend_value """
fns
=
FnDict
()
depend
=
P
.
Depend
()
@
fns
def
before
(
x
):
return
depend
(
x
,
None
)
@
fns
def
after
(
x
):
return
x
return
fns
[
tag
]
def
test_elim_tile_multiply_one
(
tag
):
""" test_elim_tile_multiply_one """
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录