Skip to content

Commit

Permalink
prevents concurrent access into llvms jit
Browse files Browse the repository at this point in the history
Apparently the internals of the orc jit are not thread-safe:
https://lists.llvm.org/pipermail/llvm-dev/2017-November/119108.html

The thread sanitizer in nebulastream complaints about a data-race deep within orc. The mailing lists suggests using a lock around access into orc.
  • Loading branch information
ls-1801 authored and PhilippGrulich committed Dec 29, 2024
1 parent c8a0dd5 commit 2d5188d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
19 changes: 18 additions & 1 deletion nautilus/src/nautilus/compiler/backends/mlir/MLIRExecutable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,27 @@
#include <mlir/IR/MLIRContext.h>

namespace nautilus::compiler::mlir {
static std::mutex llvm_jit_mutex {};

MLIRExecutable::MLIRExecutable(std::unique_ptr<::mlir::ExecutionEngine> engine) : engine(std::move(engine)) {
}

MLIRExecutable::~MLIRExecutable() {
if (engine) {
std::scoped_lock lock(llvm_jit_mutex);
engine.reset();
}
}
MLIRExecutable::MLIRExecutable(MLIRExecutable&& other) noexcept
: engine(std::move(other.engine)) {
}
MLIRExecutable& MLIRExecutable::operator=(MLIRExecutable&& other) noexcept {
if (this == &other)
return *this;
engine = std::move(other.engine);
return *this;
}
void* MLIRExecutable::getInvocableFunctionPtr(const std::string& member) {
std::scoped_lock lock(llvm_jit_mutex);
return engine->lookup(member).get();
}
bool MLIRExecutable::hasInvocableFunctionPtr() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ namespace nautilus::compiler::mlir {
class MLIRExecutable : public Executable {
public:
MLIRExecutable(std::unique_ptr<::mlir::ExecutionEngine> engine);
~MLIRExecutable() override;
MLIRExecutable(const MLIRExecutable& other) = delete;
MLIRExecutable(MLIRExecutable&& other) noexcept;
MLIRExecutable& operator=(const MLIRExecutable& other) = delete;
MLIRExecutable& operator=(MLIRExecutable&& other) noexcept;

protected:
void* getInvocableFunctionPtr(const std::string& member) override;
Expand Down

0 comments on commit 2d5188d

Please sign in to comment.