提交 2514d70e 编写于 作者: C chengduoZH

follow comments

上级 ffa63974
...@@ -131,7 +131,12 @@ void* CUDAPinnedAllocator::Alloc(size_t& index, size_t size) { ...@@ -131,7 +131,12 @@ void* CUDAPinnedAllocator::Alloc(size_t& index, size_t size) {
size_t usable = size_t usable =
paddle::platform::CUDAPinnedMaxAllocSize() - cuda_pinnd_alloc_size_; paddle::platform::CUDAPinnedMaxAllocSize() - cuda_pinnd_alloc_size_;
if (size > usable) return nullptr; if (size > usable) {
LOG(WARNING) << "Cannot malloc " << size / 1024.0 / 1024.0
<< " MB pinned memory."
<< ", available " << usable / 1024.0 / 1024.0 << " MB";
return nullptr;
}
void* p; void* p;
// PINNED memory is visible to all CUDA contexts. // PINNED memory is visible to all CUDA contexts.
...@@ -141,6 +146,9 @@ void* CUDAPinnedAllocator::Alloc(size_t& index, size_t size) { ...@@ -141,6 +146,9 @@ void* CUDAPinnedAllocator::Alloc(size_t& index, size_t size) {
index = 1; // PINNED memory index = 1; // PINNED memory
cuda_pinnd_alloc_size_ += size; cuda_pinnd_alloc_size_ += size;
return p; return p;
} else {
LOG(WARNING) << "cudaMallocHost failed.";
return nullptr;
} }
return nullptr; return nullptr;
......
...@@ -133,11 +133,10 @@ void* Alloc<platform::CUDAPinnedPlace>(platform::CUDAPinnedPlace place, ...@@ -133,11 +133,10 @@ void* Alloc<platform::CUDAPinnedPlace>(platform::CUDAPinnedPlace place,
auto* buddy_allocator = GetCUDAPinnedBuddyAllocator(); auto* buddy_allocator = GetCUDAPinnedBuddyAllocator();
void* ptr = buddy_allocator->Alloc(size); void* ptr = buddy_allocator->Alloc(size);
// if (ptr == nullptr) { if (ptr == nullptr) {
// LOG(WARNING) << "Cannot allocate " << size << " bytes in CUDAPinnedPlace LOG(WARNING) << "cudaMallocHost Cannot allocate " << size
// " << " bytes in CUDAPinnedPlace";
// << ", available " << avail << " bytes" }
// }
return ptr; return ptr;
} }
......
...@@ -27,9 +27,10 @@ DEFINE_double(fraction_of_cpu_memory_to_use, 1, ...@@ -27,9 +27,10 @@ DEFINE_double(fraction_of_cpu_memory_to_use, 1,
"Default use 100% of CPU memory for PaddlePaddle," "Default use 100% of CPU memory for PaddlePaddle,"
"reserve the rest for page tables, etc"); "reserve the rest for page tables, etc");
DEFINE_double(fraction_of_cuda_pinned_memory_to_use, 0.5, DEFINE_double(
"Default use 100% of CPU memory for PaddlePaddle," fraction_of_cuda_pinned_memory_to_use, 0.5,
"reserve the rest for page tables, etc"); "Default use 50% of CPU memory as the pinned_memory for PaddlePaddle,"
"reserve the rest for page tables, etc");
namespace paddle { namespace paddle {
namespace platform { namespace platform {
...@@ -78,7 +79,7 @@ size_t CUDAPinnedMinChunkSize() { ...@@ -78,7 +79,7 @@ size_t CUDAPinnedMinChunkSize() {
} }
size_t CUDAPinnedMaxChunkSize() { size_t CUDAPinnedMaxChunkSize() {
// Allow to allocate the maximum chunk size is roughly 0.39% of CUDA_PINNED // Allow to allocate the maximum chunk size is roughly 1/256 of CUDA_PINNED
// memory. // memory.
return CUDAPinnedMaxAllocSize() / 256; return CUDAPinnedMaxAllocSize() / 256;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册