[PATCH] D78580: [MLIR] Add extra locking during cubin generation.

Stephan Herhut via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 21 12:59:38 PDT 2020


herhut created this revision.
Herald added subscribers: llvm-commits, frgossen, grosul1, Joonsoo, liufengdb, lucyrfox, mgester, arpith-jacob, csigg, nicolasvasilache, antiagainst, shauheen, jpienaar, rriddle, mehdi_amini.
Herald added a project: LLVM.
herhut added reviewers: rriddle, mehdi_amini, ftynse.
rriddle accepted this revision.
This revision is now accepted and ready to land.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78580

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


Index: mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp
===================================================================
--- mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp
+++ 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 @@
   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();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78580.259080.patch
Type: text/x-patch
Size: 980 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200421/00c779dc/attachment.bin>


More information about the llvm-commits mailing list