Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
pingzhuyan
mindspore
提交
4faa3304
M
mindspore
项目概览
pingzhuyan
/
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,发现更多精彩内容 >>
提交
4faa3304
编写于
8月 13, 2020
作者:
W
wenchunjiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1. replace weak_ptr to shared_ptr in child_graph_order_ an parent_graph_
2. erase kAttrChildGraph after finish using
上级
529e1a0a
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
35 addition
and
25 deletion
+35
-25
mindspore/ccsrc/backend/session/ascend_control_parser.cc
mindspore/ccsrc/backend/session/ascend_control_parser.cc
+11
-6
mindspore/ccsrc/backend/session/ascend_session.cc
mindspore/ccsrc/backend/session/ascend_session.cc
+8
-6
mindspore/ccsrc/backend/session/kernel_graph.cc
mindspore/ccsrc/backend/session/kernel_graph.cc
+8
-5
mindspore/ccsrc/backend/session/kernel_graph.h
mindspore/ccsrc/backend/session/kernel_graph.h
+6
-6
mindspore/ccsrc/runtime/device/ascend/ascend_label_assign.cc
mindspore/ccsrc/runtime/device/ascend/ascend_label_assign.cc
+2
-2
未找到文件。
mindspore/ccsrc/backend/session/ascend_control_parser.cc
浏览文件 @
4faa3304
...
...
@@ -63,7 +63,7 @@ static void RecursiveReplaceNode(NotNull<KernelGraphPtr> kg, NotNull<AnfNodePtr>
}
for
(
auto
&
child
:
kg
->
child_graph_order
())
{
RecursiveReplaceNode
(
NOT_NULL
(
child
),
main_parameter
,
parameter_reuse_set
,
memo
);
RecursiveReplaceNode
(
NOT_NULL
(
child
.
lock
()
),
main_parameter
,
parameter_reuse_set
,
memo
);
}
}
...
...
@@ -177,13 +177,14 @@ void AscendControlParser::AttachChildGraphToReturnNode(NotNull<KernelGraphPtr> g
return
;
}
memo
->
insert
(
graph
.
get
());
const
std
::
vector
<
std
::
shared
_ptr
<
KernelGraph
>>
&
child_graph_order
=
graph
->
child_graph_order
();
const
std
::
vector
<
std
::
weak
_ptr
<
KernelGraph
>>
&
child_graph_order
=
graph
->
child_graph_order
();
if
(
child_graph_order
.
empty
())
{
return
;
}
std
::
vector
<
AnfNodePtr
>
depend_inputs
=
{
NewValueNode
(
std
::
make_shared
<
Primitive
>
(
prim
::
kPrimPartial
->
name
()))};
for
(
auto
&
cg
:
child_graph_order
)
{
for
(
auto
&
kg
:
child_graph_order
)
{
std
::
shared_ptr
<
KernelGraph
>
cg
=
kg
.
lock
();
MS_EXCEPTION_IF_NULL
(
cg
);
auto
fg
=
cg
->
cast
<
FuncGraphPtr
>
();
MS_EXCEPTION_IF_NULL
(
fg
);
...
...
@@ -207,7 +208,7 @@ void AscendControlParser::LinkGraph(NotNull<KernelGraphPtr> kg) {
memo
.
clear
();
// assign label resource
device
::
ascend
::
AscendLabelAssign
::
GetInstance
().
AssignLabel
(
kg
);
AttachChildGraphToReturnNode
(
kg
,
NOT_NULL
(
&
memo
));
//
AttachChildGraphToReturnNode(kg, NOT_NULL(&memo));
}
void
AscendControlParser
::
EraseParameter
(
NotNull
<
KernelGraphPtr
>
root_graph
,
...
...
@@ -428,7 +429,7 @@ void AscendControlParser::ChildGraphDataAssign(
}
kg
->
SetExecOrderByDefault
();
for
(
auto
&
child_graph
:
kg
->
child_graph_order
())
{
ChildGraphDataAssign
(
NOT_NULL
(
child_graph
),
link_list
,
memo
);
ChildGraphDataAssign
(
NOT_NULL
(
child_graph
.
lock
()
),
link_list
,
memo
);
}
}
...
...
@@ -772,7 +773,7 @@ std::vector<CNodePtr> AscendControlParser::RecurseGraph(NotNull<KernelGraphPtr>
MS_LOG
(
EXCEPTION
)
<<
"Index out of range:"
<<
graph
->
child_graph_order
().
size
();
}
auto
child_graph
=
graph
->
child_graph_order
()[
child_order_index
++
];
auto
child_execution_order
=
RecurseGraph
(
NOT_NULL
(
child_graph
),
memo
);
auto
child_execution_order
=
RecurseGraph
(
NOT_NULL
(
child_graph
.
lock
()
),
memo
);
execution_order
.
insert
(
execution_order
.
end
(),
child_execution_order
.
begin
(),
child_execution_order
.
end
());
};
...
...
@@ -791,6 +792,10 @@ std::vector<CNodePtr> AscendControlParser::RecurseGraph(NotNull<KernelGraphPtr>
uint32_t
label_index
=
AnfAlgo
::
GetNodeAttr
<
uint32_t
>
(
node
,
kAttrLabelIndex
);
recurse_child_graph
(
child_graph_index
,
label_index
,
node
);
}
// erase kAttrChildGraph after finish using
if
(
AnfAlgo
::
HasNodeAttr
(
kAttrChildGraph
,
node
))
{
AnfAlgo
::
EraseNodeAttr
(
kAttrChildGraph
,
node
);
}
}
graph
->
set_execution_order
(
execution_order
);
graph
->
PrintGraphExecuteOrder
();
...
...
mindspore/ccsrc/backend/session/ascend_session.cc
浏览文件 @
4faa3304
...
...
@@ -860,7 +860,7 @@ void AscendSession::CreateMultiBranchOutput(NotNull<KernelGraphPtr> graph, NotNu
memo
->
insert
(
graph
.
get
());
graph
->
UpdateChildGraphOrder
();
for
(
auto
&
child_graph
:
graph
->
child_graph_order
())
{
CreateMultiBranchOutput
(
NOT_NULL
(
child_graph
),
memo
);
CreateMultiBranchOutput
(
NOT_NULL
(
child_graph
.
lock
()
),
memo
);
}
std
::
map
<
AnfNodePtr
,
AnfNodePtr
>
need_replace_list
;
auto
node_list
=
GetCNodes
(
TopoSort
(
graph
->
get_return
()));
...
...
@@ -932,7 +932,7 @@ void AscendSession::IrFusionPass(const NotNull<KernelGraphPtr> graph, NotNull<st
}
for
(
auto
&
child_graph
:
graph
->
child_graph_order
())
{
IrFusionPass
(
NOT_NULL
(
child_graph
),
memo
);
IrFusionPass
(
NOT_NULL
(
child_graph
.
lock
()
),
memo
);
}
}
...
...
@@ -1016,7 +1016,7 @@ void AscendSession::HardwareOptimize(NotNull<KernelGraphPtr> graph,
HardwareOptimize
(
graph
.
get
());
for
(
auto
&
child_graph
:
graph
->
child_graph_order
())
{
HardwareOptimize
(
NOT_NULL
(
child_graph
),
memo
);
HardwareOptimize
(
NOT_NULL
(
child_graph
.
lock
()
),
memo
);
}
MS_LOG
(
INFO
)
<<
"Finish doing HardwareOptimize in graph: "
<<
graph
->
graph_id
();
}
...
...
@@ -1035,7 +1035,7 @@ void AscendSession::AssignStaticMemory(NotNull<KernelGraphPtr> graph,
runtime_instance
->
AssignStaticMemoryInput
(
graph
.
get
().
get
());
runtime_instance
->
AssignStaticMemoryValueNode
(
graph
.
get
().
get
());
for
(
auto
&
child_graph
:
graph
->
child_graph_order
())
{
AssignStaticMemory
(
NOT_NULL
(
child_graph
),
memo
);
AssignStaticMemory
(
NOT_NULL
(
child_graph
.
lock
()
),
memo
);
}
MS_LOG
(
INFO
)
<<
"Finish assigning static memory for parameter in graph: "
<<
graph
->
graph_id
();
}
...
...
@@ -1048,9 +1048,11 @@ void AscendSession::UpdateRefOutputMap(NotNull<KernelGraphPtr> graph,
memo
->
insert
(
graph
.
get
());
for
(
auto
&
child_graph
:
graph
->
child_graph_order
())
{
UpdateRefOutputMap
(
NOT_NULL
(
child_graph
),
memo
);
std
::
shared_ptr
<
KernelGraph
>
child_graph_ptr
=
child_graph
.
lock
();
MS_EXCEPTION_IF_NULL
(
child_graph_ptr
);
UpdateRefOutputMap
(
NOT_NULL
(
child_graph_ptr
),
memo
);
// copy ref map to final graph
auto
child_ref_map
=
child_graph
->
GetRefMap
();
auto
child_ref_map
=
child_graph
_ptr
->
GetRefMap
();
for
(
auto
&
item
:
child_ref_map
)
{
if
(
graph
->
IsInRefOutputMap
(
item
.
first
))
{
MS_LOG
(
WARNING
)
<<
"The ref pair <"
<<
item
.
first
.
first
->
DebugString
()
<<
", "
<<
item
.
first
.
second
...
...
mindspore/ccsrc/backend/session/kernel_graph.cc
浏览文件 @
4faa3304
...
...
@@ -922,8 +922,9 @@ std::vector<std::shared_ptr<KernelGraph>> KernelGraph::GetLeafGraphOrder() {
leaf_graph_order
.
push_back
(
shared_from_this
()
->
cast
<
KernelGraphPtr
>
());
}
else
{
for
(
const
auto
&
child_graph
:
child_graph_order_
)
{
MS_EXCEPTION_IF_NULL
(
child_graph
);
auto
child_leaf_graph_order
=
child_graph
->
GetLeafGraphOrder
();
std
::
shared_ptr
<
KernelGraph
>
child_graph_ptr
=
child_graph
.
lock
();
MS_EXCEPTION_IF_NULL
(
child_graph_ptr
);
auto
child_leaf_graph_order
=
child_graph_ptr
->
GetLeafGraphOrder
();
std
::
copy
(
child_leaf_graph_order
.
begin
(),
child_leaf_graph_order
.
end
(),
std
::
back_inserter
(
leaf_graph_order
));
}
}
...
...
@@ -1103,13 +1104,13 @@ void KernelGraph::UpdateChildGraphOrder() {
SetExecOrderByDefault
();
auto
call_nodes
=
FindNodeByPrimitive
(
{
std
::
make_shared
<
Primitive
>
(
prim
::
kPrimCall
->
name
()),
std
::
make_shared
<
Primitive
>
(
prim
::
kPrimSwitch
->
name
())});
std
::
vector
<
KernelGraphPtr
>
child_graph_order
;
std
::
vector
<
std
::
weak_ptr
<
KernelGraph
>
>
child_graph_order
;
for
(
auto
&
call_node
:
call_nodes
)
{
MS_EXCEPTION_IF_NULL
(
call_node
);
auto
call_child_graphs
=
AnfAlgo
::
GetCallSwitchKernelGraph
(
call_node
->
cast
<
CNodePtr
>
());
for
(
const
auto
&
child_graph
:
call_child_graphs
)
{
MS_EXCEPTION_IF_NULL
(
child_graph
);
if
(
child_graph
!=
parent_graph_
)
{
if
(
child_graph
!=
parent_graph_
.
lock
()
)
{
auto
shared_this
=
std
::
dynamic_pointer_cast
<
KernelGraph
>
(
shared_from_this
());
MS_EXCEPTION_IF_NULL
(
shared_this
);
child_graph
->
set_parent_graph
(
shared_this
);
...
...
@@ -1118,7 +1119,9 @@ void KernelGraph::UpdateChildGraphOrder() {
}
}
for
(
size_t
i
=
0
;
i
<
child_graph_order
.
size
();
++
i
)
{
MS_LOG
(
INFO
)
<<
"Child graph["
<<
i
<<
"][id:"
<<
child_graph_order
[
i
]
->
graph_id
()
<<
"]"
;
std
::
shared_ptr
<
KernelGraph
>
child_graph
=
child_graph_order
[
i
].
lock
();
MS_EXCEPTION_IF_NULL
(
child_graph
);
MS_LOG
(
INFO
)
<<
"Child graph["
<<
i
<<
"][id:"
<<
child_graph
->
graph_id
()
<<
"]"
;
}
child_graph_order_
=
child_graph_order
;
}
...
...
mindspore/ccsrc/backend/session/kernel_graph.h
浏览文件 @
4faa3304
...
...
@@ -114,8 +114,8 @@ class KernelGraph : public FuncGraph {
// calculate the leaf graph order of root graph
std
::
vector
<
std
::
shared_ptr
<
KernelGraph
>>
GetLeafGraphOrder
();
// the child graph of current graph
const
std
::
vector
<
std
::
shared
_ptr
<
KernelGraph
>>
&
child_graph_order
()
const
{
return
child_graph_order_
;
}
void
set_child_graph_order
(
const
std
::
vector
<
std
::
shared
_ptr
<
KernelGraph
>>
&
order
)
{
child_graph_order_
=
order
;
}
const
std
::
vector
<
std
::
weak
_ptr
<
KernelGraph
>>
&
child_graph_order
()
const
{
return
child_graph_order_
;
}
void
set_child_graph_order
(
const
std
::
vector
<
std
::
weak
_ptr
<
KernelGraph
>>
&
order
)
{
child_graph_order_
=
order
;
}
// checkout whether current graph is leaf graph
bool
IsLeafGraph
()
const
;
...
...
@@ -126,9 +126,9 @@ class KernelGraph : public FuncGraph {
// get input_tensors pointer of control parameter
std
::
shared_ptr
<
std
::
vector
<
tensor
::
TensorPtr
>>
input_ctrl_tensors
()
const
{
return
input_ctrl_tensors_
;
}
// get parent kernel graph
std
::
shared
_ptr
<
KernelGraph
>
parent_graph
()
const
{
return
parent_graph_
;
}
std
::
weak
_ptr
<
KernelGraph
>
parent_graph
()
const
{
return
parent_graph_
;
}
// set parent kernel graph
void
set_parent_graph
(
const
std
::
shared
_ptr
<
KernelGraph
>
&
parent_graph
)
{
parent_graph_
=
parent_graph
;
}
void
set_parent_graph
(
const
std
::
weak
_ptr
<
KernelGraph
>
&
parent_graph
)
{
parent_graph_
=
parent_graph
;
}
// find anf node in graph
std
::
vector
<
CNodePtr
>
FindNodeByPrimitive
(
const
PrimitivePtr
&
primitive
)
const
;
std
::
vector
<
CNodePtr
>
FindNodeByPrimitive
(
const
std
::
vector
<
PrimitivePtr
>
&
primitive_list
)
const
;
...
...
@@ -227,13 +227,13 @@ class KernelGraph : public FuncGraph {
std
::
vector
<
bool
>
valid_inputs_
;
// child graph execute order in root graph
std
::
vector
<
std
::
shared
_ptr
<
KernelGraph
>>
child_graph_order_
;
std
::
vector
<
std
::
weak
_ptr
<
KernelGraph
>>
child_graph_order_
;
// input_tensors of control parameter
std
::
shared_ptr
<
std
::
vector
<
tensor
::
TensorPtr
>>
input_ctrl_tensors_
;
// parameter graph
std
::
shared
_ptr
<
KernelGraph
>
parent_graph_
;
std
::
weak
_ptr
<
KernelGraph
>
parent_graph_
;
CNodePtr
start_label_
;
CNodePtr
end_goto_
;
...
...
mindspore/ccsrc/runtime/device/ascend/ascend_label_assign.cc
浏览文件 @
4faa3304
...
...
@@ -89,7 +89,7 @@ static void AssignLabelForLabelSet(NotNull<std::shared_ptr<session::KernelGraph>
}
for
(
auto
&
cg
:
graph
->
child_graph_order
())
{
AssignLabelForLabelSet
(
NOT_NULL
(
cg
),
label_id
,
memo
);
AssignLabelForLabelSet
(
NOT_NULL
(
cg
.
lock
()
),
label_id
,
memo
);
}
}
...
...
@@ -120,7 +120,7 @@ static void AssignLabelForGotoSwitch(NotNull<std::shared_ptr<session::KernelGrap
}
}
for
(
auto
&
cg
:
graph
->
child_graph_order
())
{
AssignLabelForGotoSwitch
(
NOT_NULL
(
cg
),
memo
);
AssignLabelForGotoSwitch
(
NOT_NULL
(
cg
.
lock
()
),
memo
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录