[Mlir-commits] [mlir] a5a24c9 - Remove misused RAII gil_scoped_release/gil_scoped_acquire: without name they don't have any effect
Mehdi Amini
llvmlistbot at llvm.org
Sun Jan 2 22:19:46 PST 2022
Author: Mehdi Amini
Date: 2022-01-03T06:17:04Z
New Revision: a5a24c93706d5cf67ccaaaeb1b7ac13a801275b4
URL: https://github.com/llvm/llvm-project/commit/a5a24c93706d5cf67ccaaaeb1b7ac13a801275b4
DIFF: https://github.com/llvm/llvm-project/commit/a5a24c93706d5cf67ccaaaeb1b7ac13a801275b4.diff
LOG: Remove misused RAII gil_scoped_release/gil_scoped_acquire: without name they don't have any effect
I'm not sure what is the right fix here, but adding a name to all these
lead to many segfaults.
Reviewed By: stellaraccident
Differential Revision: https://reviews.llvm.org/D116506
Added:
Modified:
mlir/lib/Bindings/Python/IRCore.cpp
mlir/lib/Bindings/Python/IRModule.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Bindings/Python/IRCore.cpp b/mlir/lib/Bindings/Python/IRCore.cpp
index 686153227203..b39a1ea844e4 100644
--- a/mlir/lib/Bindings/Python/IRCore.cpp
+++ b/mlir/lib/Bindings/Python/IRCore.cpp
@@ -868,7 +868,6 @@ void PyOperationBase::print(py::object fileObject, bool binary,
mlirOpPrintingFlagsPrintGenericOpForm(flags);
PyFileAccumulator accum(fileObject, binary);
- py::gil_scoped_release();
mlirOperationPrintWithFlags(operation, flags, accum.getCallback(),
accum.getUserData());
mlirOpPrintingFlagsDestroy(flags);
diff --git a/mlir/lib/Bindings/Python/IRModule.cpp b/mlir/lib/Bindings/Python/IRModule.cpp
index 633ffe4e111b..ba6b2d29f74b 100644
--- a/mlir/lib/Bindings/Python/IRModule.cpp
+++ b/mlir/lib/Bindings/Python/IRModule.cpp
@@ -35,7 +35,6 @@ PyGlobals::PyGlobals() {
PyGlobals::~PyGlobals() { instance = nullptr; }
void PyGlobals::loadDialectModule(llvm::StringRef dialectNamespace) {
- py::gil_scoped_acquire();
if (loadedDialectModulesCache.contains(dialectNamespace))
return;
// Since re-entrancy is possible, make a copy of the search prefixes.
@@ -46,7 +45,6 @@ void PyGlobals::loadDialectModule(llvm::StringRef dialectNamespace) {
moduleName.append(dialectNamespace.data(), dialectNamespace.size());
try {
- py::gil_scoped_release();
loaded = py::module::import(moduleName.c_str());
} catch (py::error_already_set &e) {
if (e.matches(PyExc_ModuleNotFoundError)) {
@@ -64,7 +62,6 @@ void PyGlobals::loadDialectModule(llvm::StringRef dialectNamespace) {
void PyGlobals::registerDialectImpl(const std::string &dialectNamespace,
py::object pyClass) {
- py::gil_scoped_acquire();
py::object &found = dialectClassMap[dialectNamespace];
if (found) {
throw SetPyError(PyExc_RuntimeError, llvm::Twine("Dialect namespace '") +
@@ -77,7 +74,6 @@ void PyGlobals::registerDialectImpl(const std::string &dialectNamespace,
void PyGlobals::registerOperationImpl(const std::string &operationName,
py::object pyClass,
py::object rawOpViewClass) {
- py::gil_scoped_acquire();
py::object &found = operationClassMap[operationName];
if (found) {
throw SetPyError(PyExc_RuntimeError, llvm::Twine("Operation '") +
@@ -90,7 +86,6 @@ void PyGlobals::registerOperationImpl(const std::string &operationName,
llvm::Optional<py::object>
PyGlobals::lookupDialectClass(const std::string &dialectNamespace) {
- py::gil_scoped_acquire();
loadDialectModule(dialectNamespace);
// Fast match against the class map first (common case).
const auto foundIt = dialectClassMap.find(dialectNamespace);
@@ -109,7 +104,6 @@ PyGlobals::lookupDialectClass(const std::string &dialectNamespace) {
llvm::Optional<pybind11::object>
PyGlobals::lookupRawOpViewClass(llvm::StringRef operationName) {
{
- py::gil_scoped_acquire();
auto foundIt = rawOpViewClassMapCache.find(operationName);
if (foundIt != rawOpViewClassMapCache.end()) {
if (foundIt->second.is_none())
@@ -126,7 +120,6 @@ PyGlobals::lookupRawOpViewClass(llvm::StringRef operationName) {
// Attempt to find from the canonical map and cache.
{
- py::gil_scoped_acquire();
auto foundIt = rawOpViewClassMap.find(operationName);
if (foundIt != rawOpViewClassMap.end()) {
if (foundIt->second.is_none())
@@ -143,7 +136,6 @@ PyGlobals::lookupRawOpViewClass(llvm::StringRef operationName) {
}
void PyGlobals::clearImportCache() {
- py::gil_scoped_acquire();
loadedDialectModulesCache.clear();
rawOpViewClassMapCache.clear();
}
More information about the Mlir-commits
mailing list