[Openmp-commits] [openmp] 03111e5 - [OpenMP] Protect unrecogonized CUDA error code

Shilei Tian via Openmp-commits openmp-commits at lists.llvm.org
Mon Sep 21 10:43:15 PDT 2020


Author: Ye Luo
Date: 2020-09-21T13:43:08-04:00
New Revision: 03111e5e7a8690300966a39f0aa2e4f2b4ec919a

URL: https://github.com/llvm/llvm-project/commit/03111e5e7a8690300966a39f0aa2e4f2b4ec919a
DIFF: https://github.com/llvm/llvm-project/commit/03111e5e7a8690300966a39f0aa2e4f2b4ec919a.diff

LOG: [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

Added: 
    

Modified: 
    openmp/libomptarget/plugins/cuda/src/rtl.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/plugins/cuda/src/rtl.cpp b/openmp/libomptarget/plugins/cuda/src/rtl.cpp
index 1a0bffb9557c..0422bfbfe319 100644
--- a/openmp/libomptarget/plugins/cuda/src/rtl.cpp
+++ b/openmp/libomptarget/plugins/cuda/src/rtl.cpp
@@ -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


        


More information about the Openmp-commits mailing list