summaryrefslogtreecommitdiff
path: root/mlir/lib/CAPI/ExecutionEngine
AgeCommit message (Collapse)Author
2025-08-17[MLIR] Split ExecutionEngine Initialization out of ctor into an explicit ↵Shenghang Tsai
method call (#153524) Retry landing https://github.com/llvm/llvm-project/pull/153373 ## Major changes from previous attempt - remove the test in CAPI because no existing tests in CAPI deal with sanitizer exemptions - update `mlir/docs/Dialects/GPU.md` to reflect the new behavior: load GPU binary in global ctors, instead of loading them at call site. - skip the test on Aarch64 since we have an issue with initialization there --------- Co-authored-by: Mehdi Amini <joker.eph@gmail.com>
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>
2025-02-15[MLIR] Fix mlirExecutionEngineLookup throwing assert on lookup fail (#123924)Edgar
Apparently trying to lookup a function pointer using the C api `mlirExecutionEngineLookup` will throw an assert instead of just returning a nullptr on builds with asserts. The docs itself says it returns a nullptr when no function is found so it should be sensible to not throw an assert in this case.
2025-01-22Reapply "[mlir] Link libraries that aren't included in libMLIR to libMLIR" ↵Michał Górny
(#123910) Use `mlir_target_link_libraries()` to link dependencies of libraries that are not included in libMLIR, to ensure that they link to the dylib when they are used in Flang. Otherwise, they implicitly pull in all their static dependencies, effectively causing Flang binaries to simultaneously link to the dylib and to static libraries, which is never a good idea. I have only covered the libraries that are used by Flang. If you wish, I can extend this approach to all non-libMLIR libraries in MLIR, making MLIR itself also link to the dylib consistently. [v3 with more `-DBUILD_SHARED_LIBS=ON` fixes]
2025-01-22Revert "[mlir] Link libraries that aren't included in libMLIR to libMLIR ↵Michał Górny
(#123781)" This reverts commit 4c6242ebf50dde0597df2bace49d534b61122496. More BUILD_SHARED_LIBS=ON regressions, sigh.
2025-01-22[mlir] Link libraries that aren't included in libMLIR to libMLIR (#123781)Michał Górny
Use `mlir_target_link_libraries()` to link dependencies of libraries that are not included in libMLIR, to ensure that they link to the dylib when they are used in Flang. Otherwise, they implicitly pull in all their static dependencies, effectively causing Flang binaries to simultaneously link to the dylib and to static libraries, which is never a good idea. I have only covered the libraries that are used by Flang. If you wish, I can extend this approach to all non-libMLIR libraries in MLIR, making MLIR itself also link to the dylib consistently. [v2 with fixed `-DBUILD_SHARED_LIBS=ON` build]
2023-09-14[NFC][CodeGen] Change CodeGenOpt::Level/CodeGenFileType into enum classes ↵Arthur Eubanks
(#66295) This will make it easy for callers to see issues with and fix up calls to createTargetMachine after a future change to the params of TargetMachine. This matches other nearby enums. For downstream users, this should be a fairly straightforward replacement, e.g. s/CodeGenOpt::Aggressive/CodeGenOptLevel::Aggressive or s/CGFT_/CodeGenFileType::
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-27[mlir] Update JitRunner, ExecutionEngine after LLVM commit 8b1771bd9f3.Lang Hames
LLVM commit 8b1771bd9f3 replaced JITEvaluatedSymbol with ExecutorSymbolDef.
2023-03-21[mlir] Support lowering of dialect attributes attached to top-level modulesSergio Afonso
This patch supports the processing of dialect attributes attached to top-level module-type operations during MLIR-to-LLVMIR lowering. This approach modifies the `mlir::translateModuleToLLVMIR()` function to call `ModuleTranslation::convertOperation()` on the top-level operation, after its body has been lowered. This, in turn, will get the `LLVMTranslationDialectInterface` object associated to that operation's dialect before trying to use it for lowering prior to processing dialect attributes attached to the operation. Since there are no `LLVMTranslationDialectInterface`s for the builtin and GPU dialects, which define their own module-type operations, this patch also adds and registers them. The requirement for always calling `mlir::registerBuiltinDialectTranslation()` before any translation of MLIR to LLVM IR where builtin module operations are present is introduced. The purpose of these new translation interfaces is to succeed when processing module-type operations, allowing the lowering process to continue and to prevent the introduction of failures related to not finding such interfaces. Differential Revision: https://reviews.llvm.org/D145932
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-04-11Reland [mlir] Remove uses of LLVM's legacy pass managerArthur Eubanks
Use the new pass manager. This also removes the ability to run arbitrary sets of passes. Not sure if this functionality is used, but it doesn't seem to be tested. No need to initialize passes outside of constructing the PassBuilder with the new pass manager. Reland: Fixed custom calls to `-lower-matrix-intrinsics` in integration tests by replacing them with `-O0 -enable-matrix`. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D123425
2022-04-11Revert "[mlir] Remove uses of LLVM's legacy pass manager"Arthur Eubanks
This reverts commit b0f7f6f78d050cc89b31c87fb48744989145af60. Causes test failures: https://lab.llvm.org/buildbot#builders/61/builds/24879
2022-04-11[mlir] Remove uses of LLVM's legacy pass managerArthur Eubanks
Use the new pass manager. This also removes the ability to run arbitrary sets of passes. Not sure if this functionality is used, but it doesn't seem to be tested. No need to initialize passes outside of constructing the PassBuilder with the new pass manager. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D123425
2022-02-23[mlir][NFC] Use options struct in ExecutionEngine::createEmilio Cota
Its number of optional parameters has grown too large, which makes adding new optional parameters quite a chore. Fix this by using an options struct. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D120380
2021-12-13[mlir][ExecutionEngine] Fix native dependencies for AsmParser and PrinterNicolas Vasilache
This is a post-commit fix for https://reviews.llvm.org/D114338 which was landed as https://reviews.llvm.org/rG050cc1cd6e6882eadba6e5ea7b588ca0b8aa1b12 Differential Revision: https://reviews.llvm.org/D115666
2021-11-26[MLIR] NFC. Rename MLIR CAPI ExecutionEngine target for consistencyUday Bondhugula
Rename MLIR CAPI ExecutionEngine target for consistency: MLIRCEXECUTIONENGINE -> MLIRCAPIExecutionEngine in line with other targets. Differential Revision: https://reviews.llvm.org/D114596
2021-11-22Rename MlirExecutionEngine lookup to lookupPackedTres Popp
The purpose of the change is to make clear whether the user is retrieving the original function or the wrapper function, in line with the invoke commands. This new functionality is useful for users that already have defined their own packed interface, so they do not want the extra layer of indirection, or for users wanting to the look at the resulting primary function rather than the wrapper function. All locations, except the python bindings now have a `lookupPacked` method that matches the original `lookup` functionality. `lookup` still exists, but with new semantics. - `lookup` returns the function with a given name. If `bool f(int,int)` is compiled, `lookup` will return a reference to `bool(*f)(int,int)`. - `lookupPacked` returns the packed wrapper of the function with the given name. If `bool f(int,int)` is compiled, `lookupPacked` will return `void(*mlir_f)(void**)`. Differential Revision: https://reviews.llvm.org/D114352
2021-11-22[mlir] Add InitializeNativeTargetAsmParser to ExecutionEngine.Nicolas Vasilache
This is required to allow python to work with lowerings that use inline_asm. Differential Revision: https://reviews.llvm.org/D114338
2021-11-11[mlir] Add MLIR-C dylib.Stella Laurenzo
Per discussion on discord and various feature requests across bindings (Haskell and Rust bindings authors have asked me directly), we should be building a link-ready MLIR-C dylib which exports the C API and can be used without linking to anything else. This patch: * Adds a new MLIR-C aggregate shared library (libMLIR-C.so), which is similar in name and function to libLLVM-C.so. * It is guarded by the new CMake option MLIR_BUILD_MLIR_C_DYLIB, which has a similar purpose/name to the LLVM_BUILD_LLVM_C_DYLIB option. * On all platforms, this will work with both static, BUILD_SHARED_LIBS, and libMLIR builds, if supported: * In static builds: libMLIR-C.so will export the CAPI symbols and statically link all dependencies into itself. * In BUILD_SHARED_LIBS: libMLIR-C.so will export the CAPI symbols and have dynamic dependencies on implementation shared libraries. * In libMLIR.so mode: same as static. libMLIR.so was not finished for actual linking use within the project. An eventual relayering so that libMLIR-C.so depends on libMLIR.so is possible but requires first re-engineering the latter to use the aggregate facility. * On Linux, exported symbols are filtered to only the CAPI. On others (MacOS, Windows), all symbols are exported. A CMake status is printed unless if global visibility is hidden indicating that this has not yet been implemented. The library should still work, but it will be larger and more likely to conflict until fixed. Someone should look at lifting the corresponding support from libLLVM-C.so and adapting. Or, for special uses, just build with `-DCMAKE_CXX_VISIBILITY_PRESET=hidden -DCMAKE_C_VISIBILITY_PRESET=hidden`. * Includes fixes to execution engine symbol export macros to enable default visibility. Without this, the advice to use hidden visibility would have resulted in test failures and unusable execution engine support libraries. Differential Revision: https://reviews.llvm.org/D113731
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-04-19[mlir][python] ExecutionEngine can dump to object fileNicolas Vasilache
Differential Revision: https://reviews.llvm.org/D100786
2021-03-30Add a "register_runtime" method to the mlir.execution_engine and show ↵Mehdi Amini
calling back from MLIR into Python This exposes the ability to register Python functions with the JIT and exposes them to the MLIR jitted code. The provided test case illustrates the mechanism. Differential Revision: https://reviews.llvm.org/D99562
2021-03-04[mlir] make implementations of translation to LLVM IR interfaces privateAlex Zinenko
There is no need for the interface implementations to be exposed, opaque registration functions are sufficient for all users, similarly to passes. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D97852
2021-03-03Add basic JIT Python BindingsMehdi Amini
This offers the ability to create a JIT and invoke a function by passing ctypes pointers to the argument and the result. Differential Revision: https://reviews.llvm.org/D97523
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