Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
1b0c7d7c
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
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看板
未验证
提交
1b0c7d7c
编写于
12月 15, 2017
作者:
Y
Yu Yang
提交者:
GitHub
12月 15, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplize system_allocator and fix GPU_INFO (#6653)
上级
c13805e9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
23 addition
and
46 deletion
+23
-46
paddle/memory/detail/system_allocator.cc
paddle/memory/detail/system_allocator.cc
+13
-37
paddle/platform/gpu_info.cc
paddle/platform/gpu_info.cc
+10
-9
未找到文件。
paddle/memory/detail/system_allocator.cc
浏览文件 @
1b0c7d7c
...
...
@@ -19,6 +19,7 @@ limitations under the License. */
#include <stdlib.h> // for malloc and free
#include <sys/mman.h> // for mlock and munlock
#include <algorithm> // for std::max
#include "gflags/gflags.h"
...
...
@@ -28,7 +29,7 @@ limitations under the License. */
// of memory available to the system for paging. So, by default, we
// should set false to use_pinned_memory.
DEFINE_bool
(
use_pinned_memory
,
true
,
"If set, allocate cpu pinned memory."
);
DECLARE_double
(
fraction_of_gpu_memory_to_use
);
namespace
paddle
{
namespace
memory
{
namespace
detail
{
...
...
@@ -77,45 +78,20 @@ void* GPUAllocator::Alloc(size_t& index, size_t size) {
// CUDA documentation doesn't explain if cudaMalloc returns nullptr
// if size is 0. We just make sure it does.
if
(
size
<=
0
)
return
nullptr
;
size_t
available
=
0
;
size_t
capacity
=
0
;
paddle
::
platform
::
GpuMemoryUsage
(
available
,
capacity
);
// Reserve memory for page tables, etc.
size_t
reserving
=
0.05
*
capacity
+
paddle
::
platform
::
GpuMinChunkSize
();
size_t
usable
=
available
>
reserving
?
available
-
reserving
:
0
;
// If remaining size no less than expected size, using general
// cudaMalloc to allocate GPU memory.
void
*
p
=
0
;
if
(
size
<=
usable
)
{
cudaError_t
result
=
cudaMalloc
(
&
p
,
size
);
if
(
result
==
cudaSuccess
)
{
index
=
0
;
gpu_alloc_size_
+=
size
;
return
p
;
}
}
// If remaining size less than expected size or cudaMalloc failed,
// cudaMallocHost will be considered as a fallback allocator.
//
// NOTE: here, we use GpuMaxAllocSize() as the maximum memory size
// of host fallback allocation. Allocates too much would reduce
// the amount of memory available to the underlying system for paging.
usable
=
paddle
::
platform
::
GpuMaxAllocSize
()
-
fallback_alloc_size_
;
if
(
size
>
usable
)
return
nullptr
;
cudaError_t
result
=
cudaMallocHost
(
&
p
,
size
);
void
*
p
;
cudaError_t
result
=
cudaMalloc
(
&
p
,
size
);
if
(
result
==
cudaSuccess
)
{
index
=
1
;
fallback
_alloc_size_
+=
size
;
index
=
0
;
gpu
_alloc_size_
+=
size
;
return
p
;
}
else
{
LOG
(
WARNING
)
<<
"Cannot malloc "
<<
size
/
1024.0
/
1024.0
<<
" MB GPU memory. Please shrink FLAGS_fraction_of_gpu_memory_to_use "
"environment variable to a lower value. Current value is "
<<
FLAGS_fraction_of_gpu_memory_to_use
;
return
nullptr
;
}
return
nullptr
;
}
void
GPUAllocator
::
Free
(
void
*
p
,
size_t
size
,
size_t
index
)
{
...
...
paddle/platform/gpu_info.cc
浏览文件 @
1b0c7d7c
...
...
@@ -73,19 +73,20 @@ size_t GpuMaxChunkSize() {
size_t
available
=
0
;
GpuMemoryUsage
(
available
,
total
);
// Reserving the rest memory for page tables, etc.
size_t
reserving
=
0.05
*
total
;
VLOG
(
10
)
<<
"GPU Usage "
<<
available
/
1024
/
1024
<<
"M/"
<<
total
/
1024
/
1024
<<
"M"
;
size_t
reserving
=
static_cast
<
size_t
>
(
0.05
*
total
);
// If available less than minimum chunk size, no usable memory exists.
available
=
std
::
max
(
std
::
max
(
available
,
GpuMinChunkSize
())
-
GpuMinChunkSize
(),
reserving
)
-
reserving
;
std
::
min
(
std
::
max
(
available
,
GpuMinChunkSize
())
-
GpuMinChunkSize
(),
total
-
reserving
);
// Reserving the rest memory for page tables, etc.
size_t
allocating
=
FLAGS_fraction_of_gpu_memory_to_use
*
total
;
size_t
allocating
=
static_cast
<
size_t
>
(
FLAGS_fraction_of_gpu_memory_to_use
*
(
total
-
reserving
));
PADDLE_ENFORCE_L
T
(
allocating
,
available
);
PADDLE_ENFORCE_L
E
(
allocating
,
available
);
return
allocating
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录