Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
e98e2d36
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e98e2d36
编写于
4月 07, 2018
作者:
Y
Yi Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update
上级
ccd83ef6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
10 addition
and
9 deletion
+10
-9
paddle/fluid/memory/detail/buddy_allocator.cc
paddle/fluid/memory/detail/buddy_allocator.cc
+10
-9
未找到文件。
paddle/fluid/memory/detail/buddy_allocator.cc
浏览文件 @
e98e2d36
...
...
@@ -46,7 +46,8 @@ inline size_t align(size_t size, size_t alignment) {
void
*
BuddyAllocator
::
Alloc
(
size_t
unaligned_size
)
{
// adjust allocation alignment
size_t
size
=
align
(
unaligned_size
+
sizeof
(
Metadata
),
min_chunk_size_
);
size_t
size
=
align
(
unaligned_size
+
sizeof
(
MemoryBlock
::
Desc
),
min_chunk_size_
);
// acquire the allocator lock
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
...
...
@@ -103,7 +104,7 @@ void BuddyAllocator::Free(void* p) {
return
;
}
block
->
mark_as_free
(
cache_
);
block
->
mark_as_free
(
&
cache_
);
total_used_
-=
block
->
total_size
(
cache_
);
total_free_
+=
block
->
total_size
(
cache_
);
...
...
@@ -122,7 +123,7 @@ void BuddyAllocator::Free(void* p) {
right_buddy
));
// merge its right buddy to the block
block
->
merge
(
cache_
,
right_buddy
);
block
->
merge
(
&
cache_
,
right_buddy
);
}
}
...
...
@@ -139,7 +140,7 @@ void BuddyAllocator::Free(void* p) {
left_buddy
->
total_size
(
cache_
),
left_buddy
));
// merge the block to its left buddy
left_buddy
->
merge
(
cache_
,
block
);
left_buddy
->
merge
(
&
cache_
,
block
);
block
=
left_buddy
;
}
}
...
...
@@ -163,13 +164,13 @@ size_t BuddyAllocator::Used() { return total_used_; }
void
*
BuddyAllocator
::
SystemAlloc
(
size_t
size
)
{
size_t
index
=
0
;
void
*
p
=
system_allocator_
->
Alloc
(
index
,
size
);
void
*
p
=
system_allocator_
->
Alloc
(
&
index
,
size
);
VLOG
(
10
)
<<
"Allocated "
<<
p
<<
" from system allocator."
;
if
(
p
==
nullptr
)
return
nullptr
;
static_cast
<
MemoryBlock
*>
(
p
)
->
init
(
cache_
,
MemoryBlock
::
HUGE_CHUNK
,
index
,
static_cast
<
MemoryBlock
*>
(
p
)
->
init
(
&
cache_
,
MemoryBlock
::
HUGE_CHUNK
,
index
,
size
,
nullptr
,
nullptr
);
return
static_cast
<
MemoryBlock
*>
(
p
)
->
data
();
...
...
@@ -187,7 +188,7 @@ BuddyAllocator::PoolSet::iterator BuddyAllocator::RefillPool() {
// Allocate a new maximum sized block
size_t
index
=
0
;
void
*
p
=
system_allocator_
->
Alloc
(
index
,
max_chunk_size_
);
void
*
p
=
system_allocator_
->
Alloc
(
&
index
,
max_chunk_size_
);
if
(
p
==
nullptr
)
return
pool_
.
end
();
...
...
@@ -238,11 +239,11 @@ void* BuddyAllocator::SplitToAlloc(BuddyAllocator::PoolSet::iterator it,
VLOG
(
10
)
<<
"Split block ("
<<
block
<<
", "
<<
block
->
total_size
(
cache_
)
<<
") into"
;
block
->
split
(
cache_
,
size
);
block
->
split
(
&
cache_
,
size
);
VLOG
(
10
)
<<
"Left block ("
<<
block
<<
", "
<<
block
->
total_size
(
cache_
)
<<
")"
;
block
->
set_type
(
cache_
,
MemoryBlock
::
ARENA_CHUNK
);
block
->
set_type
(
&
cache_
,
MemoryBlock
::
ARENA_CHUNK
);
// the rest of memory if exist
if
(
block
->
has_right_buddy
(
cache_
))
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录