未验证 提交 3a0a4586 编写于 作者: Q QI JUN 提交者: GitHub

refine GPU memory allocation policy (#6373)

* fix gpu memory allocation policy

* refine codes

* fix code style

* follow comments
上级 c096130a
...@@ -83,7 +83,7 @@ void* GPUAllocator::Alloc(size_t& index, size_t size) { ...@@ -83,7 +83,7 @@ void* GPUAllocator::Alloc(size_t& index, size_t size) {
paddle::platform::GpuMemoryUsage(available, capacity); paddle::platform::GpuMemoryUsage(available, capacity);
// Reserve memory for page tables, etc. // Reserve memory for page tables, etc.
size_t reserving = capacity - paddle::platform::GpuMaxAllocSize(); size_t reserving = 0.05 * capacity + paddle::platform::GpuMinChunkSize();
size_t usable = available > reserving ? available - reserving : 0; size_t usable = available > reserving ? available - reserving : 0;
// If remaining size no less than expected size, using general // If remaining size no less than expected size, using general
......
...@@ -64,19 +64,21 @@ BuddyAllocator* GetGPUBuddyAllocator(int gpu_id) { ...@@ -64,19 +64,21 @@ BuddyAllocator* GetGPUBuddyAllocator(int gpu_id) {
int gpu_num = platform::GetCUDADeviceCount(); int gpu_num = platform::GetCUDADeviceCount();
as = new BuddyAllocator*[gpu_num]; as = new BuddyAllocator*[gpu_num];
for (int gpu = 0; gpu < gpu_num; gpu++) { for (int gpu = 0; gpu < gpu_num; gpu++) {
platform::SetDeviceId(gpu); as[gpu] = nullptr;
as[gpu] = new BuddyAllocator(new detail::GPUAllocator, }
}
platform::SetDeviceId(gpu_id);
if (!as[gpu_id]) {
as[gpu_id] = new BuddyAllocator(new detail::GPUAllocator,
platform::GpuMinChunkSize(), platform::GpuMinChunkSize(),
platform::GpuMaxChunkSize()); platform::GpuMaxChunkSize());
}
VLOG(10) << "\n\nNOTE: each GPU device use " VLOG(10) << "\n\nNOTE: each GPU device use "
<< FLAGS_fraction_of_gpu_memory_to_use * 100 << FLAGS_fraction_of_gpu_memory_to_use * 100
<< "% of GPU memory.\n" << "% of GPU memory.\n"
<< "You can set environment variable '" << "You can set GFlags environment variable '"
<< platform::kEnvFractionGpuMemoryToUse << "FLAGS_fraction_of_gpu_memory_to_use"
<< "' to change the fraction of GPU usage.\n\n"; << "' to change the fraction of GPU usage.\n\n";
} }
platform::SetDeviceId(gpu_id);
return as[gpu_id]; return as[gpu_id];
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册