Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
283e6014
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看板
提交
283e6014
编写于
6月 28, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
6月 28, 2020
浏览文件
操作
浏览文件
下载
差异文件
!2563 reorder depend for mix target
Merge pull request !2563 from kisnwang/reorder-depend-for-mix-target
上级
363489d0
a3843659
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
55 addition
and
41 deletion
+55
-41
mindspore/ccsrc/session/session_basic.cc
mindspore/ccsrc/session/session_basic.cc
+11
-2
mindspore/ccsrc/vm/segment_runner.cc
mindspore/ccsrc/vm/segment_runner.cc
+8
-10
mindspore/ccsrc/vm/transform.cc
mindspore/ccsrc/vm/transform.cc
+35
-29
mindspore/ccsrc/vm/transform.h
mindspore/ccsrc/vm/transform.h
+1
-0
未找到文件。
mindspore/ccsrc/session/session_basic.cc
浏览文件 @
283e6014
...
...
@@ -395,9 +395,15 @@ CNodePtr SessionBasic::CreateNewCNode(const CNodePtr &cnode, bool valid_input, K
auto
new_fg
=
BasicClone
(
fg
);
cnode_inputs
.
push_back
(
std
::
make_shared
<
ValueNode
>
(
new_fg
));
}
auto
origin_inputs
=
cnode
->
inputs
();
bool
optimize_depend
=
false
;
if
(
IsPrimitiveCNode
(
cnode
,
prim
::
kPrimDepend
)
&&
origin_inputs
.
size
()
==
3
&&
origin_inputs
[
kRealInputIndexInDepend
]
->
isa
<
ValueNode
>
())
{
optimize_depend
=
true
;
}
// if has multiple depends,only select first depend as parameter
for
(
size_t
input_idx
=
1
;
input_idx
<
cnode
->
inputs
()
.
size
();
input_idx
++
)
{
auto
anf
=
cnode
->
inputs
()
[
input_idx
];
for
(
size_t
input_idx
=
1
;
input_idx
<
origin_inputs
.
size
();
input_idx
++
)
{
auto
anf
=
origin_inputs
[
input_idx
];
MS_EXCEPTION_IF_NULL
(
anf
);
// anf has been created before
if
(
graph
->
GetBackendAnfByFrontAnf
(
anf
)
!=
nullptr
)
{
...
...
@@ -422,6 +428,9 @@ CNodePtr SessionBasic::CreateNewCNode(const CNodePtr &cnode, bool valid_input, K
(
*
other_graph_cnode
)[
anf
]
=
new_parameter
;
}
continue
;
}
else
if
(
optimize_depend
&&
input_idx
==
kDependAttachNodeIndex
)
{
cnode_inputs
.
push_back
(
origin_inputs
[
kRealInputIndexInDepend
]);
continue
;
}
else
if
(
anf
->
isa
<
AnfNode
>
())
{
*
from_other_graph
=
true
;
// the input node is a cnode from other graph
...
...
mindspore/ccsrc/vm/segment_runner.cc
浏览文件 @
283e6014
...
...
@@ -28,6 +28,7 @@
#include <string>
#include "utils/log_adapter.h"
#include "utils/utils.h"
#include "ir/manager.h"
#include "ir/func_graph_cloner.h"
#include "operator/ops.h"
...
...
@@ -85,7 +86,6 @@ std::tuple<FuncGraphPtr, AnfNodePtrList, AnfNodePtrList> TransformSegmentToAnfGr
if
(
lst
.
empty
())
{
MS_LOG
(
EXCEPTION
)
<<
"Input anf node list is empty"
;
}
auto
ref
=
[
&
eqv
,
&
inputs
,
&
fg
](
const
AnfNodePtr
&
a
)
->
AnfNodePtr
{
if
(
a
->
isa
<
ValueNode
>
()
&&
!
IsValueNode
<
FuncGraph
>
(
a
))
{
eqv
[
a
]
=
a
;
...
...
@@ -95,17 +95,14 @@ std::tuple<FuncGraphPtr, AnfNodePtrList, AnfNodePtrList> TransformSegmentToAnfGr
eqv
[
a
]
->
set_abstract
(
a
->
abstract
());
eqv
[
a
]
->
set_kernel_info
(
a
->
kernel_info_ptr
());
}
return
eqv
[
a
];
};
// Merge CNodes into a AnfGraph that represents a linear instruction segment
for
(
auto
n
:
lst
)
{
if
(
!
n
->
isa
<
CNode
>
())
{
MS_LOG
(
EXCEPTION
)
<<
"Inst is not CNode"
;
}
auto
&
inps
=
n
->
cast
<
CNodePtr
>
()
->
inputs
();
if
(
inps
.
empty
())
{
MS_LOG
(
EXCEPTION
)
<<
"Input is empty"
;
}
...
...
@@ -114,21 +111,22 @@ std::tuple<FuncGraphPtr, AnfNodePtrList, AnfNodePtrList> TransformSegmentToAnfGr
inps
[
0
]
->
cast
<
ValueNodePtr
>
()
->
value
()
->
cast
<
FuncGraphPtr
>
()
->
has_attr
(
FUNC_GRAPH_ATTR_GRAPH_KERNEL
)))
{
MS_LOG
(
EXCEPTION
)
<<
"Input[0] Must be a Primitive valuenode"
;
}
auto
fn
=
inps
[
0
];
std
::
vector
<
AnfNodePtr
>
args
{
fn
};
(
void
)
std
::
transform
(
std
::
begin
(
inps
)
+
1
,
std
::
end
(
inps
),
std
::
back_inserter
(
args
),
ref
);
if
(
IsPrimitive
(
fn
,
prim
::
kPrimDepend
)
&&
inps
.
size
()
==
3
&&
inps
[
kRealInputIndexInDepend
]
->
isa
<
ValueNode
>
()
&&
eqv
.
find
(
inps
[
kDependAttachNodeIndex
])
==
eqv
.
end
())
{
args
.
emplace_back
(
inps
[
kRealInputIndexInDepend
]);
args
.
emplace_back
(
inps
[
kRealInputIndexInDepend
]);
}
else
{
(
void
)
std
::
transform
(
std
::
begin
(
inps
)
+
1
,
std
::
end
(
inps
),
std
::
back_inserter
(
args
),
ref
);
}
eqv
[
n
]
=
fg
->
NewCNode
(
args
);
eqv
[
n
]
->
set_abstract
(
n
->
abstract
());
eqv
[
n
]
->
set_kernel_info
(
n
->
kernel_info_ptr
());
}
std
::
vector
<
AnfNodePtr
>
eqv_keys
;
(
void
)
std
::
transform
(
std
::
begin
(
eqv
),
std
::
end
(
eqv
),
std
::
back_inserter
(
eqv_keys
),
[](
const
std
::
pair
<
AnfNodePtr
,
AnfNodePtr
>
&
elem
)
->
AnfNodePtr
{
return
elem
.
first
;
});
auto
outputs
=
GetOutput
(
lst
,
lst
[
0
]
->
func_graph
()
->
manager
()
->
node_users
(),
eqv_keys
);
AnfNodePtr
fg_output
;
if
(
outputs
.
size
()
>
1
)
{
...
...
mindspore/ccsrc/vm/transform.cc
浏览文件 @
283e6014
...
...
@@ -136,29 +136,12 @@ void CalcNodeRefCount(const FuncGraphPtr &graph, std::map<AnfNodePtr, size_t> *n
}
}
bool
IsGetItemNode
(
const
AnfNodePtr
&
node
)
{
MS_EXCEPTION_IF_NULL
(
node
);
if
(
node
->
isa
<
CNode
>
())
{
auto
cnode
=
node
->
cast
<
CNodePtr
>
();
auto
&
inputs
=
cnode
->
inputs
();
if
(
inputs
.
empty
())
{
MS_LOG
(
EXCEPTION
)
<<
"Inputs of apply node is empty"
;
}
if
(
!
IsValueNode
<
Primitive
>
(
inputs
[
0
]))
{
return
true
;
}
PrimitivePtr
node_prim
=
GetValueNode
<
PrimitivePtr
>
(
inputs
[
0
]);
return
node_prim
->
name
()
==
prim
::
kPrimTupleGetItem
->
name
();
}
return
false
;
}
std
::
vector
<
AnfNodePtr
>
ReorderGetItemNode
(
const
std
::
vector
<
AnfNodePtr
>
&
nodes
)
{
std
::
vector
<
AnfNodePtr
>
OptimizeGetItemOrder
(
const
std
::
vector
<
AnfNodePtr
>
&
nodes
)
{
std
::
vector
<
AnfNodePtr
>
result
;
std
::
map
<
size_t
,
std
::
vector
<
AnfNodePtr
>>
insert_positions
;
std
::
map
<
AnfNodePtr
,
size_t
>
node_positions
;
for
(
auto
&
node
:
nodes
)
{
if
(
IsGetItemNode
(
node
))
{
if
(
node
->
isa
<
CNode
>
()
&&
IsPrimitiveCNode
(
node
,
prim
::
kPrimTupleGetItem
))
{
auto
cnode
=
node
->
cast
<
CNodePtr
>
();
MS_EXCEPTION_IF_NULL
(
cnode
);
auto
&
inputs
=
cnode
->
inputs
();
...
...
@@ -241,7 +224,7 @@ std::vector<AnfNodePtr> SplitSort(const FuncGraphPtr &graph, const std::string &
}
}
std
::
reverse
(
result
.
begin
(),
result
.
end
());
return
ReorderGetItemNode
(
result
)
;
return
result
;
}
}
// namespace
...
...
@@ -309,19 +292,12 @@ bool CompileGraph::IsCut(const AnfNodePtr &node) {
return
false
;
}
VectorRef
CompileGraph
::
SplitNodes
(
const
FuncGraphPtr
&
graph
)
{
VectorRef
CompileGraph
::
SplitNodes
WithTarget
(
const
std
::
vector
<
AnfNodePtr
>
&
input_nodes
,
const
FuncGraphPtr
&
graph
)
{
MS_EXCEPTION_IF_NULL
(
graph
);
auto
nodes
=
OptimizeGetItemOrder
(
input_nodes
);
VectorRef
splits
;
VectorRef
split
;
auto
nodes
=
TopoSort
(
graph
->
get_return
());
if
(
ContainMultiTarget
(
nodes
))
{
auto
context_ptr
=
MsContext
::
GetInstance
();
MS_EXCEPTION_IF_NULL
(
context_ptr
);
std
::
string
default_target
=
context_ptr
->
device_target
();
nodes
=
SplitSort
(
graph
,
default_target
);
}
std
::
string
last_target
;
MS_LOG
(
DEBUG
)
<<
"Split all nodes size:"
<<
nodes
.
size
();
for
(
auto
&
node
:
nodes
)
{
MS_EXCEPTION_IF_NULL
(
node
);
if
(
IsCut
(
node
))
{
...
...
@@ -343,6 +319,36 @@ VectorRef CompileGraph::SplitNodes(const FuncGraphPtr &graph) {
return
splits
;
}
VectorRef
CompileGraph
::
SplitNodes
(
const
FuncGraphPtr
&
graph
)
{
MS_EXCEPTION_IF_NULL
(
graph
);
auto
nodes
=
TopoSort
(
graph
->
get_return
());
MS_LOG
(
DEBUG
)
<<
"Split all nodes size:"
<<
nodes
.
size
();
if
(
ContainMultiTarget
(
nodes
))
{
auto
context_ptr
=
MsContext
::
GetInstance
();
MS_EXCEPTION_IF_NULL
(
context_ptr
);
std
::
string
default_target
=
context_ptr
->
device_target
();
nodes
=
SplitSort
(
graph
,
default_target
);
return
SplitNodesWithTarget
(
nodes
,
graph
);
}
VectorRef
splits
;
VectorRef
split
;
for
(
auto
&
node
:
nodes
)
{
MS_EXCEPTION_IF_NULL
(
node
);
if
(
IsCut
(
node
))
{
if
(
split
.
size
()
!=
0
)
{
splits
.
push_back
(
split
);
}
splits
.
push_back
(
node
);
split
.
clear
();
}
else
if
(
node
->
isa
<
CNode
>
())
{
split
.
push_back
(
node
);
}
}
return
splits
;
}
// Push the value node on the stack.
void
CompileGraph
::
Push
(
const
AnfNodePtr
&
node
)
{
MS_EXCEPTION_IF_NULL
(
node
);
...
...
mindspore/ccsrc/vm/transform.h
浏览文件 @
283e6014
...
...
@@ -78,6 +78,7 @@ class CompileGraph {
}
private:
VectorRef
SplitNodesWithTarget
(
const
std
::
vector
<
AnfNodePtr
>
&
input_nodes
,
const
FuncGraphPtr
&
graph
);
void
PushParameters
(
const
FuncGraphPtr
&
func_graph
);
bool
SplitGraph
(
const
FuncGraphPtr
&
func_graph
);
int
LinConvert
(
const
FuncGraphPtr
&
func_graph
,
const
AnfNodePtrList
&
node_list
,
const
std
::
string
&
target
=
""
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录