Commit 8bd9be43 authored by Luka Stanisic's avatar Luka Stanisic

cleaner way to handle CUDA errors

parent c3c5062f
......@@ -69,16 +69,11 @@ static const char *cufftGetErrorStrung(cufftResult error)
/* Handing CUDA Driver errors */
// Expand and stringify argument
#define STRINGx(x) #x
#define STRING(x) STRINGx(x)
#define CU_ERROR_CHECK(call) \
#define cuErrorCheck(call) \
do { \
CUresult __error__; \
if ((__error__ = (call)) != CUDA_SUCCESS) { \
printf(STRING(call), __func__, __FILE__, __LINE__, __error__, \
(const char * (*)(int))cuGetError); \
printf("CUDA Driver Error %d / %s (%s %d)\n", __error__, cuGetError(__error__),__FILE__, __LINE__); \
return __error__; \
} \
} while (false)
......@@ -412,13 +407,13 @@ int bioem_cuda::selectCudaDevice()
#else
unsigned int free, total;
#endif
CU_ERROR_CHECK(cuInit(0));
cuErrorCheck(cuInit(0));
CUdevice tmpDevice;
CU_ERROR_CHECK(cuDeviceGet(&tmpDevice, i));
cuErrorCheck(cuDeviceGet(&tmpDevice, i));
CUcontext tmpContext;
CU_ERROR_CHECK(cuCtxCreate(&tmpContext, 0, tmpDevice));
cuErrorCheck(cuCtxCreate(&tmpContext, 0, tmpDevice));
if(cuMemGetInfo(&free, &total)) exit(1);
CU_ERROR_CHECK(cuCtxDestroy(tmpContext));
cuErrorCheck(cuCtxDestroy(tmpContext));
checkCudaErrors(cudaGetDeviceProperties(&deviceProp, i));
if (DebugOutput >= 2 && mpi_rank == 0) printf("CUDA Device %2d: %s (Rev: %d.%d - Mem Avail %lld / %lld)\n", i, deviceProp.name, deviceProp.major, deviceProp.minor, (long long int) free, (long long int) deviceProp.totalGlobalMem);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment