Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
a669bf48
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
694
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a669bf48
编写于
7月 06, 2017
作者:
L
liaogang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FIX: explicit construct pool element
上级
3ad8e364
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
13 addition
and
10 deletion
+13
-10
paddle/memory/detail/buddy_allocator.cc
paddle/memory/detail/buddy_allocator.cc
+13
-10
未找到文件。
paddle/memory/detail/buddy_allocator.cc
浏览文件 @
a669bf48
...
@@ -118,8 +118,9 @@ void BuddyAllocator::Free(void* p) {
...
@@ -118,8 +118,9 @@ void BuddyAllocator::Free(void* p) {
if
(
right_buddy
->
type
(
cache_
)
==
MemoryBlock
::
FREE_CHUNK
)
{
if
(
right_buddy
->
type
(
cache_
)
==
MemoryBlock
::
FREE_CHUNK
)
{
// Take away right buddy from pool
// Take away right buddy from pool
pool_
.
erase
({
right_buddy
->
index
(
cache_
),
right_buddy
->
total_size
(
cache_
),
pool_
.
erase
(
IndexSizeAddress
(
right_buddy
->
index
(
cache_
),
right_buddy
});
right_buddy
->
total_size
(
cache_
),
right_buddy
));
// merge its right buddy to the block
// merge its right buddy to the block
block
->
merge
(
cache_
,
right_buddy
);
block
->
merge
(
cache_
,
right_buddy
);
...
@@ -135,8 +136,8 @@ void BuddyAllocator::Free(void* p) {
...
@@ -135,8 +136,8 @@ void BuddyAllocator::Free(void* p) {
if
(
left_buddy
->
type
(
cache_
)
==
MemoryBlock
::
FREE_CHUNK
)
{
if
(
left_buddy
->
type
(
cache_
)
==
MemoryBlock
::
FREE_CHUNK
)
{
// Take away right buddy from pool
// Take away right buddy from pool
pool_
.
erase
(
{
left_buddy
->
index
(
cache_
),
left_buddy
->
total_size
(
cache_
),
pool_
.
erase
(
IndexSizeAddress
(
left_buddy
->
index
(
cache_
),
left_buddy
}
);
left_buddy
->
total_size
(
cache_
),
left_buddy
)
);
// merge the block to its left buddy
// merge the block to its left buddy
left_buddy
->
merge
(
cache_
,
block
);
left_buddy
->
merge
(
cache_
,
block
);
...
@@ -147,7 +148,8 @@ void BuddyAllocator::Free(void* p) {
...
@@ -147,7 +148,8 @@ void BuddyAllocator::Free(void* p) {
// Dumping this block into pool
// Dumping this block into pool
DLOG
(
INFO
)
<<
"Inserting free block ("
<<
block
<<
", "
DLOG
(
INFO
)
<<
"Inserting free block ("
<<
block
<<
", "
<<
block
->
total_size
(
cache_
)
<<
")"
;
<<
block
->
total_size
(
cache_
)
<<
")"
;
pool_
.
insert
({
block
->
index
(
cache_
),
block
->
total_size
(
cache_
),
block
});
pool_
.
insert
(
IndexSizeAddress
(
block
->
index
(
cache_
),
block
->
total_size
(
cache_
),
block
));
// TODO(gangliao): Clean up if existing too much free memory
// TODO(gangliao): Clean up if existing too much free memory
}
}
...
@@ -193,14 +195,14 @@ BuddyAllocator::PoolSet::iterator BuddyAllocator::RefillPool() {
...
@@ -193,14 +195,14 @@ BuddyAllocator::PoolSet::iterator BuddyAllocator::RefillPool() {
total_free_
+=
max_chunk_size_
;
total_free_
+=
max_chunk_size_
;
// dump the block into pool
// dump the block into pool
return
pool_
.
insert
(
{
index
,
max_chunk_size_
,
p
}
).
first
;
return
pool_
.
insert
(
IndexSizeAddress
(
index
,
max_chunk_size_
,
p
)
).
first
;
}
}
BuddyAllocator
::
PoolSet
::
iterator
BuddyAllocator
::
FindExistChunk
(
size_t
size
)
{
BuddyAllocator
::
PoolSet
::
iterator
BuddyAllocator
::
FindExistChunk
(
size_t
size
)
{
size_t
index
=
0
;
size_t
index
=
0
;
while
(
1
)
{
while
(
1
)
{
auto
it
=
pool_
.
lower_bound
(
{
index
,
size
,
nullptr
}
);
auto
it
=
pool_
.
lower_bound
(
IndexSizeAddress
(
index
,
size
,
nullptr
)
);
// no match chunk memory
// no match chunk memory
if
(
it
==
pool_
.
end
())
return
it
;
if
(
it
==
pool_
.
end
())
return
it
;
...
@@ -237,9 +239,10 @@ void* BuddyAllocator::SplitToAlloc(BuddyAllocator::PoolSet::iterator it,
...
@@ -237,9 +239,10 @@ void* BuddyAllocator::SplitToAlloc(BuddyAllocator::PoolSet::iterator it,
DLOG
(
INFO
)
<<
"Insert right block ("
<<
block
->
right_buddy
(
cache_
)
<<
", "
DLOG
(
INFO
)
<<
"Insert right block ("
<<
block
->
right_buddy
(
cache_
)
<<
", "
<<
block
->
right_buddy
(
cache_
)
->
total_size
(
cache_
)
<<
")"
;
<<
block
->
right_buddy
(
cache_
)
->
total_size
(
cache_
)
<<
")"
;
pool_
.
insert
({
block
->
right_buddy
(
cache_
)
->
index
(
cache_
),
pool_
.
insert
(
block
->
right_buddy
(
cache_
)
->
total_size
(
cache_
),
IndexSizeAddress
(
block
->
right_buddy
(
cache_
)
->
index
(
cache_
),
block
->
right_buddy
(
cache_
)});
block
->
right_buddy
(
cache_
)
->
total_size
(
cache_
),
block
->
right_buddy
(
cache_
)));
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录