Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
49d81260
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看板
提交
49d81260
编写于
5月 22, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
5月 22, 2020
浏览文件
操作
浏览文件
下载
差异文件
!1347 add memory swap module header file
Merge pull request !1347 from zyli2020/add_mem_swap_module_header
上级
f3d14fa1
af3307ec
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
227 addition
and
0 deletion
+227
-0
mindspore/ccsrc/pre_activate/mem_reuse/mem_swap_manager.h
mindspore/ccsrc/pre_activate/mem_reuse/mem_swap_manager.h
+123
-0
mindspore/ccsrc/pre_activate/mem_reuse/mem_swap_util.h
mindspore/ccsrc/pre_activate/mem_reuse/mem_swap_util.h
+104
-0
未找到文件。
mindspore/ccsrc/pre_activate/mem_reuse/mem_swap_manager.h
0 → 100644
浏览文件 @
49d81260
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MINDSPORE_CCSRC_PRE_ACTIVATE_MEM_REUSE_MEM_SWAP_MANAGER_H_
#define MINDSPORE_CCSRC_PRE_ACTIVATE_MEM_REUSE_MEM_SWAP_MANAGER_H_
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <memory>
#include <vector>
#include <utility>
#include "pre_activate/mem_reuse/mem_swap_util.h"
using
PerformPair
=
std
::
pair
<
float
,
float
>
;
namespace
mindspore
{
namespace
device
{
namespace
memswap
{
class
MemSwapManager
{
public:
MemSwapManager
()
:
tensor_size_threshold_
(
0
),
tensor_size_threshold_idx_
(
0
),
tensor_size_num_
(
1
),
distance_threshold_
(
1
)
{
mem_copy_manager_
=
std
::
make_shared
<
MemCopyManager
>
();
}
~
MemSwapManager
()
=
default
;
void
Init
(
const
mindspore
::
session
::
KernelGraph
*
kernel_graph
);
void
AddMemSwapTask
(
SwapKind
swap_kind
,
const
DeviceAddressPtr
&
device_address
,
const
HostAddress
&
host_address
);
bool
SyncMemCopyStream
(
SwapKind
swap_kind
);
DeviceAddressPtr
UpdateSwapQueue
(
SwapKind
swap_kind
);
// retreat to find a workable swap scheme
bool
RetreatSwapInfo
();
bool
trigger_swap
()
const
{
return
trigger_swap_
;
}
bool
mem_swap_init
()
const
{
return
mem_swap_initialized_
;
}
KernelExecutionInfo
&
SearchKernelExecutionInfo
(
const
AnfNodePtr
&
kernel
)
const
;
void
AddKernelExecutionPerform
(
const
AnfNodePtr
&
kernel
,
float
perform
);
float
QueryKernelExecutionPerform
(
const
AnfNodePtr
&
kernel
)
const
;
void
AddKernelSwapPerform
(
const
AnfNodePtr
&
kernel
,
size_t
output_idx
,
const
PerformPair
&
perform
);
const
PerformPair
&
QueryKernelSwapPerform
(
const
AnfNodePtr
&
kernel
,
size_t
output_idx
)
const
;
bool
QueryKerneTriggerSwap
(
const
AnfNodePtr
&
kernel
)
const
;
bool
QueryKerneNeedSwap
(
const
AnfNodePtr
&
kernel
)
const
;
const
std
::
vector
<
MemSwapInfo
>
&
QueryKerneMemSwapInfo
(
const
AnfNodePtr
&
kernel
)
const
;
void
InsertSwapInBlackList
(
const
void
*
device_ptr
);
bool
FindInSwapInBlackList
(
const
void
*
device_ptr
)
const
;
const
HostAddress
&
kernel_host_addr
(
const
AnfNodePtr
&
kernel
,
size_t
output_idx
)
const
;
size_t
AllocHostPinnedMemory
(
size_t
size
,
HostMemPtr
*
addr
)
const
;
void
FreeHostPinnedMemory
();
void
ClearSwapQueue
();
private:
MemSwapManager
(
const
MemSwapManager
&
)
=
delete
;
MemSwapManager
&
operator
=
(
const
MemSwapManager
&
)
=
delete
;
void
AddSwapInfo
();
void
ResetSwapInfo
();
void
AddKernelTriggerSwap
(
const
AnfNodePtr
&
kernel
,
bool
trigger_swap
);
void
AddKernelNeedSwap
(
const
AnfNodePtr
&
kernel
,
bool
need_swap
);
void
AddKernelMemSwapInfo
(
const
AnfNodePtr
&
kernel
,
const
MemSwapInfo
&
mem_swap_info
);
std
::
vector
<
CNodePtr
>
execution_order_
;
std
::
vector
<
TensorInfo
>
ordered_tensors_
;
std
::
unordered_map
<
void
*
,
KernelExecutionInfo
>
kernel_execution_info_
;
std
::
unordered_map
<
void
*
,
std
::
map
<
size_t
,
PerformPair
>>
kernel_swap_perform_
;
// trigger swap kernel key : MemSwapInfo of kernel need to be swapped
std
::
unordered_map
<
void
*
,
std
::
vector
<
MemSwapInfo
>>
mem_swap_info_
;
std
::
vector
<
HostAddress
>
host_addrs_list_
;
std
::
unordered_set
<
const
void
*>
swap_in_blacklist_
;
size_t
tensor_size_threshold_
;
size_t
tensor_size_threshold_idx_
;
size_t
tensor_size_num_
;
size_t
distance_threshold_
;
MemCopyManagerPtr
mem_copy_manager_
{
nullptr
};
bool
mem_swap_initialized_
{
false
};
bool
swap_info_already_set_
{
false
};
bool
trigger_swap_
{
false
};
};
using
MemSwapManagerPtr
=
std
::
shared_ptr
<
MemSwapManager
>
;
}
// namespace memswap
}
// namespace device
}
// namespace mindspore
#endif // MINDSPORE_CCSRC_PRE_ACTIVATE_MEM_REUSE_MEM_SWAP_MANAGER_H_
mindspore/ccsrc/pre_activate/mem_reuse/mem_swap_util.h
0 → 100644
浏览文件 @
49d81260
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MINDSPORE_CCSRC_PRE_ACTIVATE_MEM_REUSE_MEM_SWAP_UTIL_H_
#define MINDSPORE_CCSRC_PRE_ACTIVATE_MEM_REUSE_MEM_SWAP_UTIL_H_
#include <vector>
#include <map>
#include <queue>
#include <memory>
#include <utility>
#include "session/kernel_graph.h"
#include "device/gpu/cuda_driver.h"
#include "kernel/kernel.h"
using
mindspore
::
device
::
gpu
::
DeviceEvent
;
using
mindspore
::
device
::
gpu
::
DeviceMemPtr
;
using
mindspore
::
device
::
gpu
::
DeviceStream
;
using
mindspore
::
device
::
gpu
::
HostMemPtr
;
using
HostAddress
=
mindspore
::
kernel
::
Address
;
namespace
mindspore
{
namespace
device
{
namespace
memswap
{
enum
class
SwapKind
{
kDeviceToHost
=
0
,
kHostToDevice
=
1
};
struct
TensorInfo
{
size_t
tensor_size_
{
0
};
AnfNodePtr
kernel_
{
nullptr
};
size_t
output_idx_
{
0
};
};
struct
KernelExecutionInfo
{
size_t
topo_order_
{
0
};
float
execution_perform_
{
0.0
};
bool
trigger_swap_
{
false
};
bool
need_swap_
{
false
};
// output index to topo orders of node users
std
::
map
<
size_t
,
std
::
vector
<
size_t
>>
node_users_map_
;
// kernel output idx to host addr
std
::
map
<
size_t
,
HostAddress
>
host_addrs_
;
KernelExecutionInfo
()
:
KernelExecutionInfo
(
0
,
0.0
,
false
,
false
)
{}
explicit
KernelExecutionInfo
(
size_t
topo_order
)
:
topo_order_
(
topo_order
),
execution_perform_
(
0.0
),
trigger_swap_
(
false
),
need_swap_
(
false
)
{}
KernelExecutionInfo
(
size_t
topo_order
,
float
execution_perform
,
bool
trigger_swap
,
bool
need_swap
)
:
topo_order_
(
topo_order
),
execution_perform_
(
execution_perform
),
trigger_swap_
(
trigger_swap
),
need_swap_
(
need_swap
)
{}
};
// trigger swap
struct
MemSwapInfo
{
SwapKind
swap_kind_
;
// kernel need to be swapped
AnfNodePtr
kernel_
{
nullptr
};
size_t
output_idx_
{
0
};
};
class
MemCopyManager
{
public:
MemCopyManager
()
=
default
;
~
MemCopyManager
()
=
default
;
void
Init
();
void
AddMemSwapOutTask
(
const
DeviceAddressPtr
&
device_address
,
const
HostAddress
&
host_addr
);
void
AddMemSwapInTask
(
const
DeviceAddressPtr
&
device_address
,
const
HostAddress
&
host_addr
);
bool
SyncMemCopyStream
(
SwapKind
swap_kind
);
DeviceAddressPtr
UpdateSwapOutQueue
();
DeviceAddressPtr
UpdateSwapInQueue
();
void
ClearSwapQueue
();
private:
DeviceStream
swap_out_stream_
{
nullptr
};
DeviceStream
swap_in_stream_
{
nullptr
};
std
::
queue
<
std
::
pair
<
DeviceAddressPtr
,
DeviceEvent
>>
swap_out_queue_
;
std
::
queue
<
std
::
pair
<
DeviceAddressPtr
,
DeviceEvent
>>
swap_in_queue_
;
};
using
MemCopyManagerPtr
=
std
::
shared_ptr
<
MemCopyManager
>
;
}
// namespace memswap
}
// namespace device
}
// namespace mindspore
#endif // MINDSPORE_CCSRC_PRE_ACTIVATE_MEM_REUSE_MEM_SWAP_UTIL_H_
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录