Skip to content

Commit 5fedf30

Browse files
committed
[mlir] Make cuInit() call thread-safe.
Reviewed By: herhut Differential Revision: https://reviews.llvm.org/D98024
1 parent 05b3716 commit 5fedf30

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ OwnedBlob compilePtxToCubin(const std::string ptx, Location loc,
6565
StringRef name) {
6666
char jitErrorBuffer[4096] = {0};
6767

68-
RETURN_ON_CUDA_ERROR(cuInit(0));
68+
// Initialize CUDA once in a thread-safe manner.
69+
static CUresult cuInitResult = [] { return cuInit(/*flags=*/0); }();
70+
RETURN_ON_CUDA_ERROR(cuInitResult);
6971

7072
// Linking requires a device context.
7173
CUdevice device;

0 commit comments

Comments
 (0)