summaryrefslogtreecommitdiff
path: root/mlir/test/CAPI/execution_engine.c
AgeCommit message (Collapse)Author
2025-08-13Revert "[MLIR] Split ExecutionEngine Initialization out of ctor into an ↵Mehdi Amini
explicit method call" (#153477) Reverts llvm/llvm-project#153373 Sanitizer bot is broken
2025-08-13[MLIR] Split ExecutionEngine Initialization out of ctor into an explicit ↵Shenghang Tsai
method call (#153373) This PR introduces a mechanism to defer JIT engine initialization, enabling registration of required symbols before global constructor execution. ## Problem Modules containing `gpu.module` generate global constructors (e.g., kernel load/unload) that execute *during* engine creation. This can force premature symbol resolution, causing failures when: - Symbols are registered via `mlirExecutionEngineRegisterSymbol` *after* creation - Global constructors exist (even if not directly using unresolved symbols, e.g., an external function declaration) - GPU modules introduce mandatory binary loading logic ## Usage ```c // Create engine without initialization MlirExecutionEngine jit = mlirExecutionEngineCreate(...); // Register required symbols mlirExecutionEngineRegisterSymbol(jit, ...); // Explicitly initialize (runs global constructors) mlirExecutionEngineInitialize(jit); ``` --------- Co-authored-by: Mehdi Amini <joker.eph@gmail.com>
2024-11-19[MLIR] Add SystemZ arg extensions for some tests (#116314)Jonas Paulsson
The SystemZ ABI requires that i32 values should be extended when passed between functions. This patch fixes some tests that were lacking this, either by adding some SystemZ specific inlinings of test functions or by disabling the verification of this with the CL option controlling this. Fixes #115564
2024-10-15[MLIR][OpenMP] Remove terminators from loop wrappers (#112229)Sergio Afonso
This patch simplifies the representation of OpenMP loop wrapper operations by introducing the `NoTerminator` trait and updating accordingly the verifier for the `LoopWrapperInterface`. Since loop wrappers are already limited to having exactly one region containing exactly one block, and this block can only hold a single `omp.loop_nest` or loop wrapper and an `omp.terminator` that does not return any values, it makes sense to simplify the representation of loop wrappers by removing the terminator. There is an extensive list of Lit tests that needed updating to remove the `omp.terminator`s adding some noise to this patch, but actual changes are limited to the definition of the `omp.wsloop`, `omp.simd`, `omp.distribute` and `omp.taskloop` loop wrapper ops, Flang lowering for those, `LoopWrapperInterface::verifyImpl()`, SCF to OpenMP conversion and OpenMP dialect documentation.
2024-04-24[MLIR][OpenMP] Make omp.wsloop into a loop wrapper (1/5) (#89209)Sergio Afonso
This patch updates the definition of `omp.wsloop` to enforce the restrictions of a loop wrapper operation. Related tests are updated but this PR on its own will not pass premerge tests. All patches in the stack are needed before it can be compiled and passes tests.
2023-06-05Activate OpenMP translation in MLIR execution engine CAPI.Rafael Ubal Tena
We've observed that the MLIR Jit Engine fails when the `omp` dialect is used due to a failure to register OpenMP-related translations. This small patch addresses this issue. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D151577
2023-03-01[mlir][CAPI] Allow running pass manager on any operationrkayaith
`mlirPassManagerRun` is currently restricted to running on `builtin.module` ops, but this restriction doesn't exist on the C++ side. This renames it to `mlirPassManagerRunOnOp` and updates it to take `MlirOperation` instead of `MlirModule`. Depends on D143352 Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D143354
2023-02-11Reland "[mlir][func] Use the generated pass options in func to llvm."Tobias Gysi
Update the FuncToLLVM pass to use the generated constructors and the generated pass option struct. The hand written constructor got out of sync after some refactorings. Using a generated constructor and options struct ensures the everything remains in sync. Reviewed By: zero9178 This reverts commit 39da46826da82c24ca4407c13ad7feb8e5dc32a1 and relands commit 771d9c05afc2515b474fb53db857716dfdfc1dcf which was originally reverted due to https://lab.llvm.org/buildbot#builders/61/builds/39694 Differential Revision: https://reviews.llvm.org/D143733
2023-02-11Revert "[mlir][func] Use the generated pass options in func to llvm."Tobias Gysi
The commit breaks the mlir-vulkan runner: https://lab.llvm.org/buildbot#builders/61/builds/39694 This reverts commit 771d9c05afc2515b474fb53db857716dfdfc1dcf.
2023-02-11[mlir][func] Use the generated pass options in func to llvm.Tobias Gysi
Update the FuncToLLVM pass to use the generated constructors and the generated pass option struct. The hand written constructor got out of sync after some refactorings. Using a generated constructor and options struct ensures the everything remains in sync. Reviewed By: zero9178 Differential Revision: https://reviews.llvm.org/D143733
2022-12-12[mlir] Fix -Wstrict-prototypes warningTom Eccles
These warnings prevent compilation using clang and -DLLVM_ENABLE_WERROR=On. Differential revision: https://reviews.llvm.org/D139322
2022-10-20[mlir] Fix and test python bindings for dump_to_object_fileDenys Shabalin
Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D136334
2022-09-29[mlir][arith] Change dialect name from Arithmetic to ArithJakub Kuderski
Suggested by @lattner in https://discourse.llvm.org/t/rfc-define-precise-arith-semantics/65507/22. Tested with: `ninja check-mlir check-mlir-integration check-mlir-mlir-spirv-cpu-runner check-mlir-mlir-vulkan-runner check-mlir-examples` and `bazel build --config=generic_clang @llvm-project//mlir:all`. Reviewed By: lattner, Mogball, rriddle, jpienaar, mehdi_amini Differential Revision: https://reviews.llvm.org/D134762
2022-09-27[MLIR] Migrate Arithmetic -> LLVM conversion pass to the auto-generated ↵Michele Scuttari
constructor See #57475 Differential Revision: https://reviews.llvm.org/D134752
2022-08-30Revert "[MLIR] Update pass declarations to new autogenerated files"Michele Scuttari
This reverts commit 2be8af8f0e0780901213b6fd3013a5268ddc3359.
2022-08-30[MLIR] Update pass declarations to new autogenerated filesMichele Scuttari
The patch introduces the required changes to update the pass declarations and definitions to use the new autogenerated files and allow dropping the old infrastructure. Reviewed By: mehdi_amini, rriddle Differential Review: https://reviews.llvm.org/D132838
2022-08-18[mlir][test] Require JIT support in JIT testsRainer Orth
A number of mlir tests `FAIL` on Solaris/sparcv9 with `Target has no JIT support`. This patch fixes that by mimicing `clang/test/lit.cfg.py` which implements a `host-supports-jit` keyword for this. The gtest-based unit tests don't support `REQUIRES:`, so lack of support needs to be hardcoded there. Tested on `amd64-pc-solaris2.11` (`check-mlir` results unchanged) and `sparcv9-sun-solaris2.11` (only one unrelated failure left). Differential Revision: https://reviews.llvm.org/D131151
2022-07-16[mlir] Overhaul C/Python registration APIs to properly scope ↵Stella Laurenzo
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 MlirDialectRegistry This 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/56037 Here 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, ftynse Differential Revision: https://reviews.llvm.org/D128593
2022-05-23[mlir] Use 'native' instead of 'llvm_has_native_target' in the mlir testsStella Stamenova
The tests actually require the target triple to match the host, rather than just having the host in the list of available targets. This change removes `llvm_has_native_target` and instead uses the `native` feature from the lit configuration. Reviewed By: stellaraccident Differential Revision: https://reviews.llvm.org/D126011
2022-04-20[mlir][NFC] Update remaining textual references of un-namespaced `func` ↵River Riddle
operations The special case parsing of operations in the `func` dialect is being removed, and operations will require the dialect namespace prefix.
2022-03-16[mlir] Move the Builtin FuncOp to the Func dialectRiver Riddle
This commit moves FuncOp out of the builtin dialect, and into the Func dialect. This move has been planned in some capacity from the moment we made FuncOp an operation (years ago). This commit handles the functional aspects of the move, but various aspects are left untouched to ease migration: func::FuncOp is re-exported into mlir to reduce the actual API churn, the assembly format still accepts the unqualified `func`. These temporary measures will remain for a little while to simplify migration before being removed. Differential Revision: https://reviews.llvm.org/D121266
2022-03-07[mlir][NFC] Rename StandardToLLVM to FuncToLLVMRiver Riddle
The current StandardToLLVM conversion patterns only really handle the Func dialect. The pass itself adds patterns for Arithmetic/CFToLLVM, but those should be/will be split out in a followup. This commit focuses solely on being an NFC rename. Aside from the directory change, the pattern and pass creation API have been renamed: * populateStdToLLVMFuncOpConversionPattern -> populateFuncToLLVMFuncOpConversionPattern * populateStdToLLVMConversionPatterns -> populateFuncToLLVMConversionPatterns * createLowerToLLVMPass -> createConvertFuncToLLVMPass Differential Revision: https://reviews.llvm.org/D120778
2022-01-14Mark some MLIR tests as requiring the native target to be configuredMehdi Amini
This makes `ninja check-mlir` work without the host targets configured.
2021-10-13[MLIR] Replace std ops with arith dialect opsMogball
Precursor: https://reviews.llvm.org/D110200 Removed redundant ops from the standard dialect that were moved to the `arith` or `math` dialects. Renamed all instances of operations in the codebase and in tests. Reviewed By: rriddle, jpienaar Differential Revision: https://reviews.llvm.org/D110797
2021-06-12[MLIR] Execution engine python binding support for shared librariesUday Bondhugula
Add support to Python bindings for the MLIR execution engine to load a specified list of shared libraries - for eg. to use MLIR runtime utility libraries. Differential Revision: https://reviews.llvm.org/D104009
2021-05-16[MLIR][PYTHON] Provide opt level for ExecutionEngine Python bindingUday Bondhugula
Provide an option to specify optimization level when creating an ExecutionEngine via the MLIR JIT Python binding. Not only is the specified optimization level used for code generation, but all LLVM optimization passes at the optimization level are also run prior to machine code generation (akin to the mlir-cpu-runner tool). Default opt level continues to remain at level two (-O2). Contributions in part from Prashant Kumar <prashantk@polymagelabs.com> as well. Differential Revision: https://reviews.llvm.org/D102551
2021-03-03Add C bindings for mlir::ExecutionEngineMehdi Amini
This adds minimalistic bindings for the execution engine, allowing to invoke the JIT from the C API. This is still quite early and experimental and shouldn't be considered stable in any way. Differential Revision: https://reviews.llvm.org/D96651