[OpenMP] Protect unrecogonized CUDA error code

If an error code can not be recognized by cuGetErrorString, errStr remains null and causes crashing at DP() printing.
Protect this case.

Reviewed By: jhuber6, tianshilei1992

Differential Revision: https://reviews.llvm.org/D87980
This commit is contained in:
Ye Luo 2020-09-21 13:42:54 -04:00 committed by Shilei Tian
parent 64e2cb7e96
commit 03111e5e7a
1 changed files with 11 additions and 3 deletions

View File

@ -30,9 +30,17 @@
#define CUDA_ERR_STRING(err) \
do { \
if (getDebugLevel() > 0) { \
const char *errStr; \
cuGetErrorString(err, &errStr); \
DP("CUDA error is: %s\n", errStr); \
const char *errStr = nullptr; \
CUresult errStr_status = cuGetErrorString(err, &errStr); \
if (errStr_status == CUDA_ERROR_INVALID_VALUE) \
DP("Unrecognized CUDA error code: %d\n", err); \
else if (errStr_status == CUDA_SUCCESS) \
DP("CUDA error is: %s\n", errStr); \
else { \
DP("Unresolved CUDA error code: %d\n", err); \
DP("Unsuccessful cuGetErrorString return status: %d\n", \
errStr_status); \
} \
} \
} while (false)
#else // OMPTARGET_DEBUG