Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
bce5f577
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看板
提交
bce5f577
编写于
4月 16, 2020
作者:
C
caifubi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use GraphId as key of DavinciModel in ascend_kernel_runtime.cc
上级
ac9f24a7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
40 addition
and
37 deletion
+40
-37
mindspore/ccsrc/device/ascend/ascend_kernel_runtime.cc
mindspore/ccsrc/device/ascend/ascend_kernel_runtime.cc
+36
-33
mindspore/ccsrc/device/ascend/ascend_kernel_runtime.h
mindspore/ccsrc/device/ascend/ascend_kernel_runtime.h
+4
-4
未找到文件。
mindspore/ccsrc/device/ascend/ascend_kernel_runtime.cc
浏览文件 @
bce5f577
...
...
@@ -54,9 +54,9 @@ static const size_t PRAMATER_OUTPUT_INDEX = 0;
AscendKernelRuntime
::~
AscendKernelRuntime
()
{
graph_model_map_
.
clear
();
}
void
AscendKernelRuntime
::
ClearGraphModelMap
()
{
for
(
auto
&
iter
:
graph_model_
id_
map_
)
{
MS_LOG
(
INFO
)
<<
"Ge UnloadModel "
<<
iter
.
second
;
auto
ret
=
ge
::
model_runner
::
ModelRunner
::
Instance
().
UnloadModel
(
iter
.
second
);
for
(
auto
&
iter
:
graph_model_map_
)
{
MS_LOG
(
INFO
)
<<
"Ge UnloadModel "
<<
iter
.
first
;
auto
ret
=
ge
::
model_runner
::
ModelRunner
::
Instance
().
UnloadModel
(
iter
.
first
);
if
(
!
ret
)
{
MS_LOG
(
ERROR
)
<<
"UnloadModel failed"
;
}
...
...
@@ -249,6 +249,10 @@ DeviceAddressPtr AscendKernelRuntime::CreateDeviceAddress(void *device_ptr, size
}
bool
AscendKernelRuntime
::
GenTask
(
const
session
::
KernelGraph
*
graph
)
{
if
(
graph
==
nullptr
)
{
MS_EXCEPTION
(
NotExistsError
)
<<
"session::KernelGraph is NULL!"
;
}
MS_LOG
(
INFO
)
<<
"GenTask start. GraphId:"
<<
graph
->
graph_id
();
auto
context_ptr
=
MsContext
::
GetInstance
();
MS_EXCEPTION_IF_NULL
(
context_ptr
);
bool
is_task_sink
=
context_ptr
->
enable_task_sink
();
...
...
@@ -261,19 +265,15 @@ bool AscendKernelRuntime::GenTask(const session::KernelGraph *graph) {
mindspore
::
memreuse
::
MemReuseChecker
::
GetInstance
().
CheckNormalIR
(
graph
);
}
#endif
if
(
graph
==
nullptr
)
{
MS_EXCEPTION
(
NotExistsError
)
<<
"session::KernelGraph is NULL!"
;
}
vector
<
std
::
shared_ptr
<
TaskInfo
>>
task_info_list
;
auto
anf_node_list
=
graph
->
execution_order
();
TaskGenerator
::
GenTasks
(
anf_node_list
,
&
task_info_list
,
graph
->
graph_id
());
// Store the task_info_list
auto
i
ter
=
task_map_
.
find
(
graph
);
if
(
iter
!=
task_map_
.
end
()
)
{
MS_LOG
(
EXCEPTION
)
<<
"
graph TaskInfo list already exist
"
;
auto
i
nsert_ret
=
task_map_
.
insert
(
std
::
make_pair
(
graph
->
graph_id
(),
task_info_list
)
);
if
(
!
insert_ret
.
second
)
{
MS_LOG
(
EXCEPTION
)
<<
"
Duplicate GraphId! Please check in ascend_session.
"
;
}
task_map_
[
graph
]
=
task_info_list
;
// Graph may have no compute node, such TensorAddGrad.
if
(
task_info_list
.
empty
())
{
...
...
@@ -296,25 +296,19 @@ bool AscendKernelRuntime::GenTask(const session::KernelGraph *graph) {
task_info_list
,
empty_list
,
empty_list
,
empty_list
,
empty_list
,
wait_active_stream_list
,
force_copy_stream_list
,
0
,
0
,
0
,
0
,
0
,
0
,
assign_instance
.
GetTotalStreamNum
(),
1
,
assign_instance
.
GetTotalEventNum
(),
0
);
graph_model_map_
[
graph
]
=
model
;
graph_model_id_map_
[
graph
]
=
graph
->
graph_id
();
auto
ret
=
graph_model_map_
.
insert
(
std
::
make_pair
(
graph
->
graph_id
(),
model
));
if
(
!
ret
.
second
)
{
MS_LOG
(
EXCEPTION
)
<<
"Duplicate GraphId! Please check in ascend_session."
;
}
MS_LOG
(
INFO
)
<<
"TaskGenerator GetTaskInfo end..."
;
return
true
;
}
uint32_t
AscendKernelRuntime
::
GetGraphModelId
(
const
session
::
KernelGraph
*
kernel_graph
)
{
MS_EXCEPTION_IF_NULL
(
kernel_graph
);
auto
iter
=
graph_model_id_map_
.
find
(
kernel_graph
);
if
(
iter
==
graph_model_id_map_
.
end
())
{
MS_LOG
(
EXCEPTION
)
<<
"graph not in the map"
;
}
return
iter
->
second
;
}
bool
AscendKernelRuntime
::
LoadTask
(
const
session
::
KernelGraph
*
graph
)
{
if
(
graph
==
nullptr
)
{
MS_EXCEPTION
(
NotExistsError
)
<<
"Null pointer graph, LoadTask failed. "
;
}
MS_LOG
(
INFO
)
<<
"LoadTask start. GraphId:"
<<
graph
->
graph_id
();
auto
context_ptr
=
MsContext
::
GetInstance
();
MS_EXCEPTION_IF_NULL
(
context_ptr
);
bool
is_task_sink
=
context_ptr
->
enable_task_sink
();
...
...
@@ -327,23 +321,22 @@ bool AscendKernelRuntime::LoadTask(const session::KernelGraph *graph) {
return
true
;
}
auto
task_iter
=
graph_model_map_
.
find
(
graph
);
if
(
task
_iter
==
graph_model_map_
.
end
())
{
MS_LOG
(
ERROR
)
<<
"
task not exist
"
;
auto
model_iter
=
graph_model_map_
.
find
(
graph
->
graph_id
()
);
if
(
model
_iter
==
graph_model_map_
.
end
())
{
MS_LOG
(
ERROR
)
<<
"
GraphId:"
<<
graph
->
graph_id
()
<<
" Invalid! Graph LoadTask without GenTask.
"
;
return
false
;
}
auto
model_id
=
GetGraphModelId
(
graph
);
std
::
shared_ptr
<
ge
::
ModelListener
>
listener
;
MS_LOG
(
INFO
)
<<
"LoadDavinciModel mode_id:"
<<
model_i
d
;
bool
status
=
ge
::
model_runner
::
ModelRunner
::
Instance
().
LoadDavinciModel
(
device_id_
,
0
,
model_id
,
task
_iter
->
second
,
listener
);
MS_LOG
(
INFO
)
<<
"LoadDavinciModel mode_id:"
<<
model_i
ter
->
first
;
bool
status
=
ge
::
model_runner
::
ModelRunner
::
Instance
().
LoadDavinciModel
(
device_id_
,
0
,
model_iter
->
first
,
model
_iter
->
second
,
listener
);
if
(
!
status
)
{
MS_LOG
(
INFO
)
<<
"load task failed"
;
MS_LOG
(
ERROR
)
<<
"load task failed"
;
return
false
;
}
if
(
ProfilingManager
::
GetInstance
().
IsProfiling
())
{
std
::
vector
<
uint32_t
>
task_ids
=
ge
::
model_runner
::
ModelRunner
::
Instance
().
GetTaskIdList
(
model_i
d
);
std
::
vector
<
uint32_t
>
task_ids
=
ge
::
model_runner
::
ModelRunner
::
Instance
().
GetTaskIdList
(
model_i
ter
->
first
);
ProfilingUtils
::
ReportProfilingData
(
graph
->
graph_id
(),
task_ids
);
}
return
true
;
...
...
@@ -351,6 +344,8 @@ bool AscendKernelRuntime::LoadTask(const session::KernelGraph *graph) {
bool
AscendKernelRuntime
::
RunTask
(
const
session
::
KernelGraph
*
graph
)
{
MS_EXCEPTION_IF_NULL
(
graph
);
MS_LOG
(
INFO
)
<<
"RunTask start. GraphId:"
<<
graph
->
graph_id
();
auto
context_ptr
=
MsContext
::
GetInstance
();
MS_EXCEPTION_IF_NULL
(
context_ptr
);
ge
::
InputData
input_tensors
=
ge
::
InputData
();
...
...
@@ -360,8 +355,12 @@ bool AscendKernelRuntime::RunTask(const session::KernelGraph *graph) {
return
true
;
}
auto
model_id
=
GetGraphModelId
(
graph
);
bool
status
=
ge
::
model_runner
::
ModelRunner
::
Instance
().
RunModel
(
model_id
,
input_tensors
,
output_tensors
);
if
(
!
CheckGraphIdValid
(
graph
->
graph_id
()))
{
MS_LOG
(
ERROR
)
<<
"GraphId:"
<<
graph
->
graph_id
()
<<
" Invalid! Graph RunTask without GenTask."
;
return
false
;
}
bool
status
=
ge
::
model_runner
::
ModelRunner
::
Instance
().
RunModel
(
graph
->
graph_id
(),
input_tensors
,
output_tensors
);
if
(
!
status
)
{
MS_LOG
(
INFO
)
<<
"run task failed"
;
return
false
;
...
...
@@ -497,12 +496,16 @@ bool AscendKernelRuntime::DestroyHccl() {
}
bool
AscendKernelRuntime
::
GraphWithEmptyTaskList
(
const
session
::
KernelGraph
*
graph
)
const
{
auto
iter
=
task_map_
.
find
(
graph
);
auto
iter
=
task_map_
.
find
(
graph
->
graph_id
()
);
if
(
iter
==
task_map_
.
end
())
{
MS_LOG
(
EXCEPTION
)
<<
"Unknown graph ptr"
;
}
return
iter
->
second
.
empty
();
}
bool
AscendKernelRuntime
::
CheckGraphIdValid
(
GraphId
graph_id
)
const
{
return
task_map_
.
find
(
graph_id
)
!=
task_map_
.
end
()
&&
graph_model_map_
.
find
(
graph_id
)
!=
graph_model_map_
.
end
();
}
}
// namespace ascend
}
// namespace device
}
// namespace mindspore
mindspore/ccsrc/device/ascend/ascend_kernel_runtime.h
浏览文件 @
bce5f577
...
...
@@ -23,6 +23,7 @@
#include "runtime/context.h"
#include "framework/ge_runtime/davinci_model.h"
#include "device/kernel_runtime_manager.h"
#include "session/session_basic.h"
using
ge
::
model_runner
::
TaskInfo
;
using
std
::
unordered_map
;
...
...
@@ -54,14 +55,13 @@ class AscendKernelRuntime : public KernelRuntime {
void
ClearGraphModelMap
();
void
ReleaseDeviceRes
()
override
;
uint32_t
GetGraphModelId
(
const
session
::
KernelGraph
*
kernel_graph
);
bool
GraphWithEmptyTaskList
(
const
session
::
KernelGraph
*
graph
)
const
;
bool
CheckGraphIdValid
(
GraphId
graph_id
)
const
;
rtContext_t
rt_context_
{
nullptr
};
bool
initialized_
{
false
};
unordered_map
<
const
session
::
KernelGraph
*
,
vector
<
std
::
shared_ptr
<
TaskInfo
>>>
task_map_
;
unordered_map
<
const
session
::
KernelGraph
*
,
std
::
shared_ptr
<
ge
::
model_runner
::
DavinciModel
>>
graph_model_map_
;
unordered_map
<
const
session
::
KernelGraph
*
,
uint32_t
>
graph_model_id_map_
;
unordered_map
<
GraphId
,
vector
<
std
::
shared_ptr
<
TaskInfo
>>>
task_map_
;
unordered_map
<
GraphId
,
std
::
shared_ptr
<
ge
::
model_runner
::
DavinciModel
>>
graph_model_map_
;
};
MS_REG_KERNEL_RUNTIME
(
kAscendDevice
,
AscendKernelRuntime
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录