[libomptarget][cuda] Gracefully handle missing cuda library
authorJon Chesterfield <jonathanchesterfield@gmail.com>
Tue, 26 Jan 2021 20:43:06 +0000 (20:43 +0000)
committerJon Chesterfield <jonathanchesterfield@gmail.com>
Tue, 26 Jan 2021 20:43:07 +0000 (20:43 +0000)
[libomptarget][cuda] Gracefully handle missing cuda library

If using dynamic cuda, and it failed to load, it is not safe to call
cuGetErrorString.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D95412

openmp/libomptarget/plugins/cuda/dynamic_cuda/cuda.cpp
openmp/libomptarget/plugins/cuda/dynamic_cuda/cuda.h
openmp/libomptarget/plugins/cuda/src/rtl.cpp

index cc7bc42..e3bd90e 100644 (file)
@@ -93,7 +93,7 @@ CUresult cuInit(unsigned X) {
   // Note: Called exactly once from cuda rtl.cpp in a global constructor so
   // does not need to handle being called repeatedly or concurrently
   if (!checkForCUDA()) {
-    return CUDA_ERROR_INVALID_VALUE;
+    return CUDA_ERROR_INVALID_HANDLE;
   }
   return dlwrap_cuInit(X);
 }
index 832c269..a65f2ac 100644 (file)
@@ -26,6 +26,7 @@ typedef struct CUstream_st *CUstream;
 typedef enum cudaError_enum {
   CUDA_SUCCESS = 0,
   CUDA_ERROR_INVALID_VALUE = 1,
+  CUDA_ERROR_INVALID_HANDLE = 400,
 } CUresult;
 
 typedef enum CUstream_flags_enum {
index e4ac1e0..732824a 100644 (file)
@@ -401,6 +401,11 @@ public:
     DP("Start initializing CUDA\n");
 
     CUresult Err = cuInit(0);
+    if (Err == CUDA_ERROR_INVALID_HANDLE) {
+      // Can't call cuGetErrorString if dlsym failed
+      DP("Failed to load CUDA shared library\n");
+      return;
+    }
     if (!checkResult(Err, "Error returned from cuInit\n")) {
       return;
     }