Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
d4017cad
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d4017cad
编写于
7月 11, 2017
作者:
L
liaogang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ENH: Add auto-free if allocate too much
上级
49fd49f7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
70 addition
and
2 deletion
+70
-2
paddle/memory/detail/buddy_allocator.cc
paddle/memory/detail/buddy_allocator.cc
+67
-2
paddle/memory/detail/buddy_allocator.h
paddle/memory/detail/buddy_allocator.h
+3
-0
未找到文件。
paddle/memory/detail/buddy_allocator.cc
浏览文件 @
d4017cad
...
...
@@ -152,7 +152,7 @@ void BuddyAllocator::Free(void* p) {
IndexSizeAddress
(
block
->
index
(
cache_
),
block
->
total_size
(
cache_
),
block
));
// Clean up if existing too much free memory
// Prefer freeing fallback allocation first
CleanIdleFallBackAlloc
();
...
...
@@ -198,6 +198,12 @@ BuddyAllocator::PoolSet::iterator BuddyAllocator::RefillPool() {
static_cast
<
MemoryBlock
*>
(
p
)
->
init
(
cache_
,
MemoryBlock
::
FREE_CHUNK
,
index
,
max_chunk_size_
,
nullptr
,
nullptr
);
// gpu fallback allocation
if
(
system_allocator_
->
UseGpu
()
&&
static_cast
<
MemoryBlock
*>
(
p
)
->
index
(
cache_
)
==
1
)
{
fallback_alloc_count_
++
;
}
total_free_
+=
max_chunk_size_
;
// dump the block into pool
...
...
@@ -256,9 +262,68 @@ void* BuddyAllocator::SplitToAlloc(BuddyAllocator::PoolSet::iterator it,
}
void
BuddyAllocator
::
CleanIdleFallBackAlloc
()
{
// If fallback allocation does not exist, return directly
if
(
!
fallback_alloc_count_
)
return
;
for
(
auto
pool
=
pool_
.
rbegin
();
pool
!=
pool_
.
rend
();)
{
// If free memory block less than max_chunk_size_, return directly
if
(
std
::
get
<
1
>
(
*
pool
)
<
max_chunk_size_
)
return
;
MemoryBlock
*
block
=
static_cast
<
MemoryBlock
*>
(
std
::
get
<
2
>
(
*
pool
));
// If no GPU fallback allocator, return
if
(
!
system_allocator_
->
UseGpu
()
||
block
->
index
(
cache_
)
==
0
)
{
return
;
}
DLOG
(
INFO
)
<<
"Return block "
<<
block
<<
" to fallback allocator."
;
system_allocator_
->
Free
(
block
,
max_chunk_size_
,
block
->
index
(
cache_
));
cache_
.
invalidate
(
block
);
pool
=
PoolSet
::
reverse_iterator
(
pool_
.
erase
(
std
::
next
(
pool
).
base
()));
total_free_
-=
max_chunk_size_
;
fallback_alloc_count_
--
;
// If no fall allocation exists, return directly
if
(
!
fallback_alloc_count_
)
return
;
}
}
void
BuddyAllocator
::
CleanIdleNormalAlloc
()
{
auto
shall_free_alloc
=
[
&
]()
->
bool
{
// free all fallback allocations
if
(
fallback_alloc_count_
>
0
)
{
return
true
;
}
// keep 2x overhead if we haven't fallen back
if
((
total_used_
+
max_chunk_size_
)
*
2
<
total_free_
)
{
return
true
;
}
return
false
;
};
if
(
!
shall_free_alloc
())
return
;
for
(
auto
pool
=
pool_
.
rbegin
();
pool
!=
pool_
.
rend
();)
{
// If free memory block less than max_chunk_size_, return directly
if
(
std
::
get
<
1
>
(
*
pool
)
<
max_chunk_size_
)
return
;
MemoryBlock
*
block
=
static_cast
<
MemoryBlock
*>
(
std
::
get
<
2
>
(
*
pool
));
DLOG
(
INFO
)
<<
"Return block "
<<
block
<<
" to base allocator."
;
system_allocator_
->
Free
(
block
,
max_chunk_size_
,
block
->
index
(
cache_
));
cache_
.
invalidate
(
block
);
pool
=
PoolSet
::
reverse_iterator
(
pool_
.
erase
(
std
::
next
(
pool
).
base
()));
total_free_
-=
max_chunk_size_
;
if
(
!
shall_free_alloc
())
return
;
}
}
}
// namespace detail
}
// namespace memory
...
...
paddle/memory/detail/buddy_allocator.h
浏览文件 @
d4017cad
...
...
@@ -94,6 +94,9 @@ class BuddyAllocator {
*/
PoolSet
pool_
;
/*! Record fallback allocation count for auto-scaling */
size_t
fallback_alloc_count_
=
0
;
private:
/*! Unify the metadata format between GPU and CPU allocations */
MetadataCache
cache_
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录