Skip to content

Commit 0ec4bd5

Browse files
committed
cudaCompressibleMemory: when unable to allocate compressible memory waive the execution
1 parent 908dddb commit 0ec4bd5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Samples/cudaCompressibleMemory/compMalloc.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include <stdio.h>
2929
#include <string.h>
30+
#include <helper_cuda.h>
3031
#include <cuda.h>
3132
#include <cuda_runtime_api.h>
3233

@@ -67,6 +68,16 @@ cudaError_t allocateCompressible(void **adr, size_t size, bool UseCompressibleMe
6768
if (cuMemCreate(&allocationHandle, size, &prop, 0) != CUDA_SUCCESS)
6869
return cudaErrorMemoryAllocation;
6970

71+
// Check if cuMemCreate was able to allocate compressible memory.
72+
if (UseCompressibleMemory) {
73+
CUmemAllocationProp allocationProp = {};
74+
cuMemGetAllocationPropertiesFromHandle(&allocationProp, allocationHandle);
75+
if (allocationProp.allocFlags.compressionType != CU_MEM_ALLOCATION_COMP_GENERIC) {
76+
printf("Could not allocate compressible memory... so waiving execution\n");
77+
exit(EXIT_WAIVED);
78+
}
79+
}
80+
7081
if (cuMemMap(dptr, size, 0, allocationHandle, 0) != CUDA_SUCCESS)
7182
return cudaErrorMemoryAllocation;
7283

0 commit comments

Comments
 (0)