Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2301_77200941
mindspore
提交
e95b4249
M
mindspore
项目概览
2301_77200941
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e95b4249
编写于
8月 24, 2020
作者:
W
WilliamLian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix circle bug of opt depend && merge cast
上级
e3899c55
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
38 addition
and
8 deletion
+38
-8
mindspore/ccsrc/backend/optimizer/ascend/ascend_helper.cc
mindspore/ccsrc/backend/optimizer/ascend/ascend_helper.cc
+2
-1
mindspore/ccsrc/backend/optimizer/common/helper.cc
mindspore/ccsrc/backend/optimizer/common/helper.cc
+24
-0
mindspore/ccsrc/backend/optimizer/common/helper.h
mindspore/ccsrc/backend/optimizer/common/helper.h
+1
-0
mindspore/ccsrc/backend/optimizer/pass/optimize_dependence.cc
...spore/ccsrc/backend/optimizer/pass/optimize_dependence.cc
+9
-5
mindspore/ccsrc/common/trans.cc
mindspore/ccsrc/common/trans.cc
+2
-2
未找到文件。
mindspore/ccsrc/backend/optimizer/ascend/ascend_helper.cc
浏览文件 @
e95b4249
...
...
@@ -71,7 +71,8 @@ AnfNodePtr AddTransOpNodeToGraph(const FuncGraphPtr &func_graph, const AnfNodePt
}
else
if
(
is_insert_input
)
{
// if need padding & is input need insert a transdata
// reshape[padding shape] -> transdata[padding shape] -> node
auto
padding_shape
=
trans
::
PaddingShapeTo4d
(
input_node_out_shape
,
AnfAlgo
::
GetInputReshapeType
(
node
,
0
));
auto
padding_shape
=
trans
::
PaddingShapeTo4d
(
input_node_out_shape
,
AnfAlgo
::
GetInputReshapeType
(
node
,
insert_index
));
auto
reshape_node
=
CreateReshapeNode
(
func_graph
,
input_node
,
kernel_select
,
padding_shape
);
trans_data
=
NewTransOpNode
(
func_graph
,
reshape_node
,
kernel_select
,
need_padding
,
prim
::
KPrimTransData
->
name
());
trans_node
=
trans_data
;
...
...
mindspore/ccsrc/backend/optimizer/common/helper.cc
浏览文件 @
e95b4249
...
...
@@ -553,6 +553,30 @@ bool IsUsedByOthers(const FuncGraphPtr &graph, const AnfNodePtr &node) {
return
output_node_list
->
size
()
>
1
;
}
bool
IsNotRealUsedByOthers
(
const
FuncGraphPtr
&
graph
,
const
AnfNodePtr
&
node
)
{
MS_EXCEPTION_IF_NULL
(
graph
);
MS_EXCEPTION_IF_NULL
(
node
);
auto
output_node_list
=
GetRealNodeUsedList
(
graph
,
node
);
MS_EXCEPTION_IF_NULL
(
output_node_list
);
if
(
output_node_list
->
empty
())
{
return
true
;
}
for
(
const
auto
&
output
:
*
output_node_list
)
{
auto
out_node
=
output
.
first
;
auto
name
=
AnfAlgo
::
GetCNodeName
(
out_node
);
if
(
name
==
prim
::
kPrimDepend
->
name
()
||
name
==
prim
::
kPrimMakeTuple
->
name
()
||
name
==
prim
::
kPrimTupleGetItem
->
name
())
{
auto
result
=
IsNotRealUsedByOthers
(
graph
,
out_node
);
if
(
!
result
)
{
return
result
;
}
continue
;
}
return
false
;
}
return
true
;
}
AnfNodePtr
CreatTupleGetItemNode
(
const
FuncGraphPtr
&
func_graph
,
const
AnfNodePtr
&
node
,
size_t
output_idx
)
{
auto
idx
=
NewValueNode
(
SizeToInt
(
output_idx
));
MS_EXCEPTION_IF_NULL
(
idx
);
...
...
mindspore/ccsrc/backend/optimizer/common/helper.h
浏览文件 @
e95b4249
...
...
@@ -175,6 +175,7 @@ std::shared_ptr<std::vector<std::pair<AnfNodePtr, int>>> GetRealNodeUsedList(con
std
::
shared_ptr
<
std
::
vector
<
std
::
pair
<
AnfNodePtr
,
int
>>>
GetRealNodeUsedListByOutputIdx
(
const
FuncGraphPtr
&
graph
,
const
AnfNodePtr
&
node
,
size_t
output_index
);
bool
IsNotRealUsedByOthers
(
const
FuncGraphPtr
&
graph
,
const
AnfNodePtr
&
node
);
void
ConstInputToAttr
(
const
CNodePtr
&
cnode
,
const
std
::
unordered_set
<
size_t
>
&
input_attrs
);
...
...
mindspore/ccsrc/backend/optimizer/pass/optimize_dependence.cc
浏览文件 @
e95b4249
...
...
@@ -28,7 +28,7 @@ namespace mindspore {
namespace
opt
{
constexpr
auto
kSingleInputIndex
=
1
;
namespace
{
AnfNodePtr
GetReplaceNode
(
const
AnfNodePtr
&
node
)
{
AnfNodePtr
GetReplaceNode
(
const
FuncGraphPtr
&
func_graph
,
const
AnfNodePtr
&
node
)
{
MS_EXCEPTION_IF_NULL
(
node
);
if
(
!
node
->
isa
<
CNode
>
())
{
return
nullptr
;
...
...
@@ -40,6 +40,9 @@ AnfNodePtr GetReplaceNode(const AnfNodePtr &node) {
if
(
op_name
!=
kTransDataOpName
&&
op_name
!=
prim
::
kPrimCast
->
name
())
{
return
nullptr
;
}
if
(
!
IsNotRealUsedByOthers
(
func_graph
,
cnode
))
{
return
nullptr
;
}
CheckCNodeInputSize
(
cnode
,
kSingleInputIndex
+
1
);
return
cnode
->
input
(
kSingleInputIndex
);
}
...
...
@@ -50,10 +53,11 @@ AnfNodePtr ReplaceMakeTuple(const FuncGraphPtr &func_graph, const CNodePtr &cnod
if
(
AnfAlgo
::
GetCNodeName
(
cnode
)
!=
prim
::
kPrimMakeTuple
->
name
())
{
return
nullptr
;
}
std
::
vector
<
AnfNodePtr
>
new_make_tuple_inputs
;
std
::
vector
<
AnfNodePtr
>
new_make_tuple_inputs
=
{
AnfAlgo
::
GetCNodePrimitiveNode
(
cnode
)}
;
bool
need_update
=
false
;
for
(
const
auto
&
input
:
cnode
->
inputs
())
{
AnfNodePtr
replace_input
=
GetReplaceNode
(
input
);
for
(
size_t
index
=
0
;
index
<
AnfAlgo
::
GetInputTensorNum
(
cnode
);
++
index
)
{
auto
input
=
AnfAlgo
::
GetInputNode
(
cnode
,
index
);
AnfNodePtr
replace_input
=
GetReplaceNode
(
func_graph
,
input
);
// If replace input is not null, it will be the input of the TransData or Cast.
if
(
replace_input
==
nullptr
)
{
new_make_tuple_inputs
.
push_back
(
input
);
...
...
@@ -149,7 +153,7 @@ const AnfNodePtr OptimizeDependence::GetConvertNode(const FuncGraphPtr &graph, c
if
(
make_tuple_replace_node
!=
nullptr
)
{
return
make_tuple_replace_node
;
}
AnfNodePtr
replace_node
=
GetReplaceNode
(
replacing_cnode
);
AnfNodePtr
replace_node
=
GetReplaceNode
(
graph
,
replacing_cnode
);
if
(
replace_node
==
nullptr
)
{
MS_LOG
(
DEBUG
)
<<
"Can not find the TransData or Cast with single output node. Depend node: "
<<
node
->
DebugString
();
return
replacing_node
;
...
...
mindspore/ccsrc/common/trans.cc
浏览文件 @
e95b4249
...
...
@@ -392,8 +392,8 @@ std::vector<int> GetRuntimePaddingShape(const AnfNodePtr &node, size_t index) {
}
else
{
host_shape
=
AnfAlgo
::
GetOutputInferShape
(
node
,
index
);
}
if
(
trans
::
IsNeedPadding
(
AnfAlgo
::
GetOutputFormat
(
node
,
0
),
host_shape
.
size
()))
{
host_shape
=
trans
::
PaddingShapeTo4d
(
host_shape
,
AnfAlgo
::
GetOutputReshapeType
(
node
,
0
));
if
(
trans
::
IsNeedPadding
(
AnfAlgo
::
GetOutputFormat
(
node
,
index
),
host_shape
.
size
()))
{
host_shape
=
trans
::
PaddingShapeTo4d
(
host_shape
,
AnfAlgo
::
GetOutputReshapeType
(
node
,
index
));
}
std
::
transform
(
host_shape
.
begin
(),
host_shape
.
end
(),
std
::
back_inserter
(
shape
),
SizeToInt
);
return
shape
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录