[Mlir-commits] [mlir] f87ceb6 - [AMDGPU] Adding mutex to guard lld::elf::link interface use

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Sep 21 11:45:58 PDT 2020


Author: jerryyin
Date: 2020-09-21T11:37:57-07:00
New Revision: f87ceb63eb011e5cd653218af619097b58bf568f

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

LOG: [AMDGPU] Adding mutex to guard lld::elf::link interface use

check-mlir target run tests simultaneously with multiple threads. This caused multiple threads to invoke the `lld::elf::link()` interface at the same time. Since the interface does not have a thread-safe implementation, add a metex to prevent multi-threaded access.

I discovered this by looking the the failure stack trace. lld/ELF/symbolTable.cpp, SymbolTable::insert() hit into an assert with related to Epoch Trackers. The root cause is to due to there is no protection around the symMap (update) which is implemented in non-thread safe data structure: denseMap.

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

Added: 
    

Modified: 
    mlir/tools/mlir-rocm-runner/mlir-rocm-runner.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/tools/mlir-rocm-runner/mlir-rocm-runner.cpp b/mlir/tools/mlir-rocm-runner/mlir-rocm-runner.cpp
index d0c515ba1f03..41d03b21c8f7 100644
--- a/mlir/tools/mlir-rocm-runner/mlir-rocm-runner.cpp
+++ b/mlir/tools/mlir-rocm-runner/mlir-rocm-runner.cpp
@@ -65,6 +65,8 @@
 // HIP headers.
 #include "hip/hip_version.h"
 
+#include <mutex>
+
 using namespace mlir;
 using namespace llvm;
 
@@ -146,6 +148,7 @@ static LogicalResult assembleIsa(const std::string isa, StringRef name,
   return success();
 }
 
+static std::mutex mutex;
 static LogicalResult createHsaco(const Blob &isaBlob, StringRef name,
                                  Blob &hsacoBlob) {
   // Save the ISA binary to a temp file.
@@ -175,6 +178,7 @@ static LogicalResult createHsaco(const Blob &isaBlob, StringRef name,
   }
   FileRemover cleanupHsaco(tempHsacoFilename);
 
+  const std::lock_guard<std::mutex> lock(mutex);
   // Invoke lld. Expect a true return value from lld.
   bool ret = lld::elf::link({"ld.lld", "-shared", tempIsaBinaryFilename.c_str(),
                              "-o", tempHsacoFilename.c_str()},


        


More information about the Mlir-commits mailing list