[Mlir-commits] [mlir] b947e15 - [mlir][python] stop initialization on ImportError

Ashay Rane llvmlistbot at llvm.org
Wed Sep 28 20:02:34 PDT 2022


Author: Ashay Rane
Date: 2022-09-29T03:02:24Z
New Revision: b947e15a577f72284d69d077cfdb2d3f211abe65

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

LOG: [mlir][python] stop initialization on ImportError

An `_mlirRegisterEverything.*.so` file from an old build that referenced
`MLIRPythonExtension.RegisterEverything`, but which no longer references
that extension in a new build, causes runtime errors in the new build
like:

    ImportError: _mlirRegisterEverything.cpython-38-x86_64-linux-gnu.so: undefined symbol: mlirRegisterAllPasses

The error occurs because the MLIR Python binding tries to dynamically
import the `_mlirRegisterEverything` module but the dynamic importer
fails since the new build no longer references
`MLIRPythonExtension.RegisterEverything`.

One possible solution is for the user to manually remove the
`_mlirRegisterEverything.*.so` file.  This patch instead resolves the
problem in code by printing a waning if the module cannot be
imported.

Reviewed By: stellaraccident

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

Added: 
    

Modified: 
    mlir/python/mlir/_mlir_libs/__init__.py

Removed: 
    


################################################################################
diff  --git a/mlir/python/mlir/_mlir_libs/__init__.py b/mlir/python/mlir/_mlir_libs/__init__.py
index add8d92eec5fb..b140ad64e64cd 100644
--- a/mlir/python/mlir/_mlir_libs/__init__.py
+++ b/mlir/python/mlir/_mlir_libs/__init__.py
@@ -62,6 +62,11 @@ def process_initializer_module(module_name):
       m = importlib.import_module(f".{module_name}", __name__)
     except ModuleNotFoundError:
       return False
+    except ImportError:
+      message = (f"Error importing mlir initializer {module_name}. This may "
+      "happen in unclean incremental builds but is likely a real bug if "
+      "encountered otherwise and the MLIR Python API may not function.")
+      logging.warning(message, exc_info=True)
 
     logging.debug("Initializing MLIR with module: %s", module_name)
     if hasattr(m, "register_dialects"):


        


More information about the Mlir-commits mailing list