Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
b29d260b
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看板
提交
b29d260b
编写于
6月 19, 2020
作者:
Z
zhousiyi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
reuse AddN primitive in opt as AddN will replicated by program_specialize
上级
2cd9649b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
8 addition
and
17 deletion
+8
-17
mindspore/ccsrc/optimizer/irpass/merge_addn.h
mindspore/ccsrc/optimizer/irpass/merge_addn.h
+6
-13
tests/ut/cpp/python_input/gtest_input/optimizer/opt_test.py
tests/ut/cpp/python_input/gtest_input/optimizer/opt_test.py
+2
-4
未找到文件。
mindspore/ccsrc/optimizer/irpass/merge_addn.h
浏览文件 @
b29d260b
...
...
@@ -35,9 +35,6 @@ namespace irpass {
// {{PrimAddNClass}, {prim::kPrimMakeTuple, Ys, Xs}}
class
MergeAddN
:
public
AnfVisitor
{
public:
MergeAddN
()
:
PrimAddN_
(
prim
::
GetPythonOps
(
"AddN"
,
"mindspore.ops.operations"
))
{}
~
MergeAddN
()
override
=
default
;
AnfNodePtr
operator
()(
const
OptimizerPtr
&
optimizer
,
const
AnfNodePtr
&
node
)
override
{
Reset
();
optimizer_
=
optimizer
;
...
...
@@ -47,15 +44,15 @@ class MergeAddN : public AnfVisitor {
return
nullptr
;
}
auto
fg
=
node
->
func_graph
();
// {PrimAddNClass}
auto
addn_node
=
fg
->
NewCNode
({
NewValueNode
(
PrimAddN_
)});
auto
cnode
=
node
->
cast
<
CNodePtr
>
();
auto
addn
=
NewValueNode
(
GetValueNode
(
cnode
->
input
(
0
)));
// {prim::kPrimMakeTuple, Xs, Ys}, {prim::kPrimMakeTuple, Ys, Xs}
(
void
)
args_
.
insert
(
args_
.
begin
(),
NewValueNode
(
prim
::
kPrimMakeTuple
));
auto
fg
=
node
->
func_graph
();
auto
make_node
=
fg
->
NewCNode
(
args_
);
return
fg
->
NewCNode
({
addn
_node
,
make_node
});
return
fg
->
NewCNode
({
addn
,
make_node
});
}
void
Visit
(
const
CNodePtr
&
cnode
)
override
{
...
...
@@ -127,7 +124,6 @@ class MergeAddN : public AnfVisitor {
}
private:
ValuePtr
PrimAddN_
;
OptimizerPtr
optimizer_
{
nullptr
};
std
::
vector
<
AnfNodePtr
>
Xs_
{},
Ys_
{},
args_
{};
bool
is_inner_
{
false
},
is_outer_
{
false
},
is_match_
{
false
};
...
...
@@ -136,9 +132,6 @@ class MergeAddN : public AnfVisitor {
// {PrimAddN, {kPrimMakeTuple, Xs}}
class
AddNZeroFilter
:
public
AnfVisitor
{
public:
AddNZeroFilter
()
:
PrimAddN_
(
prim
::
GetPythonOps
(
"AddN"
,
"mindspore.ops.operations"
))
{}
~
AddNZeroFilter
()
override
=
default
;
AnfNodePtr
operator
()(
const
OptimizerPtr
&
,
const
AnfNodePtr
&
node
)
override
{
Reset
();
AnfVisitor
::
Match
(
prim
::
kPrimAddN
,
{
IsCNode
})(
node
);
...
...
@@ -161,8 +154,9 @@ class AddNZeroFilter : public AnfVisitor {
return
nullptr
;
}
auto
cnode
=
node
->
cast
<
CNodePtr
>
();
auto
addn
=
NewValueNode
(
GetValueNode
(
cnode
->
input
(
0
)));
auto
fg
=
node
->
func_graph
();
auto
addn
=
fg
->
NewCNode
({
NewValueNode
(
PrimAddN_
)});
auto
make_tuple
=
fg
->
NewCNode
(
filtered_Xs_
);
return
fg
->
NewCNode
({
addn
,
make_tuple
});
}
...
...
@@ -193,7 +187,6 @@ class AddNZeroFilter : public AnfVisitor {
}
private:
ValuePtr
PrimAddN_
;
std
::
vector
<
AnfNodePtr
>
filtered_Xs_
{},
Xs_
{};
bool
has_zero_like_
{
false
};
};
...
...
tests/ut/cpp/python_input/gtest_input/optimizer/opt_test.py
浏览文件 @
b29d260b
...
...
@@ -875,7 +875,6 @@ def test_merge_addn(tag):
""" test_merge_addn """
fns
=
FnDict
()
addn
=
P
.
AddN
()
AddN
=
P
.
AddN
@
fns
def
before
(
x
,
y
,
z
,
a
):
...
...
@@ -883,7 +882,7 @@ def test_merge_addn(tag):
@
fns
def
after
(
x
,
y
,
z
,
a
):
return
AddN
()
((
a
,
x
,
y
,
z
))
return
addn
((
a
,
x
,
y
,
z
))
return
fns
[
tag
]
...
...
@@ -892,7 +891,6 @@ def test_addn_zero(tag):
""" test_addn_zero """
fns
=
FnDict
()
addn
=
P
.
AddN
()
AddN
=
P
.
AddN
zero_tensor
=
Primitive
(
'ZerosLike'
)
@
fns
...
...
@@ -901,7 +899,7 @@ def test_addn_zero(tag):
@
fns
def
after
(
x
,
y
,
z
,
a
):
return
AddN
()
((
a
,
z
))
return
addn
((
a
,
z
))
@
fns
def
before_2
(
x
,
y
,
z
,
a
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录