[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
This commit is contained in:
Stephan Herhut 2020-04-21 21:21:37 +02:00
parent 84e4c09995
commit c22876b550
1 changed files with 7 additions and 0 deletions

View File

@ -31,6 +31,7 @@
#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h" #include "llvm/IR/Module.h"
#include "llvm/Support/Error.h" #include "llvm/Support/Error.h"
#include "llvm/Support/Mutex.h"
#include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h" #include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
@ -57,6 +58,12 @@ public:
void runOnOperation() override { void runOnOperation() override {
gpu::GPUModuleOp module = getOperation(); 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. // Make sure the NVPTX target is initialized.
LLVMInitializeNVPTXTarget(); LLVMInitializeNVPTXTarget();
LLVMInitializeNVPTXTargetInfo(); LLVMInitializeNVPTXTargetInfo();