|
|
|
@ -35,14 +35,27 @@ void CUDAAllocator::FreeImpl(Allocation* allocation) {
|
|
|
|
|
Allocation* CUDAAllocator::AllocateImpl(size_t size) {
|
|
|
|
|
platform::CUDADeviceGuard guard(place_.device);
|
|
|
|
|
void* ptr;
|
|
|
|
|
auto status = cudaMalloc(&ptr, size);
|
|
|
|
|
if (UNLIKELY(status != cudaSuccess)) {
|
|
|
|
|
PADDLE_ENFORCE_NE(cudaGetLastError(), cudaSuccess);
|
|
|
|
|
PADDLE_THROW_BAD_ALLOC("Cannot allocate %d on GPU %d, cuda status %d, %s",
|
|
|
|
|
size, place_.device, status,
|
|
|
|
|
cudaGetErrorString(status));
|
|
|
|
|
auto result = cudaMalloc(&ptr, size);
|
|
|
|
|
if (LIKELY(result == cudaSuccess)) {
|
|
|
|
|
return new Allocation(ptr, size, platform::Place(place_));
|
|
|
|
|
}
|
|
|
|
|
return new Allocation(ptr, size, platform::Place(place_));
|
|
|
|
|
|
|
|
|
|
platform::RaiseNonOutOfMemoryError(&result);
|
|
|
|
|
|
|
|
|
|
size_t avail = 0, total = 0;
|
|
|
|
|
result = cudaMemGetInfo(&avail, &total);
|
|
|
|
|
if (result != cudaSuccess) avail = 0;
|
|
|
|
|
platform::RaiseNonOutOfMemoryError(&result);
|
|
|
|
|
|
|
|
|
|
PADDLE_THROW_BAD_ALLOC(
|
|
|
|
|
"\n\nOut of memory error on GPU %d. "
|
|
|
|
|
"Cannot allocate %s memory on GPU %d, "
|
|
|
|
|
"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.\n",
|
|
|
|
|
place_.device, string::HumanReadableSize(size), place_.device,
|
|
|
|
|
string::HumanReadableSize(avail), place_.device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace allocation
|
|
|
|
|