diff --git a/mlir/tools/mlir-cuda-runner/mlir-cuda-runner.cpp b/mlir/tools/mlir-cuda-runner/mlir-cuda-runner.cpp --- a/mlir/tools/mlir-cuda-runner/mlir-cuda-runner.cpp +++ b/mlir/tools/mlir-cuda-runner/mlir-cuda-runner.cpp @@ -65,7 +65,9 @@ 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;