提交 6e7209f0 编写于 作者: L liaogang

ENH: Add gpu info interface

上级 e6c14f7e
......@@ -42,8 +42,33 @@ size_t GpuMaxAllocSize() {
GpuMemoryUsage(available, total);
// Reserve the rest for page tables, etc.
return total * FLAGS_fraction_of_gpu_memory_to_use;
}
size_t GpuMinChunkSize() {
// Allow to allocate the minimum chunk size is 256 bytes.
return 1 << 8;
}
size_t GpuMaxChunkSize() {
// Allow to allocate the maximum chunk size is roughly 3% of CPU memory.
size_t total = 0;
size_t available = 0;
GpuMemoryUsage(available, total);
// Reserving the rest memory for page tables, etc.
size_t reserving = (1 - FLAGS_fraction_of_gpu_memory_to_use) * total;
// If available less than minimum chunk size, no usable memory exists.
available = std::max(available, GpuMinChunkSize()) - GpuMinChunkSize();
// If available less than reserving, no usable memory exists.
size_t usable = std::max(available, reserving) - reserving;
return usable;
}
} // namespace platform
} // namespace paddle
......@@ -30,6 +30,12 @@ void GpuMemoryUsage(size_t& available, size_t& total);
//! Get the maximum allocation size of current GPU device.
size_t GpuMaxAllocSize();
//! Get the minimum chunk size for GPU buddy allocator.
size_t GpuMinChunkSize();
//! Get the maximum chunk size for GPU buddy allocator.
size_t GpuMaxChunkSize();
} // namespace platform
} // namespace paddle
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册