Skip to content

Commit

Permalink
Add a better error on memory allocation failure (#808)
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffburdick authored Nov 23, 2024
1 parent 3368402 commit 0e5c634
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions include/matx/core/allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,27 +177,26 @@ struct MemTracker {
switch (space) {
case MATX_MANAGED_MEMORY:
err = cudaMallocManaged(ptr, bytes);
MATX_ASSERT(err == cudaSuccess, matxOutOfMemory);
break;
case MATX_HOST_MEMORY:
err = cudaMallocHost(ptr, bytes);
MATX_ASSERT(err == cudaSuccess, matxOutOfMemory);
break;
case MATX_HOST_MALLOC_MEMORY:
*ptr = malloc(bytes);
break;
case MATX_DEVICE_MEMORY:
err = cudaMalloc(ptr, bytes);
MATX_ASSERT(err == cudaSuccess, matxOutOfMemory);
break;
case MATX_ASYNC_DEVICE_MEMORY:
err = cudaMallocAsync(ptr, bytes, stream);
MATX_ASSERT(err == cudaSuccess, matxOutOfMemory);
break;
case MATX_INVALID_MEMORY:
MATX_THROW(matxInvalidType, "Invalid memory kind when allocating!");
};

MATX_ASSERT_STR_EXP(err, cudaSuccess, matxOutOfMemory,
"Failed to allocate memory. May be an asynchronous error from another CUDA call");

if (*ptr == nullptr) {
MATX_THROW(matxOutOfMemory, "Failed to allocate memory");
}
Expand Down

0 comments on commit 0e5c634

Please sign in to comment.