未验证 提交 747d4498 编写于 作者: Z Zeng Jinle 提交者: GitHub

Refine err msg of out of gpu memory (#19779)

* refine err msg of out of gpu memory, test=develop

* refine err msg again, test=develop

* refine errog message again, test=develop

* follow reviewer's comments, test=develop
上级 fcf53e55
...@@ -23,6 +23,8 @@ limitations under the License. */ ...@@ -23,6 +23,8 @@ limitations under the License. */
#endif #endif
#include <stdlib.h> // for malloc and free #include <stdlib.h> // for malloc and free
#include <algorithm> // for std::max #include <algorithm> // for std::max
#include <string>
#include <utility>
#include "gflags/gflags.h" #include "gflags/gflags.h"
#include "paddle/fluid/memory/allocation/allocator.h" #include "paddle/fluid/memory/allocation/allocator.h"
...@@ -119,19 +121,25 @@ void* GPUAllocator::Alloc(size_t* index, size_t size) { ...@@ -119,19 +121,25 @@ void* GPUAllocator::Alloc(size_t* index, size_t size) {
return p; return p;
} else { } else {
PADDLE_ENFORCE_NE(cudaGetLastError(), cudaSuccess); PADDLE_ENFORCE_NE(cudaGetLastError(), cudaSuccess);
size_t avail, total;
platform::GpuMemoryUsage(&avail, &total);
PADDLE_THROW_BAD_ALLOC( PADDLE_THROW_BAD_ALLOC(
"Cannot malloc " + std::to_string(size / 1024.0 / 1024.0) + "\n\nOut of memory error on GPU %d. "
" MB GPU memory. Please shrink " "Cannot allocate %s memory on GPU %d, "
"FLAGS_fraction_of_gpu_memory_to_use or " "available memory is only %s.\n\n"
"FLAGS_initial_gpu_memory_in_mb or " "Please check whether there is any other process using GPU %d.\n"
"FLAGS_reallocate_gpu_memory_in_mb " "1. If yes, please stop them, or start PaddlePaddle on another GPU.\n"
"environment variable to a lower value. " + "2. If no, please try one of the following suggestions:\n"
"Current FLAGS_fraction_of_gpu_memory_to_use value is " + " 1) Decrease the batch size of your model.\n"
std::to_string(FLAGS_fraction_of_gpu_memory_to_use) + " 2) FLAGS_fraction_of_gpu_memory_to_use is %.2lf now, "
". Current FLAGS_initial_gpu_memory_in_mb value is " + "please set it to a higher value but less than 1.0.\n"
std::to_string(FLAGS_initial_gpu_memory_in_mb) + " The command is "
". Current FLAGS_reallocate_gpu_memory_in_mb value is " + "`export FLAGS_fraction_of_gpu_memory_to_use=xxx`.\n\n",
std::to_string(FLAGS_reallocate_gpu_memory_in_mb)); gpu_id_, string::HumanReadableSize(size), gpu_id_,
string::HumanReadableSize(avail), gpu_id_,
FLAGS_fraction_of_gpu_memory_to_use);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册