Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
0ba63475
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看板
提交
0ba63475
编写于
7月 04, 2017
作者:
L
liaogang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ENH: Add buddy allocator Free
上级
379434b2
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
65 addition
and
20 deletion
+65
-20
paddle/memory/detail/CMakeLists.txt
paddle/memory/detail/CMakeLists.txt
+3
-6
paddle/memory/detail/buddy_allocator.cc
paddle/memory/detail/buddy_allocator.cc
+40
-1
paddle/memory/detail/buddy_allocator.h
paddle/memory/detail/buddy_allocator.h
+1
-1
paddle/memory/detail/memory_block.h
paddle/memory/detail/memory_block.h
+1
-1
paddle/memory/detail/meta_data.cc
paddle/memory/detail/meta_data.cc
+1
-1
paddle/memory/detail/meta_data.h
paddle/memory/detail/meta_data.h
+0
-0
paddle/platform/cpu_info.h
paddle/platform/cpu_info.h
+0
-10
paddle/platform/gpu_info.cc
paddle/platform/gpu_info.cc
+13
-0
paddle/platform/gpu_info.h
paddle/platform/gpu_info.h
+6
-0
未找到文件。
paddle/memory/detail/CMakeLists.txt
浏览文件 @
0ba63475
if
(
${
WITH_GPU
}
)
if
(
${
WITH_GPU
}
)
nv_library
(
system_allocator SRCS system_allocator.cc DEPS gflags
)
nv_library
(
system_allocator SRCS system_allocator.cc DEPS gflags gpu_info
)
nv_test
(
system_allocator_test
SRCS system_allocator_test.cc
DEPS system_allocator gpu_info gflags
)
else
(
${
WITH_GPU
}
)
else
(
${
WITH_GPU
}
)
cc_library
(
system_allocator SRCS system_allocator.cc DEPS gflags
)
cc_library
(
system_allocator SRCS system_allocator.cc DEPS gflags
)
cc_test
(
system_allocator_test SRCS system_allocator_test.cc DEPS system_allocator gflags
)
endif
(
${
WITH_GPU
}
)
endif
(
${
WITH_GPU
}
)
cc_test
(
system_allocator_test SRCS system_allocator_test.cc DEPS system_allocator
)
cc_library
(
meta
data SRCS meta
data.cc
)
cc_library
(
meta
_data SRCS meta_
data.cc
)
cc_library
(
buddy_allocator SRCS buddy_allocator.cc
)
cc_library
(
buddy_allocator SRCS buddy_allocator.cc
)
paddle/memory/detail/buddy_allocator.cc
浏览文件 @
0ba63475
...
@@ -75,10 +75,49 @@ void* BuddyAllocator::Alloc(size_t unaligned_size) {
...
@@ -75,10 +75,49 @@ void* BuddyAllocator::Alloc(size_t unaligned_size) {
}
}
void
BuddyAllocator
::
Free
(
void
*
p
)
{
void
BuddyAllocator
::
Free
(
void
*
p
)
{
// Point back to metadata
auto
block
=
static_cast
<
MemoryBlock
*>
(
p
)
->
metadata
();
auto
block
=
static_cast
<
MemoryBlock
*>
(
p
)
->
metadata
();
//
a
cquire the allocator lock
//
A
cquire the allocator lock
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
mutex_
);
DLOG
(
INFO
)
<<
"Free from address "
<<
block
;
if
(
block
->
type
(
cache_
)
==
MemoryBlock
::
HUGE_CHUNK
)
{
DLOG
(
INFO
)
<<
"Free directly from system allocator"
;
system_allocator_
->
Free
(
block
,
block
->
total_size
(
cache_
),
block
->
index
(
cache_
));
// Invalidate GPU allocation from cache
if
(
system_allocator_
->
UseGpu
())
{
cache_
.
erase
(
block
);
}
return
;
}
block
->
mark_as_free
(
cache_
);
total_used_
-=
block
->
total_size
(
cache_
);
total_free_
+=
block
->
total_size
(
cache_
);
// Trying to merge the right buddy
if
(
block
->
has_right_buddy
(
cache_
))
{
DLOG
(
INFO
)
<<
"Merging this block "
<<
block
<<
" with its right buddy "
<<
block
->
right_buddy
(
cache_
);
}
// Trying to merge the left buddy
if
(
block
->
has_left_buddy
(
cache_
))
{
DLOG
(
INFO
)
<<
"Merging this block "
<<
block
<<
" with its left buddy "
<<
block
->
left_buddy
(
cache_
);
}
// Dumping this block into pool
DLOG
(
INFO
)
<<
"Inserting free block ("
<<
block
<<
", "
<<
block
->
total_size
(
cache_
)
<<
")"
;
pool_
.
insert
({
block
->
index
(
cache_
),
block
->
total_size
(
cache_
),
block
});
// TODO(gangliao): Clean up if existing too much free memory
}
}
void
*
BuddyAllocator
::
SystemAlloc
(
size_t
size
)
{
void
*
BuddyAllocator
::
SystemAlloc
(
size_t
size
)
{
...
...
paddle/memory/detail/buddy_allocator.h
浏览文件 @
0ba63475
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
#pragma once
#pragma once
#include "paddle/memory/detail/metadata.h"
#include "paddle/memory/detail/meta
_
data.h"
#include "paddle/memory/detail/system_allocator.h"
#include "paddle/memory/detail/system_allocator.h"
#include "paddle/platform/assert.h"
#include "paddle/platform/assert.h"
#include "paddle/platform/cpu_info.h"
#include "paddle/platform/cpu_info.h"
...
...
paddle/memory/detail/memory_block.h
浏览文件 @
0ba63475
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
#pragma once
#pragma once
#include "paddle/memory/detail/metadata.h"
#include "paddle/memory/detail/meta
_
data.h"
#include <cstddef>
#include <cstddef>
#include <unordered_map>
#include <unordered_map>
...
...
paddle/memory/detail/metadata.cc
→
paddle/memory/detail/meta
_
data.cc
浏览文件 @
0ba63475
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
See the License for the specific language governing permissions and
See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#include "paddle/memory/detail/metadata.h"
#include "paddle/memory/detail/meta
_
data.h"
#include <functional>
#include <functional>
...
...
paddle/memory/detail/metadata.h
→
paddle/memory/detail/meta
_
data.h
浏览文件 @
0ba63475
文件已移动
paddle/platform/cpu_info.h
浏览文件 @
0ba63475
...
@@ -28,15 +28,5 @@ size_t CpuMinChunkSize();
...
@@ -28,15 +28,5 @@ size_t CpuMinChunkSize();
//! Get the maximum chunk size for buddy allocator.
//! Get the maximum chunk size for buddy allocator.
size_t
CpuMaxChunkSize
();
size_t
CpuMaxChunkSize
();
int
GetCurrentDeviceId
(
void
)
{
int
device_id
;
throw_on_error
(
cudaGetDevice
(
&
device_id
),
"cudaGetDevice failed"
);
return
device_id
;
}
void
SetDeviceId
(
int
device_id
)
{
throw_on_error
(
cudaSetDevice
(
device_id
),
"cudaSetDevice failed"
);
}
}
// namespace platform
}
// namespace platform
}
// namespace paddle
}
// namespace paddle
paddle/platform/gpu_info.cc
浏览文件 @
0ba63475
...
@@ -31,6 +31,19 @@ int GpuDeviceCount() {
...
@@ -31,6 +31,19 @@ int GpuDeviceCount() {
return
count
;
return
count
;
}
}
int
GetCurrentDeviceId
()
{
int
device_id
;
throw_on_error
(
cudaGetDevice
(
&
device_id
),
"cudaGetDevice failed in paddle::platform::GetCurrentDeviceId"
);
return
device_id
;
}
void
SetDeviceId
(
int
id
)
{
throw_on_error
(
cudaSetDevice
(
id
),
"cudaSetDevice failed in paddle::platform::SetDeviceId"
);
}
void
GpuMemoryUsage
(
size_t
&
available
,
size_t
&
total
)
{
void
GpuMemoryUsage
(
size_t
&
available
,
size_t
&
total
)
{
throw_on_error
(
cudaMemGetInfo
(
&
available
,
&
total
),
throw_on_error
(
cudaMemGetInfo
(
&
available
,
&
total
),
"cudaMemGetInfo failed in paddle::platform::GetMemoryUsage"
);
"cudaMemGetInfo failed in paddle::platform::GetMemoryUsage"
);
...
...
paddle/platform/gpu_info.h
浏览文件 @
0ba63475
...
@@ -24,6 +24,12 @@ namespace platform {
...
@@ -24,6 +24,12 @@ namespace platform {
//! Get the total number of GPU devices in system.
//! Get the total number of GPU devices in system.
int
GpuDeviceCount
();
int
GpuDeviceCount
();
//! Get the current GPU device id in system.
int
GetCurrentDeviceId
();
//! Set the GPU device id for next execution.
void
SetDeviceId
(
int
device_id
);
//!Get the memory usage of current GPU device.
//!Get the memory usage of current GPU device.
void
GpuMemoryUsage
(
size_t
&
available
,
size_t
&
total
);
void
GpuMemoryUsage
(
size_t
&
available
,
size_t
&
total
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录