This is an archive of the discontinued LLVM Phabricator instance.

[mlir][python] Simplify python extension loading.
ClosedPublic

Authored by stellaraccident on Aug 20 2021, 2:52 PM.

Details

Summary
  • Now that packaging has stabilized, removes old mechanisms for loading extensions, preferring direct importing.
  • Removes _cext_loader.py, _dlloader.py as unnecessary.
  • Fixes the path where the CAPI dll is written on Windows. This enables that path of least resistance loading behavior to work with no further drama (see: https://bugs.python.org/issue36085).
  • With this patch, ninja check-mlir on Windows with Python bindings works for me, modulo some failures that are actually due to a couple of pre-existing Windows bugs. I think this is the first time the Windows Python bindings have worked upstream.
  • Downstream changes needed:
    • If downstreams are using the now removed load_extension, reexport_cext, etc, then those should be replaced with normal import statements as done in this patch.

Diff Detail

Event Timeline

stellaraccident requested review of this revision.Aug 20 2021, 2:52 PM

Try to fix arc diff issue?

Fix windows line endings.

stellaraccident edited reviewers, added: jdd, mikeurbach, ftynse; removed: aartbik.Aug 20 2021, 3:01 PM
jdd accepted this revision.Aug 20 2021, 7:32 PM

I'm probably not the best person to review this (since I'm not aware of the full history), but everything here looks reasonable to me and significantly less hacky to boot! Thanks

This revision is now accepted and ready to land.Aug 20 2021, 7:32 PM

I'm probably not the best person to review this (since I'm not aware of the full history), but everything here looks reasonable to me and significantly less hacky to boot! Thanks

Thanks - I'll wait for ftynse to have a look. He's got the history and visibility into some of the weirder things we've done with this code out of tree. The tl;dr on the history is that we used to have deps that spanned the python package and the main LLVM build/install tree, and there were a few different ways this was packaged in downstreams. Now everything has converged on hermetic with a namespaced, relative package layout, so all that extra gunk can go away. Probably makes tools (pytype, et al) happier too.

Remove last two sys.modules stuffing aliases (should make type checkers happier).

aartbik accepted this revision.Aug 23 2021, 11:17 AM

Looks good for the parts I worked on (all passes registration and sparse tensor dialect stuff)

Further simplify _mlir_libs.init by using the new MAKE_MLIR_PYTHON_QUALNAME in native code to properly initialize the search path internally.

stellaraccident edited the summary of this revision. (Show Details)Aug 23 2021, 7:52 PM
stellaraccident edited the summary of this revision. (Show Details)

Rebase.

This revision was automatically updated to reflect the committed changes.
mlir/python/CMakeLists.txt