Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MegEngine 天元
MegEngine
提交
2676fb73
MegEngine
项目概览
MegEngine 天元
/
MegEngine
1 年多 前同步成功
通知
403
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看板
提交
2676fb73
编写于
11月 09, 2021
作者:
M
Megvii Engine Team
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(imperative): remove enable_defrag interface as it is enabled by default
GitOrigin-RevId: de9e7d7f16e4d17e1e283159bef35f3a86509dc6
上级
d909950f
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
14 addition
and
47 deletion
+14
-47
imperative/python/megengine/dtr/dtr.py
imperative/python/megengine/dtr/dtr.py
+0
-1
imperative/python/src/utils.cpp
imperative/python/src/utils.cpp
+0
-3
imperative/src/impl/blob_manager_impl.cpp
imperative/src/impl/blob_manager_impl.cpp
+12
-31
imperative/src/impl/blob_manager_impl.h
imperative/src/impl/blob_manager_impl.h
+0
-3
imperative/src/include/megbrain/imperative/blob_manager.h
imperative/src/include/megbrain/imperative/blob_manager.h
+0
-2
imperative/src/test/imperative.cpp
imperative/src/test/imperative.cpp
+2
-7
未找到文件。
imperative/python/megengine/dtr/dtr.py
浏览文件 @
2676fb73
...
...
@@ -10,7 +10,6 @@ import re
from
typing
import
Union
from
..core._imperative_rt.core2
import
set_option
as
_set_option
from
..core._imperative_rt.utils
import
_set_defrag
_eviction_threshold
=
0
_evictee_minimum_size
=
1024
**
2
...
...
imperative/python/src/utils.cpp
浏览文件 @
2676fb73
...
...
@@ -216,9 +216,6 @@ void init_utils(py::module m) {
#endif
// Debug code, internal only
m
.
def
(
"_set_defrag"
,
[](
bool
enable
)
{
mgb
::
imperative
::
BlobManager
::
inst
()
->
set_enable
(
enable
);
});
m
.
def
(
"_defrag"
,
[](
const
mgb
::
CompNode
&
cn
)
{
mgb
::
imperative
::
BlobManager
::
inst
()
->
defrag
(
cn
);
});
...
...
imperative/src/impl/blob_manager_impl.cpp
浏览文件 @
2676fb73
...
...
@@ -41,22 +41,14 @@ void BlobManagerImpl::unregister_blob(Blob* blob) {
}
void
BlobManagerImpl
::
alloc_with_defrag
(
Blob
*
blob
,
size_t
size
)
{
if
(
!
m_enable
)
{
// try alloc
MGB_TRY
{
alloc_direct
(
blob
,
size
);
}
// if fail, try defrag, alloc again
MGB_CATCH
(
MemAllocError
&
,
{
mgb_log_warn
(
"memory allocation failed for blob; try defragmenting"
);
defrag
(
blob
->
m_comp_node
);
alloc_direct
(
blob
,
size
);
}
else
{
// // debug
// defrag(blob->m_comp_node);
// alloc_direct(blob, storage, size);
// try alloc
MGB_TRY
{
alloc_direct
(
blob
,
size
);
}
// if fail, try defrag, alloc again
MGB_CATCH
(
MemAllocError
&
,
{
mgb_log_warn
(
"memory allocation failed for blob; try defragmenting"
);
defrag
(
blob
->
m_comp_node
);
alloc_direct
(
blob
,
size
);
});
}
});
}
void
BlobManagerImpl
::
alloc_direct
(
Blob
*
blob
,
size_t
size
)
{
...
...
@@ -69,16 +61,12 @@ void BlobManagerImpl::alloc_direct(Blob* blob, size_t size) {
DeviceTensorND
BlobManagerImpl
::
alloc_workspace_with_defrag
(
CompNode
cn
,
TensorLayout
layout
)
{
DeviceTensorND
dev_tensor
;
if
(
!
m_enable
)
{
MGB_TRY
{
dev_tensor
=
alloc_workspace
(
cn
,
layout
);
}
MGB_CATCH
(
MemAllocError
&
,
{
mgb_log_warn
(
"memory allocation failed for workspace; try defragmenting"
);
defrag
(
cn
);
dev_tensor
=
alloc_workspace
(
cn
,
layout
);
}
else
{
MGB_TRY
{
dev_tensor
=
alloc_workspace
(
cn
,
layout
);
}
MGB_CATCH
(
MemAllocError
&
,
{
mgb_log_warn
(
"memory allocation failed for workspace; try defragmenting"
);
defrag
(
cn
);
dev_tensor
=
alloc_workspace
(
cn
,
layout
);
});
}
});
return
dev_tensor
;
};
...
...
@@ -154,10 +142,6 @@ void BlobManagerImpl::defrag(const CompNode& cn) {
cn
.
sync
();
}
void
BlobManagerImpl
::
set_enable
(
bool
flag
)
{
m_enable
=
flag
;
}
struct
BlobManagerStub
:
BlobManager
{
void
alloc_direct
(
Blob
*
blob
,
size_t
size
)
{
mgb_assert
(
0
,
"prohibited after global variable destruction"
);
...
...
@@ -172,9 +156,6 @@ struct BlobManagerStub : BlobManager {
mgb_assert
(
0
,
"prohibited after global variable destruction"
);
};
void
unregister_blob
(
Blob
*
blob
){};
void
set_enable
(
bool
flag
)
{
mgb_assert
(
0
,
"prohibited after global variable destruction"
);
};
void
defrag
(
const
CompNode
&
cn
)
{
mgb_assert
(
0
,
"prohibited after global variable destruction"
);
};
...
...
imperative/src/impl/blob_manager_impl.h
浏览文件 @
2676fb73
...
...
@@ -38,7 +38,6 @@ class BlobManagerImpl final : public BlobManager {
std
::
mutex
m_mtx
;
CompNode
::
UnorderedMap
<
BlobSetWithMux
>
m_comp2blobs_map
;
bool
m_enable
=
true
;
void
defrag
(
const
CompNode
&
cn
)
override
;
...
...
@@ -57,8 +56,6 @@ public:
void
register_blob
(
Blob
*
blob
)
override
;
void
unregister_blob
(
Blob
*
blob
)
override
;
void
set_enable
(
bool
flag
)
override
;
};
}
// namespace imperative
...
...
imperative/src/include/megbrain/imperative/blob_manager.h
浏览文件 @
2676fb73
...
...
@@ -33,8 +33,6 @@ public:
virtual
void
unregister_blob
(
Blob
*
blob
)
=
0
;
virtual
void
set_enable
(
bool
flag
)
=
0
;
virtual
void
defrag
(
const
CompNode
&
cn
)
=
0
;
};
...
...
imperative/src/test/imperative.cpp
浏览文件 @
2676fb73
...
...
@@ -94,15 +94,13 @@ TEST(TestImperative, Split) {
}
#if MGB_CUDA && MGB_ENABLE_EXCEPTION
void
run_graph
(
size_t
mem_reserved
,
bool
enable_defrag
)
{
void
run_graph
(
size_t
mem_reserved
)
{
CompNode
::
try_coalesce_all_free_memory
();
CompNode
::
finalize
();
auto
cn
=
CompNode
::
load
(
"gpux"
);
cn
.
sync
();
// wait for async init to finish
BlobManager
::
inst
()
->
set_enable
(
enable_defrag
);
HostTensorGenerator
<>
gen
;
using
TensorPtr
=
std
::
shared_ptr
<
Tensor
>
;
TensorPtr
ptr_a
[
100
];
...
...
@@ -159,10 +157,7 @@ TEST(TestImperative, Defragment) {
}
auto
reserve_setting
=
ssprintf
(
"b:%zu"
,
reserve
);
auto
do_run
=
[
reserve
]()
{
ASSERT_THROW
(
run_graph
(
reserve
,
false
),
MemAllocError
);
run_graph
(
reserve
,
true
);
};
auto
do_run
=
[
reserve
]()
{
run_graph
(
reserve
);
};
// reserve memory explicitly to avoid uncontrollable factors
constexpr
const
char
*
KEY
=
"MGB_CUDA_RESERVE_MEMORY"
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录