From 2514d70ea77bd770068adc12f99b7eb7f1fcdaf8 Mon Sep 17 00:00:00 2001 From: chengduoZH Date: Mon, 2 Apr 2018 23:19:00 +0800 Subject: [PATCH] follow comments --- paddle/fluid/memory/detail/system_allocator.cc | 10 +++++++++- paddle/fluid/memory/memory.cc | 9 ++++----- paddle/fluid/platform/cpu_info.cc | 9 +++++---- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/paddle/fluid/memory/detail/system_allocator.cc b/paddle/fluid/memory/detail/system_allocator.cc index 2463fdf483..bb6862990a 100644 --- a/paddle/fluid/memory/detail/system_allocator.cc +++ b/paddle/fluid/memory/detail/system_allocator.cc @@ -131,7 +131,12 @@ void* CUDAPinnedAllocator::Alloc(size_t& index, size_t size) { size_t usable = 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; // PINNED memory is visible to all CUDA contexts. @@ -141,6 +146,9 @@ void* CUDAPinnedAllocator::Alloc(size_t& index, size_t size) { index = 1; // PINNED memory cuda_pinnd_alloc_size_ += size; return p; + } else { + LOG(WARNING) << "cudaMallocHost failed."; + return nullptr; } return nullptr; diff --git a/paddle/fluid/memory/memory.cc b/paddle/fluid/memory/memory.cc index 7b459fe4d0..dc6c362728 100644 --- a/paddle/fluid/memory/memory.cc +++ b/paddle/fluid/memory/memory.cc @@ -133,11 +133,10 @@ void* Alloc(platform::CUDAPinnedPlace place, auto* buddy_allocator = GetCUDAPinnedBuddyAllocator(); void* ptr = buddy_allocator->Alloc(size); - // if (ptr == nullptr) { - // LOG(WARNING) << "Cannot allocate " << size << " bytes in CUDAPinnedPlace - // " - // << ", available " << avail << " bytes" - // } + if (ptr == nullptr) { + LOG(WARNING) << "cudaMallocHost Cannot allocate " << size + << " bytes in CUDAPinnedPlace"; + } return ptr; } diff --git a/paddle/fluid/platform/cpu_info.cc b/paddle/fluid/platform/cpu_info.cc index d44f1cadd2..4fc9aae8e3 100644 --- a/paddle/fluid/platform/cpu_info.cc +++ b/paddle/fluid/platform/cpu_info.cc @@ -27,9 +27,10 @@ DEFINE_double(fraction_of_cpu_memory_to_use, 1, "Default use 100% of CPU memory for PaddlePaddle," "reserve the rest for page tables, etc"); -DEFINE_double(fraction_of_cuda_pinned_memory_to_use, 0.5, - "Default use 100% of CPU memory for PaddlePaddle," - "reserve the rest for page tables, etc"); +DEFINE_double( + fraction_of_cuda_pinned_memory_to_use, 0.5, + "Default use 50% of CPU memory as the pinned_memory for PaddlePaddle," + "reserve the rest for page tables, etc"); namespace paddle { namespace platform { @@ -78,7 +79,7 @@ size_t CUDAPinnedMinChunkSize() { } 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. return CUDAPinnedMaxAllocSize() / 256; } -- GitLab