Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refine error msg when out of memory #32527

Merged
merged 1 commit into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions paddle/fluid/memory/allocation/cuda_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Allocation* CUDAAllocator::AllocateImpl(size_t size) {
size_t avail, total, actual_avail, actual_total;
bool is_limited = platform::RecordedCudaMemGetInfo(
&avail, &total, &actual_avail, &actual_total, place_.device);
size_t allocated = total - avail;

std::string err_msg;
if (is_limited) {
Expand All @@ -68,13 +69,14 @@ Allocation* CUDAAllocator::AllocateImpl(size_t size) {

PADDLE_THROW_BAD_ALLOC(platform::errors::ResourceExhausted(
"\n\nOut of memory error on GPU %d. "
"Cannot allocate %s memory on GPU %d, "
"Cannot allocate %s memory on GPU %d, %s memory has been allocated and "
"available memory is only %s.\n\n"
"Please check whether there is any other process using GPU %d.\n"
"1. If yes, please stop them, or start PaddlePaddle on another GPU.\n"
"2. If no, please decrease the batch size of your model. %s\n\n",
place_.device, string::HumanReadableSize(size), place_.device,
string::HumanReadableSize(avail), place_.device, err_msg));
string::HumanReadableSize(allocated), string::HumanReadableSize(avail),
place_.device, err_msg));
}

} // namespace allocation
Expand Down
7 changes: 4 additions & 3 deletions paddle/fluid/memory/detail/system_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ void* GPUAllocator::Alloc(size_t* index, size_t size) {
size_t avail, total, actual_avail, actual_total;
bool is_limited = platform::RecordedCudaMemGetInfo(
&avail, &total, &actual_avail, &actual_total, gpu_id_);
size_t allocated = total - avail;

std::string err_msg;
if (is_limited) {
Expand All @@ -139,7 +140,7 @@ void* GPUAllocator::Alloc(size_t* index, size_t size) {

PADDLE_THROW_BAD_ALLOC(platform::errors::ResourceExhausted(
"\n\nOut of memory error on GPU %d. "
"Cannot allocate %s memory on GPU %d, "
"Cannot allocate %s memory on GPU %d, %s memory has been allocated and "
"available memory is only %s.\n\n"
"Please check whether there is any other process using GPU %d.\n"
"1. If yes, please stop them, or start PaddlePaddle on another GPU.\n"
Expand All @@ -150,8 +151,8 @@ void* GPUAllocator::Alloc(size_t* index, size_t size) {
" The command is "
"`export FLAGS_fraction_of_gpu_memory_to_use=xxx`.%s\n\n",
gpu_id_, string::HumanReadableSize(size), gpu_id_,
string::HumanReadableSize(avail), gpu_id_,
FLAGS_fraction_of_gpu_memory_to_use, err_msg));
string::HumanReadableSize(allocated), string::HumanReadableSize(avail),
gpu_id_, FLAGS_fraction_of_gpu_memory_to_use, err_msg));
}
}

Expand Down