[Mlir-commits] [mlir] 5fedf30 - [mlir] Make cuInit() call thread-safe.

Christian Sigg llvmlistbot at llvm.org
Fri Mar 5 07:06:25 PST 2021


Author: Christian Sigg
Date: 2021-03-05T16:06:15+01:00
New Revision: 5fedf30748381ad84697291591dab7d570f50d06

URL: https://github.com/llvm/llvm-project/commit/5fedf30748381ad84697291591dab7d570f50d06
DIFF: https://github.com/llvm/llvm-project/commit/5fedf30748381ad84697291591dab7d570f50d06.diff

LOG: [mlir] Make cuInit() call thread-safe.

Reviewed By: herhut

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

Added: 
    

Modified: 
    mlir/tools/mlir-cuda-runner/mlir-cuda-runner.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/tools/mlir-cuda-runner/mlir-cuda-runner.cpp b/mlir/tools/mlir-cuda-runner/mlir-cuda-runner.cpp
index fde875927f1f..22f15a67f481 100644
--- a/mlir/tools/mlir-cuda-runner/mlir-cuda-runner.cpp
+++ b/mlir/tools/mlir-cuda-runner/mlir-cuda-runner.cpp
@@ -65,7 +65,9 @@ OwnedBlob compilePtxToCubin(const std::string ptx, Location loc,
                             StringRef name) {
   char jitErrorBuffer[4096] = {0};
 
-  RETURN_ON_CUDA_ERROR(cuInit(0));
+  // Initialize CUDA once in a thread-safe manner.
+  static CUresult cuInitResult = [] { return cuInit(/*flags=*/0); }();
+  RETURN_ON_CUDA_ERROR(cuInitResult);
 
   // Linking requires a device context.
   CUdevice device;


        


More information about the Mlir-commits mailing list