Skip to content

Commit 3a0a458

Browse files
authored
refine GPU memory allocation policy (#6373)
* fix gpu memory allocation policy * refine codes * fix code style * follow comments
1 parent c096130 commit 3a0a458

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

paddle/memory/detail/system_allocator.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void* GPUAllocator::Alloc(size_t& index, size_t size) {
8383
paddle::platform::GpuMemoryUsage(available, capacity);
8484

8585
// Reserve memory for page tables, etc.
86-
size_t reserving = capacity - paddle::platform::GpuMaxAllocSize();
86+
size_t reserving = 0.05 * capacity + paddle::platform::GpuMinChunkSize();
8787
size_t usable = available > reserving ? available - reserving : 0;
8888

8989
// If remaining size no less than expected size, using general

paddle/memory/memory.cc

+9-7
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,21 @@ BuddyAllocator* GetGPUBuddyAllocator(int gpu_id) {
6464
int gpu_num = platform::GetCUDADeviceCount();
6565
as = new BuddyAllocator*[gpu_num];
6666
for (int gpu = 0; gpu < gpu_num; gpu++) {
67-
platform::SetDeviceId(gpu);
68-
as[gpu] = new BuddyAllocator(new detail::GPUAllocator,
69-
platform::GpuMinChunkSize(),
70-
platform::GpuMaxChunkSize());
67+
as[gpu] = nullptr;
7168
}
69+
}
70+
platform::SetDeviceId(gpu_id);
71+
if (!as[gpu_id]) {
72+
as[gpu_id] = new BuddyAllocator(new detail::GPUAllocator,
73+
platform::GpuMinChunkSize(),
74+
platform::GpuMaxChunkSize());
7275
VLOG(10) << "\n\nNOTE: each GPU device use "
7376
<< FLAGS_fraction_of_gpu_memory_to_use * 100
7477
<< "% of GPU memory.\n"
75-
<< "You can set environment variable '"
76-
<< platform::kEnvFractionGpuMemoryToUse
78+
<< "You can set GFlags environment variable '"
79+
<< "FLAGS_fraction_of_gpu_memory_to_use"
7780
<< "' to change the fraction of GPU usage.\n\n";
7881
}
79-
platform::SetDeviceId(gpu_id);
8082
return as[gpu_id];
8183
}
8284

0 commit comments

Comments
 (0)