Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
69f4c45b
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看板
提交
69f4c45b
编写于
7月 27, 2020
作者:
C
chenfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
get real parameters if graph input is a virtual cnode
上级
1f1a07e6
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
41 addition
and
33 deletion
+41
-33
mindspore/ccsrc/backend/session/ascend_session.cc
mindspore/ccsrc/backend/session/ascend_session.cc
+6
-5
mindspore/ccsrc/backend/session/session_basic.cc
mindspore/ccsrc/backend/session/session_basic.cc
+35
-28
未找到文件。
mindspore/ccsrc/backend/session/ascend_session.cc
浏览文件 @
69f4c45b
...
...
@@ -885,11 +885,6 @@ void AscendSession::CreateMultiBranchOutput(NotNull<KernelGraphPtr> graph, NotNu
for
(
auto
&
child_graph
:
graph
->
child_graph_order
())
{
CreateMultiBranchOutput
(
NOT_NULL
(
child_graph
),
memo
);
}
// If graph has no output, the graph is the true graph of while and will call condition graph, no need insert assign
// from condition to true graph
if
(
graph
->
get_output_null
())
{
return
;
}
std
::
map
<
AnfNodePtr
,
AnfNodePtr
>
need_replace_list
;
auto
node_list
=
GetCNodes
(
TopoSort
(
graph
->
get_return
()));
for
(
auto
&
node
:
node_list
)
{
...
...
@@ -909,6 +904,11 @@ void AscendSession::CreateMultiBranchOutput(NotNull<KernelGraphPtr> graph, NotNu
auto
child_graphs
=
AnfAlgo
::
GetCallNodeKernelGraph
(
node
);
for
(
auto
&
child_graph
:
child_graphs
)
{
MS_EXCEPTION_IF_NULL
(
child_graph
);
// If graph has no output, the graph is the true graph of while and will call condition graph, no need insert
// assign from condition to true graph
if
(
memo
->
find
(
child_graph
)
!=
memo
->
end
())
{
continue
;
}
if
(
child_graph
->
get_output_null
())
{
continue
;
}
...
...
@@ -927,6 +927,7 @@ void AscendSession::CreateMultiBranchOutput(NotNull<KernelGraphPtr> graph, NotNu
}
}
}
memo
->
erase
(
graph
.
get
());
}
void
AscendSession
::
IrFusionPass
(
const
NotNull
<
KernelGraphPtr
>
graph
,
NotNull
<
std
::
set
<
KernelGraphPtr
>
*>
memo
)
{
...
...
mindspore/ccsrc/backend/session/session_basic.cc
浏览文件 @
69f4c45b
...
...
@@ -475,7 +475,7 @@ CNodePtr SessionBasic::CreateNewCNode(const CNodePtr &cnode, bool valid_input, K
cnode_inputs
.
emplace_back
(
new_value_node
);
}
continue
;
}
else
if
(
anf
->
isa
<
Parameter
>
()
&&
AnfAlgo
::
GetOutputTensorNum
(
anf
)
==
1
)
{
}
else
if
(
anf
->
isa
<
Parameter
>
())
{
auto
new_parameter
=
CreateNewParameterFromParameter
(
anf
,
valid_input
,
graph
);
cnode_inputs
.
push_back
(
new_parameter
);
if
(
GetGraphIdByNode
(
anf
)
==
kInvalidGraphId
)
{
...
...
@@ -818,6 +818,25 @@ void SessionBasic::AddParameterToGraphInputs(const std::vector<AnfNodePtr> ¶
}
}
namespace
{
bool
TensorNeedSync
(
const
AnfNodePtr
&
parameter
,
const
tensor
::
TensorPtr
&
tensor
)
{
auto
ms_context
=
MsContext
::
GetInstance
();
MS_EXCEPTION_IF_NULL
(
ms_context
);
auto
device_address
=
AnfAlgo
::
GetMutableOutputAddr
(
parameter
,
0
);
if
(
ms_context
->
enable_pynative_infer
())
{
return
tensor
->
device_address
().
get
()
==
nullptr
||
tensor
->
device_address
()
!=
device_address
;
}
if
(
tensor
->
is_dirty
())
{
return
true
;
}
if
(
tensor
->
device_address
()
!=
device_address
)
{
(
void
)
tensor
->
data_sync
();
return
true
;
}
return
false
;
}
}
// namespace
// run graph steps
void
SessionBasic
::
LoadInputData
(
const
std
::
shared_ptr
<
KernelGraph
>
&
kernel_graph
,
const
std
::
vector
<
tensor
::
TensorPtr
>
&
inputs_const
)
const
{
...
...
@@ -827,7 +846,11 @@ void SessionBasic::LoadInputData(const std::shared_ptr<KernelGraph> &kernel_grap
if
(
kernel_graph
->
input_ctrl_tensors
())
{
input_ctrl_size
=
LoadCtrlInputTensor
(
kernel_graph
,
&
inputs
);
}
auto
input_nodes
=
kernel_graph
->
inputs
();
std
::
vector
<
AnfNodePtr
>
input_nodes
;
for
(
const
auto
&
input_node
:
kernel_graph
->
inputs
())
{
auto
params
=
AnfAlgo
::
GetAllOutput
(
input_node
);
std
::
copy
(
params
.
begin
(),
params
.
end
(),
std
::
back_inserter
(
input_nodes
));
}
if
((
inputs
.
size
()
+
input_ctrl_size
)
-
2
!=
input_nodes
.
size
())
{
MS_LOG
(
EXCEPTION
)
<<
"Tensor input:"
<<
inputs
.
size
()
<<
" is not equal graph inputs:"
<<
input_nodes
.
size
()
<<
", input_ctrl_size:"
<<
input_ctrl_size
;
...
...
@@ -838,33 +861,17 @@ void SessionBasic::LoadInputData(const std::shared_ptr<KernelGraph> &kernel_grap
auto
tensor
=
inputs
[
i
];
MS_EXCEPTION_IF_NULL
(
tensor
);
auto
input_node
=
input_nodes
[
i
];
MS_EXCEPTION_IF_NULL
(
input_node
);
if
(
input_node
->
isa
<
Parameter
>
()
&&
AnfAlgo
::
OutputAddrExist
(
input_node
,
0
))
{
auto
pk_node
=
input_node
->
cast
<
ParameterPtr
>
();
auto
device_address
=
AnfAlgo
::
GetMutableOutputAddr
(
pk_node
,
0
);
bool
need_sync
=
false
;
if
(
ms_context
->
enable_pynative_infer
())
{
if
(
tensor
->
device_address
().
get
()
==
nullptr
||
tensor
->
device_address
()
!=
device_address
)
{
need_sync
=
true
;
}
}
else
{
if
(
tensor
->
is_dirty
())
{
need_sync
=
true
;
}
else
if
(
tensor
->
device_address
()
!=
device_address
)
{
(
void
)
tensor
->
data_sync
();
need_sync
=
true
;
}
if
(
TensorNeedSync
(
input_node
,
tensor
)
&&
input_node
->
isa
<
Parameter
>
()
&&
AnfAlgo
::
OutputAddrExist
(
input_node
,
0
))
{
auto
device_address
=
AnfAlgo
::
GetMutableOutputAddr
(
input_node
,
0
);
if
(
ms_context
->
execution_mode
()
==
kPynativeMode
||
AnfAlgo
::
IsParameterWeight
(
input_node
->
cast
<
ParameterPtr
>
()))
{
tensor
->
set_device_address
(
device_address
);
}
if
(
need_sync
)
{
if
(
ms_context
->
execution_mode
()
==
kPynativeMode
||
AnfAlgo
::
IsParameterWeight
(
pk_node
))
{
tensor
->
set_device_address
(
device_address
);
}
MS_EXCEPTION_IF_NULL
(
device_address
);
if
(
!
device_address
->
SyncHostToDevice
(
trans
::
GetRuntimePaddingShape
(
pk_node
,
0
),
LongToSize
(
tensor
->
data
().
nbytes
()),
tensor
->
data_type
(),
tensor
->
data_c
()))
{
MS_LOG
(
EXCEPTION
)
<<
"SyncHostToDevice failed."
;
}
MS_EXCEPTION_IF_NULL
(
device_address
);
if
(
!
device_address
->
SyncHostToDevice
(
trans
::
GetRuntimePaddingShape
(
input_node
,
0
),
LongToSize
(
tensor
->
data
().
nbytes
()),
tensor
->
data_type
(),
tensor
->
data_c
()))
{
MS_LOG
(
EXCEPTION
)
<<
"SyncHostToDevice failed."
;
}
}
tensor
->
set_dirty
(
false
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录