[Mlir-commits] [mlir] c22876b - [MLIR] Add extra locking during cubin generation.

Stephan Herhut llvmlistbot at llvm.org
Tue Apr 21 23:58:45 PDT 2020


Author: Stephan Herhut
Date: 2020-04-22T08:57:45+02:00
New Revision: c22876b550f5905b1cb7a4a0f329e76fac3e0232

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

LOG: [MLIR] Add extra locking during cubin generation.

We also need to lock the LLVMDialect mutex when initializing
LLVM targets or destroying llvm modules concurrently. Added another
scoped lock to that effect.

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

Added: 
    

Modified: 
    mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp b/mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp
index 7cdb0dda4454..3f99c56c4716 100644
--- a/mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp
+++ b/mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp
@@ -31,6 +31,7 @@
 #include "llvm/IR/LegacyPassManager.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/Mutex.h"
 #include "llvm/Support/TargetRegistry.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Target/TargetMachine.h"
@@ -57,6 +58,12 @@ class GpuKernelToCubinPass
   void runOnOperation() override {
     gpu::GPUModuleOp module = getOperation();
 
+    // Lock access to the llvm context.
+    llvm::sys::SmartScopedLock<true> scopedLock(
+        module.getContext()
+            ->getRegisteredDialect<LLVM::LLVMDialect>()
+            ->getLLVMContextMutex());
+
     // Make sure the NVPTX target is initialized.
     LLVMInitializeNVPTXTarget();
     LLVMInitializeNVPTXTargetInfo();


        


More information about the Mlir-commits mailing list