[Openmp-commits] [PATCH] D87980: [OpenMP] Protect unrecogonized CUDA error code

Ye Luo via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Sat Sep 19 20:31:59 PDT 2020


ye-luo created this revision.
ye-luo added a reviewer: jhuber6.
Herald added subscribers: guansong, yaxunl.
ye-luo requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

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


https://reviews.llvm.org/D87980

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


Index: openmp/libomptarget/plugins/cuda/src/rtl.cpp
===================================================================
--- openmp/libomptarget/plugins/cuda/src/rtl.cpp
+++ openmp/libomptarget/plugins/cuda/src/rtl.cpp
@@ -31,8 +31,11 @@
   do {                                                                         \
     if (getDebugLevel() > 0) {                                                 \
       const char *errStr;                                                      \
-      cuGetErrorString(err, &errStr);                                          \
-      DP("CUDA error is: %s\n", errStr);                                       \
+      CUresult Err = cuGetErrorString(err, &errStr);                           \
+      if (Err != CUDA_SUCCESS)                                                 \
+        DP("unrecognized CUDA error code: %d\n", Err);                         \
+      else                                                                     \
+        DP("CUDA error is: %s\n", errStr);                                     \
     }                                                                          \
   } while (false)
 #else // OMPTARGET_DEBUG


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87980.293000.patch
Type: text/x-patch
Size: 1184 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20200920/e7daa935/attachment.bin>


More information about the Openmp-commits mailing list