Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
1b4a7cde
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看板
提交
1b4a7cde
编写于
7月 02, 2020
作者:
L
lizhenyu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix mem swap bug
上级
0cd9e4cc
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
40 addition
and
12 deletion
+40
-12
mindspore/ccsrc/device/gpu/gpu_kernel_runtime.cc
mindspore/ccsrc/device/gpu/gpu_kernel_runtime.cc
+1
-1
mindspore/ccsrc/pre_activate/mem_reuse/mem_swap_manager.cc
mindspore/ccsrc/pre_activate/mem_reuse/mem_swap_manager.cc
+34
-9
mindspore/ccsrc/pre_activate/mem_reuse/mem_swap_manager.h
mindspore/ccsrc/pre_activate/mem_reuse/mem_swap_manager.h
+5
-2
未找到文件。
mindspore/ccsrc/device/gpu/gpu_kernel_runtime.cc
浏览文件 @
1b4a7cde
...
...
@@ -565,7 +565,7 @@ void GPUKernelRuntime::FreeKernelDynamicRes(const mindspore::AnfNodePtr &kernel,
MS_EXCEPTION_IF_NULL
(
mem_reuse_util_ptr
);
auto
cnode
=
kernel
->
cast
<
CNodePtr
>
();
MS_EXCEPTION_IF_NULL
(
cnode
);
if
(
AnfAlgo
::
GetCNodeName
(
kernel
)
==
kAllReduceOpName
)
{
if
(
AnfAlgo
::
IsCommunicationOp
(
kernel
)
)
{
return
;
}
// Free the input of kernel by reference count.
...
...
mindspore/ccsrc/pre_activate/mem_reuse/mem_swap_manager.cc
浏览文件 @
1b4a7cde
...
...
@@ -24,7 +24,15 @@ namespace device {
namespace
memswap
{
void
MemSwapManager
::
Init
(
const
mindspore
::
session
::
KernelGraph
*
kernel_graph
)
{
MS_EXCEPTION_IF_NULL
(
kernel_graph
);
execution_order_
=
kernel_graph
->
execution_order
();
graph_manager_
=
kernel_graph
->
manager
();
MS_EXCEPTION_IF_NULL
(
graph_manager_
);
auto
&
kernels
=
kernel_graph
->
execution_order
();
for
(
const
auto
&
kernel
:
kernels
)
{
if
(
AnfAlgo
::
IsRealCNodeKernel
(
kernel
)
&&
(
!
opt
::
IsNopNode
(
kernel
)))
{
execution_order_
.
push_back
(
kernel
);
}
}
size_t
kernel_index
=
0
;
for
(
const
auto
&
kernel
:
execution_order_
)
{
// parse topo order of kernel
...
...
@@ -41,7 +49,7 @@ void MemSwapManager::Init(const mindspore::session::KernelGraph *kernel_graph) {
}
// parse topo order of user kernel
SaveUserKernelTopoOrder
(
kernel_graph
);
SaveUserKernelTopoOrder
();
sort
(
ordered_tensors_
.
begin
(),
ordered_tensors_
.
end
(),
[](
const
TensorInfo
&
a
,
const
TensorInfo
&
b
)
{
return
a
.
tensor_size_
>
b
.
tensor_size_
;
});
...
...
@@ -62,11 +70,22 @@ void MemSwapManager::Init(const mindspore::session::KernelGraph *kernel_graph) {
mem_copy_manager_
->
Init
();
}
void
MemSwapManager
::
SaveUserKernelTopoOrder
(
const
mindspore
::
session
::
KernelGraph
*
kernel_graph
)
{
MS_EXCEPTION_IF_NULL
(
kernel_graph
);
FuncGraphManagerPtr
manager
=
kernel_graph
->
manager
();
MS_EXCEPTION_IF_NULL
(
manager
);
NodeUsersMap
user_map
=
manager
->
node_users
();
bool
MemSwapManager
::
IsCommunicationRelevantOp
(
const
AnfNodePtr
&
kernel
)
const
{
MS_EXCEPTION_IF_NULL
(
kernel
);
NodeUsersMap
&
user_map
=
graph_manager_
->
node_users
();
auto
iter
=
user_map
.
find
(
kernel
);
bool
adjacent_with_communication_op
=
false
;
if
(
iter
!=
user_map
.
end
())
{
AnfNodeIndexSet
node_set
=
iter
->
second
;
adjacent_with_communication_op
=
std
::
any_of
(
node_set
.
begin
(),
node_set
.
end
(),
[](
const
std
::
pair
<
AnfNodePtr
,
int
>
&
node_pair
)
{
return
AnfAlgo
::
IsCommunicationOp
(
node_pair
.
first
);
});
}
return
(
AnfAlgo
::
IsCommunicationOp
(
kernel
))
||
adjacent_with_communication_op
;
}
void
MemSwapManager
::
SaveUserKernelTopoOrder
()
{
NodeUsersMap
&
user_map
=
graph_manager_
->
node_users
();
for
(
const
auto
&
kernel
:
execution_order_
)
{
auto
iter
=
user_map
.
find
(
kernel
);
if
(
iter
==
user_map
.
end
())
{
...
...
@@ -76,13 +95,16 @@ void MemSwapManager::SaveUserKernelTopoOrder(const mindspore::session::KernelGra
auto
&
kernel_exec_info
=
SearchKernelExecutionInfo
(
kernel
);
for
(
auto
&
node_pair
:
node_set
)
{
auto
user_kernel
=
node_pair
.
first
;
if
(
!
AnfAlgo
::
IsRealCNodeKernel
(
user_kernel
))
{
if
(
!
AnfAlgo
::
IsRealCNodeKernel
(
user_kernel
)
||
opt
::
IsNopNode
(
user_kernel
)
)
{
continue
;
}
size_t
user_kernel_topo_sort
=
SearchKernelExecutionInfo
(
user_kernel
).
topo_order_
;
auto
kernel_with_index
=
AnfAlgo
::
GetPrevNodeOutput
(
user_kernel
,
node_pair
.
second
-
1
);
auto
&
output_idx
=
kernel_with_index
.
second
;
if
(
kernel_with_index
.
first
.
get
()
!=
kernel
.
get
())
{
MS_LOG
(
EXCEPTION
)
<<
"Save user kernel topo order failed for op["
<<
AnfAlgo
::
GetCNodeName
(
kernel
)
<<
"]"
;
}
kernel_exec_info
.
node_users_map_
[
output_idx
].
push_back
(
user_kernel_topo_sort
);
}
for
(
auto
&
node_user_pair
:
kernel_exec_info
.
node_users_map_
)
{
...
...
@@ -100,6 +122,9 @@ void MemSwapManager::AddSwapInfo() {
size_t
output_idx
=
tensor
.
output_idx_
;
const
AnfNodePtr
&
kernel
=
tensor
.
kernel_
;
if
(
IsCommunicationRelevantOp
(
kernel
))
{
continue
;
}
auto
&
kernel_exec_info
=
SearchKernelExecutionInfo
(
kernel
);
auto
&
node_users_map
=
kernel_exec_info
.
node_users_map_
;
...
...
@@ -178,7 +203,7 @@ bool MemSwapManager::RetreatSwapInfo() {
while
(
tensor_size_threshold_idx_
<
ordered_tensors_
.
size
()
-
1
)
{
++
tensor_size_threshold_idx_
;
if
(
tensor_size_threshold_
idx_
>
ordered_tensors_
[
tensor_size_threshold_idx_
].
tensor_size_
)
{
if
(
tensor_size_threshold_
>
ordered_tensors_
[
tensor_size_threshold_idx_
].
tensor_size_
)
{
tensor_size_threshold_
=
ordered_tensors_
[
tensor_size_threshold_idx_
].
tensor_size_
;
break
;
}
...
...
mindspore/ccsrc/pre_activate/mem_reuse/mem_swap_manager.h
浏览文件 @
1b4a7cde
...
...
@@ -91,7 +91,7 @@ class MemSwapManager {
void
ResetSwapInfo
();
void
SaveUserKernelTopoOrder
(
const
mindspore
::
session
::
KernelGraph
*
kernel_graph
);
void
SaveUserKernelTopoOrder
();
void
AddKernelTriggerSwap
(
const
AnfNodePtr
&
kernel
,
bool
trigger_swap
);
...
...
@@ -99,6 +99,8 @@ class MemSwapManager {
void
AddKernelMemSwapInfo
(
const
AnfNodePtr
&
kernel
,
const
MemSwapInfo
&
mem_swap_info
);
bool
IsCommunicationRelevantOp
(
const
AnfNodePtr
&
kernel
)
const
;
std
::
vector
<
CNodePtr
>
execution_order_
;
std
::
vector
<
TensorInfo
>
ordered_tensors_
;
std
::
unordered_map
<
void
*
,
KernelExecutionInfo
>
kernel_execution_info_
;
...
...
@@ -113,7 +115,8 @@ class MemSwapManager {
size_t
tensor_size_num_
;
size_t
distance_threshold_
;
MemCopyManagerPtr
mem_copy_manager_
;
MemCopyManagerPtr
mem_copy_manager_
{
nullptr
};
FuncGraphManagerPtr
graph_manager_
{
nullptr
};
bool
mem_swap_initialized_
{
false
};
bool
swap_info_already_set_
{
false
};
bool
trigger_swap_
{
false
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录