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 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 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(); }