diff --git a/paddle/fluid/memory/allocation/cuda_allocator.cc b/paddle/fluid/memory/allocation/cuda_allocator.cc index af899230dee36334f3cb07e977bdc04c6e8bdfc3..6e0677dcb45dc3a9ff541d35f0d9d6e6b0794356 100644 --- a/paddle/fluid/memory/allocation/cuda_allocator.cc +++ b/paddle/fluid/memory/allocation/cuda_allocator.cc @@ -47,7 +47,7 @@ Allocation* CUDAAllocator::AllocateImpl(size_t size) { if (result != cudaSuccess) avail = 0; platform::RaiseNonOutOfMemoryError(&result); - PADDLE_THROW_BAD_ALLOC( + PADDLE_THROW_BAD_ALLOC(platform::errors::ResourceExhausted( "\n\nOut of memory error on GPU %d. " "Cannot allocate %s memory on GPU %d, " "available memory is only %s.\n\n" @@ -55,7 +55,7 @@ Allocation* CUDAAllocator::AllocateImpl(size_t size) { "1. If yes, please stop them, or start PaddlePaddle on another GPU.\n" "2. If no, please decrease the batch size of your model.\n", place_.device, string::HumanReadableSize(size), place_.device, - string::HumanReadableSize(avail), place_.device); + string::HumanReadableSize(avail), place_.device)); } } // namespace allocation diff --git a/paddle/fluid/memory/detail/system_allocator.cc b/paddle/fluid/memory/detail/system_allocator.cc index 76a121241e952d1c5c511bfbec17791fd605e23c..058485b8ddd1e934dcfc5133c9052f76346fb587 100644 --- a/paddle/fluid/memory/detail/system_allocator.cc +++ b/paddle/fluid/memory/detail/system_allocator.cc @@ -134,7 +134,7 @@ void* GPUAllocator::Alloc(size_t* index, size_t size) { if (result != cudaSuccess) avail = 0; platform::RaiseNonOutOfMemoryError(&result); - PADDLE_THROW_BAD_ALLOC( + PADDLE_THROW_BAD_ALLOC(platform::errors::ResourceExhausted( "\n\nOut of memory error on GPU %d. " "Cannot allocate %s memory on GPU %d, " "available memory is only %s.\n\n" @@ -148,7 +148,7 @@ void* GPUAllocator::Alloc(size_t* index, size_t size) { "`export FLAGS_fraction_of_gpu_memory_to_use=xxx`.\n\n", gpu_id_, string::HumanReadableSize(size), gpu_id_, string::HumanReadableSize(avail), gpu_id_, - FLAGS_fraction_of_gpu_memory_to_use); + FLAGS_fraction_of_gpu_memory_to_use)); } } diff --git a/paddle/fluid/platform/enforce.h b/paddle/fluid/platform/enforce.h index ac6e1e657bf8e81d5c7327336b9b7b18debe5b4c..6b737a6fced472ccbe0ae6bd747ef1ce05b5c484 100644 --- a/paddle/fluid/platform/enforce.h +++ b/paddle/fluid/platform/enforce.h @@ -360,10 +360,11 @@ struct EOFException : public std::exception { __LINE__); \ } while (0) -#define PADDLE_THROW_BAD_ALLOC(...) \ - do { \ - throw ::paddle::memory::allocation::BadAlloc( \ - ::paddle::string::Sprintf(__VA_ARGS__), __FILE__, __LINE__); \ +#define PADDLE_THROW_BAD_ALLOC(...) \ + do { \ + throw ::paddle::memory::allocation::BadAlloc( \ + ::paddle::platform::ErrorSummary(__VA_ARGS__).ToString(), __FILE__, \ + __LINE__); \ } while (0) /** CUDA PADDLE ENFORCE FUNCTIONS AND MACROS **/