Skip to content

Commit c22876b

Browse files
author
Stephan Herhut
committed
[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
1 parent 84e4c09 commit c22876b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "llvm/IR/LegacyPassManager.h"
3232
#include "llvm/IR/Module.h"
3333
#include "llvm/Support/Error.h"
34+
#include "llvm/Support/Mutex.h"
3435
#include "llvm/Support/TargetRegistry.h"
3536
#include "llvm/Support/TargetSelect.h"
3637
#include "llvm/Target/TargetMachine.h"
@@ -57,6 +58,12 @@ class GpuKernelToCubinPass
5758
void runOnOperation() override {
5859
gpu::GPUModuleOp module = getOperation();
5960

61+
// Lock access to the llvm context.
62+
llvm::sys::SmartScopedLock<true> scopedLock(
63+
module.getContext()
64+
->getRegisteredDialect<LLVM::LLVMDialect>()
65+
->getLLVMContextMutex());
66+
6067
// Make sure the NVPTX target is initialized.
6168
LLVMInitializeNVPTXTarget();
6269
LLVMInitializeNVPTXTargetInfo();

0 commit comments

Comments
 (0)