[mlir] Overhaul C/Python registration APIs to properly scope registration/loading activities.Since the very first commits, the Python and C MLIR APIs have had mis-placed registration/load functiona
[mlir] Overhaul C/Python registration APIs to properly scope registration/loading activities.Since the very first commits, the Python and C MLIR APIs have had mis-placed registration/load functionality for dialects, extensions, etc. This was done pragmatically in order to get bootstrapped and then just grew in. Downstreams largely bypass and do their own thing by providing various APIs to register things they need. Meanwhile, the C++ APIs have stabilized around this and it would make sense to follow suit.The thing we have observed in canonical usage by downstreams is that each downstream tends to have native entry points that configure its installation to its preferences with one-stop APIs. This patch leans in to this approach with `RegisterEverything.h` and `mlir._mlir_libs._mlirRegisterEverything` being the one-stop entry points for the "upstream packages". The `_mlir_libs.__init__.py` now allows customization of the environment and Context by adding "initialization modules" to the `_mlir_libs` package. If present, `_mlirRegisterEverything` is treated as such a module. Others can be added by downstreams by adding a `_site_initialize_{i}.py` module, where '{i}' is a number starting with zero. The number will be incremented and corresponding module loaded until one is not found. Initialization modules can:* Perform load time customization to the global environment (i.e. registering passes, hooks, etc).* Define a `register_dialects(registry: DialectRegistry)` function that can extend the `DialectRegistry` that will be used to bootstrap the `Context`.* Define a `context_init_hook(context: Context)` function that will be added to a list of callbacks which will be invoked after dialect registration during `Context` initialization.Note that the `MLIRPythonExtension.RegisterEverything` is not included by default when building a downstream (its corresponding behavior was prior). For downstreams which need the default MLIR initialization to take place, they must add this back in to their Python CMake build just like they add their own components (i.e. to `add_mlir_python_common_capi_library` and `add_mlir_python_modules`). It is perfectly valid to not do this, in which case, only the things explicitly depended on and initialized by downstreams will be built/packaged. If the downstream has not been set up for this, it is recommended to simply add this back for the time being and pay the build time/package size cost.CMake changes:* `MLIRCAPIRegistration` -> `MLIRCAPIRegisterEverything` (renamed to signify what it does and force an evaluation: a number of places were incidentally linking this very expensive target)* `MLIRPythonSoure.Passes` removed (without replacement: just drop)* `MLIRPythonExtension.AllPassesRegistration` removed (without replacement: just drop)* `MLIRPythonExtension.Conversions` removed (without replacement: just drop)* `MLIRPythonExtension.Transforms` removed (without replacement: just drop)Header changes:* `mlir-c/Registration.h` is deleted. Dialect registration functionality is now in `IR.h`. Registration of upstream features are in `mlir-c/RegisterEverything.h`. When updating MLIR and a couple of downstreams, I found that proper usage was commingled so required making a choice vs just blind S&R.Python APIs removed: * mlir.transforms and mlir.conversions (previously only had an __init__.py which indirectly triggered `mlirRegisterTransformsPasses()` and `mlirRegisterConversionPasses()` respectively). Downstream impact: Remove these imports if present (they now happen as part of default initialization). * mlir._mlir_libs._all_passes_registration, mlir._mlir_libs._mlirTransforms, mlir._mlir_libs._mlirConversions. Downstream impact: None expected (these were internally used).C-APIs changed: * mlirRegisterAllDialects(MlirContext) now takes an MlirDialectRegistry instead. It also used to trigger loading of all dialects, which was already marked with a TODO to remove -- it no longer does, and for direct use, dialects must be explicitly loaded. Downstream impact: Direct C-API users must ensure that needed dialects are loaded or call `mlirContextLoadAllAvailableDialects(MlirContext)` to emulate the prior behavior. Also see the `ir.c` test case (e.g. ` mlirContextGetOrLoadDialect(ctx, mlirStringRefCreateFromCString("func"));`). * mlirDialectHandle* APIs were moved from Registration.h (which now is restricted to just global/upstream registration) to IR.h, arguably where it should have been. Downstream impact: include correct header (likely already doing so).C-APIs added: * mlirContextLoadAllAvailableDialects(MlirContext): Corresponds to C++ API with the same purpose.Python APIs added: * mlir.ir.DialectRegistry: Mapping for an MlirDialectRegistry. * mlir.ir.Context.append_dialect_registry(MlirDialectRegistry) * mlir.ir.Context.load_all_available_dialects() * mlir._mlir_libs._mlirAllRegistration: New native extension that exposes a `register_dialects(MlirDialectRegistry)` entry point and performs all upstream pass/conversion/transforms registration on init. In this first step, we eagerly load this as part of the __init__.py and use it to monkey patch the Context to emulate prior behavior. * Type caster and capsule support for MlirDialectRegistryThis should make it possible to build downstream Python dialects that only depend on a subset of MLIR. See: https://github.com/llvm/llvm-project/issues/56037Here is an example PR, minimally adapting IREE to these changes: https://github.com/iree-org/iree/pull/9638/files In this situation, IREE is opting to not link everything, since it is already configuring the Context to its liking. For projects that would just like to not think about it and pull in everything, add `MLIRPythonExtension.RegisterEverything` to the list of Python sources getting built, and the old behavior will continue.Reviewed By: mehdi_amini, ftynseDifferential Revision: https://reviews.llvm.org/D128593
show more ...
[mlir][gpu] Move GPU headers into IR/ and Transforms/Depends on D127350Reviewed By: rriddleDifferential Revision: https://reviews.llvm.org/D127352
[mlir] Add C API for ControlFlow dialectAdd basic C API for the ControlFlow dialect. Follows the format of the other dialects.Reviewed By: mehdi_aminiDifferential Revision: https://reviews.llvm
[mlir] Add C API for ControlFlow dialectAdd basic C API for the ControlFlow dialect. Follows the format of the other dialects.Reviewed By: mehdi_aminiDifferential Revision: https://reviews.llvm.org/D121867
[mlir] Rename the Standard dialect to the Func dialectThe last remaining operations in the standard dialect all revolve aroundFuncOp/function related constructs. This patch simply handles the init
[mlir] Rename the Standard dialect to the Func dialectThe last remaining operations in the standard dialect all revolve aroundFuncOp/function related constructs. This patch simply handles the initialrenaming (which by itself is already huge), but there are a large numberof cleanups unlocked/necessary afterwards:* Removing a bunch of unnecessary dependencies on Func* Cleaning up the From/ToStandard conversion passes* Preparing for the move of FuncOp to the Func dialectSee the discussion at https://discourse.llvm.org/t/standard-dialect-the-final-chapter/6061Differential Revision: https://reviews.llvm.org/D120624
[MLIR][PDL] Fix typo (NFC)
[mlir] Introduce Python bindings for the PDL dialectThis change adds full python bindings for PDL, including types and operationswith additional mixins to make operation construction more similar
[mlir] Introduce Python bindings for the PDL dialectThis change adds full python bindings for PDL, including types and operationswith additional mixins to make operation construction more similar to the PDLsyntax.Reviewed By: ftynseDifferential Revision: https://reviews.llvm.org/D117458
Apply clang-tidy fixes for llvm-header-guard in MLIR (NFC)Differential Revision: https://reviews.llvm.org/D117251
[mlir] Introduce C API for PDL dialect typesThis change introduces C API helper functions to work with PDL types.Modification closely follow the format of the https://reviews.llvm.org/D116546.Re
[mlir] Introduce C API for PDL dialect typesThis change introduces C API helper functions to work with PDL types.Modification closely follow the format of the https://reviews.llvm.org/D116546.Reviewed By: ftynseDifferential Revision: https://reviews.llvm.org/D117221
[mlir] Introduce C API for the Quantization dialect typesReviewed By: nicolasvasilacheDifferential Revision: https://reviews.llvm.org/D116546
[mlir] Use public PybindAdaptors in Linalg dialect bindingsPreviously, the Python bindings for the Linalg dialect relied on the internalimplementation of core bindings. Most of that functionality
[mlir] Use public PybindAdaptors in Linalg dialect bindingsPreviously, the Python bindings for the Linalg dialect relied on the internalimplementation of core bindings. Most of that functionality was moved, and theremaining one does not need access to the implementation: it used to accept adialect pointer as argument, but it can always be extracted from the operationthat it also accepts; operations are available through PybindAdaptors in anopaque way. Change the bindings in that direction.This enables the decoupling of the Linalg dialect Python extension from thecore IR Python extension.Reviewed By: nicolasvasilacheDifferential Revision: https://reviews.llvm.org/D116649
Add more types to the LLVM dialect C APIThis includes:- void type- array types- function types- literal (unnamed) struct typesReviewed By: jpienaar, ftynseDifferential Revision: https://rev
Add more types to the LLVM dialect C APIThis includes:- void type- array types- function types- literal (unnamed) struct typesReviewed By: jpienaar, ftynseDifferential Revision: https://reviews.llvm.org/D105908
Add C API files for the LLVM dialectFor now only expose a builder for the LLVM pointer type.Reviewed By: jpienaar, ftynseDifferential Revision: https://reviews.llvm.org/D105346
[mlir][linalg] Remove the StructuredOp capture mechanism.After https://reviews.llvm.org/D104109, structured ops support scalar inputs. As a result, the capture mechanism meant to pass non-shaped pa
[mlir][linalg] Remove the StructuredOp capture mechanism.After https://reviews.llvm.org/D104109, structured ops support scalar inputs. As a result, the capture mechanism meant to pass non-shaped parameters got redundant. The patch removes the capture semantics after the FillOp migrated to use scalar operands https://reviews.llvm.org/D104121.Differential Revision: https://reviews.llvm.org/D104785
[mlir][sparse][capi][python] add sparse tensor passesFirst set of "boilerplate" to get sparse tensorpasses available through CAPI and Python.Reviewed By: stellaraccidentDifferential Revision:
[mlir][sparse][capi][python] add sparse tensor passesFirst set of "boilerplate" to get sparse tensorpasses available through CAPI and Python.Reviewed By: stellaraccidentDifferential Revision: https://reviews.llvm.org/D102362
[mlir][CAPI] Add CAPI bindings for the sparse_tensor dialect.* Adds dialect registration, hand coded 'encoding' attribute and test.* An MLIR CAPI tablegen backend for attributes does not exist, an
[mlir][CAPI] Add CAPI bindings for the sparse_tensor dialect.* Adds dialect registration, hand coded 'encoding' attribute and test.* An MLIR CAPI tablegen backend for attributes does not exist, and this is a relatively complicated case. I opted to hand code it in a canonical way for now, which will provide a reasonable blueprint for building out the tablegen version in the future.* Also added a (local) CMake function for declaring new CAPI tests, since it was getting repetitive/buggy.Differential Revision: https://reviews.llvm.org/D102141
[mlir][python] Add basic python support for GPU dialect and passesDifferential Revision: https://reviews.llvm.org/D101449
[mlir][python] Add python support for async dialect and passes.since the `async` keyword is reserved in python, the dialect is called async_dialect.Differential Revision: https://reviews.llvm.org
[mlir][python] Add python support for async dialect and passes.since the `async` keyword is reserved in python, the dialect is called async_dialect.Differential Revision: https://reviews.llvm.org/D101447
[mlir][Python][Linalg] Add support for captures in body builder.When Linalg named ops support was added, captures were omittedfrom the body builder. This revision adds support for captureswhich a
[mlir][Python][Linalg] Add support for captures in body builder.When Linalg named ops support was added, captures were omittedfrom the body builder. This revision adds support for captureswhich allows us to write FillOp in a more idiomatic fashion usingthe _linalg_ops_ext mixin support.This raises an issue in the generation of `_linalg_ops_gen.py` where``` @property def result(self): return self.operation.results[0] if len(self.operation.results) > 1 else None```.The condition should be `== 1`.This will be fixed in a separate commit.Differential Revision: https://reviews.llvm.org/D100363
[mlir][Linalg][Python] Create the body of builtin named Linalg opsThis revision adds support to properly add the body of registeredbuiltin named linalg ops.At this time, indexing_map and iterator
[mlir][Linalg][Python] Create the body of builtin named Linalg opsThis revision adds support to properly add the body of registeredbuiltin named linalg ops.At this time, indexing_map and iterator_type support is stillmissing so the op is not executable yet.Differential Revision: https://reviews.llvm.org/D99578
[mlir] Register Linalg passes in C API and Python BindingsProvide a registration mechanism for Linalg dialect-specific passes in CAPI and Python bindings. These are being built into the dialect li
[mlir] Register Linalg passes in C API and Python BindingsProvide a registration mechanism for Linalg dialect-specific passes in CAPI and Python bindings. These are being built into the dialect librarybut exposed in separate headers (C) or modules (Python).Differential Revision: https://reviews.llvm.org/D99431
[mlir][CAPI] Introduce standard source layout for mlir-c dialect registration.* Registers a small set of sample dialects.* NFC with respect to existing C-API symbols but some headers have been mov
[mlir][CAPI] Introduce standard source layout for mlir-c dialect registration.* Registers a small set of sample dialects.* NFC with respect to existing C-API symbols but some headers have been moved down a level to the Dialect/ sub-directory.* Adds an additional entry point per dialect that is needed for dynamic discovery/loading.* See discussion: https://llvm.discourse.group/t/dialects-and-the-c-api/2306/16Differential Revision: https://reviews.llvm.org/D94370