Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
a7b9ece4
MegEngine
项目概览
MegEngine 天元
/
MegEngine
大约 1 年 前同步成功
通知
399
Star
4705
Fork
582
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
MegEngine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a7b9ece4
编写于
9月 03, 2020
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(mgb/comp_node): add set_prealloc_config
GitOrigin-RevId: e725e7efdd78e4e8ae85ac963988aef55ee5f9c4
上级
066da0bf
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
49 addition
and
14 deletion
+49
-14
imperative/python/megengine/device.py
imperative/python/megengine/device.py
+10
-9
imperative/python/src/common.cpp
imperative/python/src/common.cpp
+3
-0
src/core/impl/comp_node/comp_node.cpp
src/core/impl/comp_node/comp_node.cpp
+17
-0
src/core/impl/comp_node/cuda/comp_node.cpp
src/core/impl/comp_node/cuda/comp_node.cpp
+8
-3
src/core/impl/comp_node/cuda/comp_node.h
src/core/impl/comp_node/cuda/comp_node.h
+3
-2
src/core/include/megbrain/comp_node.h
src/core/include/megbrain/comp_node.h
+8
-0
未找到文件。
imperative/python/megengine/device.py
浏览文件 @
a7b9ece4
...
...
@@ -9,6 +9,7 @@
import
os
from
.core._imperative_rt.common
import
CompNode
,
DeviceType
from
.core._imperative_rt.common
import
set_prealloc_config
as
_set_prealloc_config
__all__
=
[
"is_cuda_available"
,
...
...
@@ -16,6 +17,7 @@ __all__ = [
"get_default_device"
,
"set_default_device"
,
"set_prealloc_config"
,
"DeviceType"
,
]
...
...
@@ -94,15 +96,15 @@ def set_prealloc_config(
alignment
:
int
=
1
,
min_req
:
int
=
32
*
1024
*
1024
,
max_overhead
:
int
=
0
,
growth_factor
:
float
=
2.0
,
device_type
:
str
=
"gpu"
,
growth_factor
=
2.0
,
device_type
=
DeviceType
.
CUDA
,
):
"""specifies how to pre-allocate from raw dev
ice
allocator
"""specifies how to pre-allocate from raw dev allocator
:param alignment: specifies the alignment in byte
:param min_req: min request size in byte
:param max_overhead: max overhead above required size in byte
:growth_factor: request size
= growth_factor * current allocated size
:param alignment: specifies the alignment in byte
s.
:param min_req: min request size in byte
s.
:param max_overhead: max overhead above required size in byte
s.
:growth_factor: request size
/ cur allocated
:device_type: the device type
"""
...
...
@@ -110,5 +112,4 @@ def set_prealloc_config(
assert
min_req
>
0
assert
max_overhead
>=
0
assert
growth_factor
>=
1
t
=
_str2device_type
(
device_type
)
_set_prealloc_config
(
alignment
,
min_req
,
max_overhead
,
growth_factor
,
t
)
_set_prealloc_config
(
alignment
,
min_req
,
max_overhead
,
growth_factor
,
device_type
)
imperative/python/src/common.cpp
浏览文件 @
a7b9ece4
...
...
@@ -165,6 +165,9 @@ void init_common(py::module m) {
.
value
(
"MULTITHREAD"
,
CompNode
::
DeviceType
::
MULTITHREAD
)
.
value
(
"MAX_DEVICE_ID"
,
CompNode
::
DeviceType
::
MAX_DEVICE_ID
);
m
.
def
(
"set_prealloc_config"
,
&
CompNode
::
set_prealloc_config
,
"specifies how to pre-allocate from raw dev allocator"
);
init_npy_num_bfloat16
(
m
);
init_npy_num_intbx
(
m
);
}
src/core/impl/comp_node/comp_node.cpp
浏览文件 @
a7b9ece4
...
...
@@ -12,6 +12,8 @@
#include "megbrain/comp_node.h"
#include "megbrain/comp_node_env.h"
#include "megbrain/graph/exc_extra_info.h"
#include "megbrain/common.h"
#include "megbrain/comp_node/alloc.h"
#include "./cuda/comp_node.h"
#include "./cpu/comp_node.h"
...
...
@@ -420,6 +422,21 @@ void CompNode::activate() const {
static_cast
<
Impl
*>
(
m_impl
)
->
env
().
activate
();
}
void
CompNode
::
set_prealloc_config
(
size_t
alignment
,
size_t
min_req
,
size_t
max_overhead
,
double
growth_factor
,
DeviceType
device_type
)
{
switch
(
device_type
)
{
case
DeviceType
::
CUDA
:
CudaCompNode
::
set_prealloc_config
(
alignment
,
min_req
,
max_overhead
,
growth_factor
);
break
;
default:
mgb_log_warn
(
"unsupported device type for set_prealloc_config"
);
};
}
void
*
CompNode
::
alloc_device
(
size_t
size
)
const
{
auto
ret
=
m_impl
->
alloc_device
(
size
);
static_cast
<
Impl
*>
(
m_impl
)
->
env
().
on_mem_event
(
size
,
true
,
ret
);
...
...
src/core/impl/comp_node/cuda/comp_node.cpp
浏览文件 @
a7b9ece4
...
...
@@ -825,15 +825,16 @@ void CudaCompNode::set_prealloc_config(size_t alignment, size_t min_req,
using
T
=
CudaCompNodeImpl
::
StaticData
;
static
std
::
aligned_storage_t
<
sizeof
(
T
),
alignof
(
T
)
>
storage
;
sdptr
=
new
(
&
storage
)
T
;
MGB_LOCK_GUARD
(
sdptr
->
mtx
);
sdptr
->
prealloc_config
.
alignment
=
alignment
;
sdptr
->
prealloc_config
.
min_req
=
min_req
;
sdptr
->
prealloc_config
.
growth_factor
=
growth_factor
;
sdptr
->
prealloc_config
.
max_overhead
=
max_overhead
;
}
else
{
mgb_log_warn
(
"failed to invoke set_prealloc_config; fallback to default configuration; "
"prealloc_config should be specified before any invocation of load_cuda"
);
"invalid call to set_prealloc_config, will fallback to "
"default config; "
"prealloc_config should be specified before any CUDA "
"memory allocation"
);
}
}
}
...
...
@@ -858,6 +859,10 @@ CudaCompNode::Impl* CudaCompNode::load_cuda(const Locator&, const Locator&) {
void
CudaCompNode
::
sync_all
()
{
}
void
CudaCompNode
::
set_prealloc_config
(
size_t
alignment
,
size_t
min_req
,
size_t
max_overhead
,
double
growth_factor
)
{}
#undef err
#endif // MGB_CUDA
...
...
src/core/impl/comp_node/cuda/comp_node.h
浏览文件 @
a7b9ece4
...
...
@@ -32,9 +32,10 @@ namespace mgb {
static
Impl
*
load_cuda
(
const
Locator
&
locator
,
const
Locator
&
locator_logical
);
static
void
sync_all
();
static
void
set_prealloc_config
(
size_t
alignment
,
size_t
min_req
,
size_t
max_overhead
,
double
growth_factor
);
};
}
// vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}
src/core/include/megbrain/comp_node.h
浏览文件 @
a7b9ece4
...
...
@@ -308,6 +308,14 @@ class CompNode {
*/
static
void
try_coalesce_all_free_memory
();
/*
* \brief specifies how to pre-allocate from raw dev allocator
*
*/
static
void
set_prealloc_config
(
size_t
alignment
,
size_t
min_req
,
size_t
max_overhead
,
double
growth_factor
,
DeviceType
device_type
);
/* =================== synchronization ======================== */
class
Event
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录