diff options
author | Ashay Rane <ashay@users.noreply.github.com> | 2022-09-28 14:53:36 +0000 |
---|---|---|
committer | Ashay Rane <ashay@users.noreply.github.com> | 2022-09-29 03:02:24 +0000 |
commit | b947e15a577f72284d69d077cfdb2d3f211abe65 (patch) | |
tree | 5d7e6b62a55f6285d078f22299e1591dc88baf50 /mlir/python | |
parent | 9e6840ccbae5c8e34e6aaa417b8e6cf4a60facf3 (diff) | |
download | llvm-b947e15a577f72284d69d077cfdb2d3f211abe65.tar.gz |
[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
Diffstat (limited to 'mlir/python')
-rw-r--r-- | mlir/python/mlir/_mlir_libs/__init__.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/mlir/python/mlir/_mlir_libs/__init__.py b/mlir/python/mlir/_mlir_libs/__init__.py index add8d92eec5f..b140ad64e64c 100644 --- a/mlir/python/mlir/_mlir_libs/__init__.py +++ b/mlir/python/mlir/_mlir_libs/__init__.py @@ -62,6 +62,11 @@ def _site_initialize(): 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"): |