Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
[MEMORY] retry GPU memory allocation if fragmented (#16194)
Browse files Browse the repository at this point in the history
  • Loading branch information
szha authored and eric-haibin-lin committed Sep 18, 2019
1 parent 477e6f7 commit 479ab46
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/storage/pooled_storage_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,16 @@ void GPUPooledStorageManager::Alloc(Storage::Handle* handle) {

void* ret = nullptr;
cudaError_t e = cudaMalloc(&ret, size);
if (e != cudaSuccess && e != cudaErrorCudartUnloading) {
LOG(FATAL) << "cudaMalloc failed: " << cudaGetErrorString(e);
if (e != cudaSuccess) {
if (e == cudaErrorMemoryAllocation) {
ReleaseAll();
e = cudaMalloc(&ret, size);
if (e != cudaSuccess && e != cudaErrorCudartUnloading) {
LOG(FATAL) << "cudaMalloc retry failed: " << cudaGetErrorString(e);
}
} else if (e != cudaErrorCudartUnloading) {
LOG(FATAL) << "cudaMalloc failed: " << cudaGetErrorString(e);
}
}
used_memory_ += size;
handle->dptr = ret;
Expand Down Expand Up @@ -328,8 +336,16 @@ void GPUPooledRoundedStorageManager::Alloc(Storage::Handle* handle) {

void* ret = nullptr;
cudaError_t e = cudaMalloc(&ret, size);
if (e != cudaSuccess && e != cudaErrorCudartUnloading) {
LOG(FATAL) << "cudaMalloc failed: " << cudaGetErrorString(e);
if (e != cudaSuccess) {
if (e == cudaErrorMemoryAllocation) {
ReleaseAll();
e = cudaMalloc(&ret, size);
if (e != cudaSuccess && e != cudaErrorCudartUnloading) {
LOG(FATAL) << "cudaMalloc retry failed: " << cudaGetErrorString(e);
}
} else if (e != cudaErrorCudartUnloading) {
LOG(FATAL) << "cudaMalloc failed: " << cudaGetErrorString(e);
}
}
used_memory_ += size;
handle->dptr = ret;
Expand Down

0 comments on commit 479ab46

Please sign in to comment.