diff options
author | Peter Hawkins <phawkins@google.com> | 2025-01-13 10:49:25 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-13 17:49:25 +0200 |
commit | e2c49a45da31522d91e2e7b12bbc0901b0519384 (patch) | |
tree | 1d449b19841f47560eb93e6b61ff585b69aac6e5 /mlir/lib/Bindings/Python/IRModule.h | |
parent | 3318a7248ae464af0abd0bea5515fa58c962b890 (diff) | |
download | llvm-e2c49a45da31522d91e2e7b12bbc0901b0519384.zip llvm-e2c49a45da31522d91e2e7b12bbc0901b0519384.tar.gz llvm-e2c49a45da31522d91e2e7b12bbc0901b0519384.tar.bz2 |
[mlir python] Add locking around PyMlirContext::liveOperations. (#122720)
In JAX, I observed a race between two PyOperation destructors from
different threads updating the same `liveOperations` map, despite not
intentionally sharing the context between different threads. Since I
don't think we can be completely sure when GC happens and on which
thread, it seems safest simply to add locking here.
We may also want to explicitly support sharing a context between threads
in the future, which would require this change or something similar.
Diffstat (limited to 'mlir/lib/Bindings/Python/IRModule.h')
-rw-r--r-- | mlir/lib/Bindings/Python/IRModule.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/mlir/lib/Bindings/Python/IRModule.h b/mlir/lib/Bindings/Python/IRModule.h index f5fbb6c..d1fb430 100644 --- a/mlir/lib/Bindings/Python/IRModule.h +++ b/mlir/lib/Bindings/Python/IRModule.h @@ -277,6 +277,9 @@ private: // attempt to access it will raise an error. using LiveOperationMap = llvm::DenseMap<void *, std::pair<nanobind::handle, PyOperation *>>; + nanobind::ft_mutex liveOperationsMutex; + + // Guarded by liveOperationsMutex in free-threading mode. LiveOperationMap liveOperations; bool emitErrorDiagnostics = false; |