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) ...@@ -69,16 +69,11 @@ static const char *cufftGetErrorStrung(cufftResult error)
/* Handing CUDA Driver errors */ /* Handing CUDA Driver errors */
// Expand and stringify argument #define cuErrorCheck(call) \
#define STRINGx(x) #x
#define STRING(x) STRINGx(x)
#define CU_ERROR_CHECK(call) \
do { \ do { \
CUresult __error__; \ CUresult __error__; \
if ((__error__ = (call)) != CUDA_SUCCESS) { \ if ((__error__ = (call)) != CUDA_SUCCESS) { \
printf(STRING(call), __func__, __FILE__, __LINE__, __error__, \ printf("CUDA Driver Error %d / %s (%s %d)\n", __error__, cuGetError(__error__),__FILE__, __LINE__); \
(const char * (*)(int))cuGetError); \
return __error__; \ return __error__; \
} \ } \
} while (false) } while (false)
...@@ -412,13 +407,13 @@ int bioem_cuda::selectCudaDevice() ...@@ -412,13 +407,13 @@ int bioem_cuda::selectCudaDevice()
#else #else
unsigned int free, total; unsigned int free, total;
#endif #endif
CU_ERROR_CHECK(cuInit(0)); cuErrorCheck(cuInit(0));
CUdevice tmpDevice; CUdevice tmpDevice;
CU_ERROR_CHECK(cuDeviceGet(&tmpDevice, i)); cuErrorCheck(cuDeviceGet(&tmpDevice, i));
CUcontext tmpContext; CUcontext tmpContext;
CU_ERROR_CHECK(cuCtxCreate(&tmpContext, 0, tmpDevice)); cuErrorCheck(cuCtxCreate(&tmpContext, 0, tmpDevice));
if(cuMemGetInfo(&free, &total)) exit(1); if(cuMemGetInfo(&free, &total)) exit(1);
CU_ERROR_CHECK(cuCtxDestroy(tmpContext)); cuErrorCheck(cuCtxDestroy(tmpContext));
checkCudaErrors(cudaGetDeviceProperties(&deviceProp, i)); 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); 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