623 Commits

Author SHA1 Message Date
Giacomo Castiglioni
6e7a44986d
[MLIR] Enable dylib init/deinit in execution engine on AArch64 platform (#172833)
This PR enables JIT initialize for AArch64. Up to now it was disabled
because of #71963 which was recently fixed by #71968.
2025-12-19 01:55:21 +01:00
Yi Zhang
188bf2769a
Fix variable only used by assert in #172716. (#172788) 2025-12-17 23:47:05 -05:00
Maksim Levental
54eee1e947
Reapply "[mlir][math] Add FP software implementation lowering pass: math-to-apfloat" (#172714) (#172716)
Reapply https://github.com/llvm/llvm-project/pull/171221 - Fix builder
by linking `MLIRTransformUtils`. Also move headers to
`mlir/Conversion/ArithAndMathToAPFloat`.
2025-12-17 17:26:37 -08:00
Maksim Levental
621fe03eaa
Revert "[mlir][math] Add FP software implementation lowering pass: math-to-apfloat" (#172714)
Reverts llvm/llvm-project#171221

Broken builder https://lab.llvm.org/buildbot/#/builders/138/builds/23270
2025-12-17 10:52:43 -08:00
Maksim Levental
7f1a30ebd2
[mlir][math] Add FP software implementation lowering pass: math-to-apfloat (#171221)
Add APFloat software implementation for `math.fma`, `math.abs`,
`math.isnan`, `math.isfinite`, `math.isinf`, `math.isnormal` for reduced
precision (`fp4*`, `fp6*`, `fp8*`).
2025-12-17 18:37:13 +00:00
Maksim Levental
8d5ade8feb
[mlir] enable APFloatWrappers on MacOS (#172070) 2025-12-12 11:34:23 -08:00
Mehdi Amini
c1d030e9a4
[MLIR][ExecutionEngine] Don't create a _mlir_ wrapper function for internal linkage (#171115)
This is somehow NFC, we were creating wrapper for interal functions,
which are de-facto not callable.
2025-12-08 14:42:00 +01:00
Mehdi Amini
1bbff7290f [MLIR] Apply clang-tidy fixes for llvm-qualified-auto in VulkanRuntimeWrappers.cpp (NFC) 2025-12-08 04:12:47 -08:00
Mehdi Amini
5e3ffd66e7 [MLIR] Apply clang-tidy fixes for readability-identifier-naming in ArmRunnerUtils.cpp (NFC) 2025-12-08 03:48:14 -08:00
Matthias Springer
147c466bcd
[mlir][arith] Add support for min/max to ArithToAPFloat (#169760)
Add support for `arith.minnumf`, `arith.maxnumf`, `arith.minimumf`,
`arith.maximumf`.
2025-12-01 08:50:02 +00:00
Matthias Springer
05b1989551
[mlir][arith] Add support for negf to ArithToAPFloat (#169759)
Add support for `arith.negf`.
2025-12-01 08:28:23 +00:00
Matthias Springer
4d7abe5355
[mlir][arith] Add support for cmpf to ArithToAPFloat (#169753)
Add support for `arith.cmpf`.
2025-12-01 09:12:11 +01:00
Mehdi Amini
ae58ae1ca7 [MLIR] Apply clang-tidy fixes for misc-use-internal-linkage in CudaRuntimeWrappers.cpp (NFC) 2025-11-28 03:46:38 -08:00
Matthias Springer
6ec686735c
[mlir][arith] Add support for sitofp, uitofp to ArithToAPFloat (#169284)
Add support for `arith.sitofp` and `arith.uitofp`.
2025-11-25 11:31:23 +09:00
Matthias Springer
3db8ed0500
[mlir][arith] Add support for fptosi, fptoui to ArithToAPFloat (#169277)
Add support for `arith.fptosi` and `arith.fptoui`.
2025-11-25 10:50:20 +09:00
Matthias Springer
78994706d8
[mlir][arith] Add support for extf, truncf to ArithToAPFloat (#169275)
Add support for `arith.extf` and `arith.truncf`. No support for custom
rounding modes yet.
2025-11-25 10:09:26 +09:00
alessandra simmons
8c74cc5a76
[mlir] Remove filtering of deprecated rocm-agent-enumerator value gfx000 (#166634)
Getting a gfx000 result from the `rocm-agent-enumerator` command was
deprecated beginning with the release of ROCm 7, but the MLIR build
system still filters it from results when looking for ROCm agents. This
PR removes that filtering.

There are a few other uses of "gfx000" in MLIR source, but those are
used as default options for running some passes, and, to my
understanding, have a semantically different meaning to the dummy result
returned from `rocm-agent-enumerator` and don't need to be changed.
2025-11-14 13:19:49 -08:00
Matthias Springer
7e5155a98c
[mlir] Fix build after #167848 (#167855)
Fix build after #167848.
2025-11-13 18:58:01 +09:00
Matthias Springer
7a53d33e7c
[mlir] Add FP software implementation lowering pass: arith-to-apfloat (#167848)
Reland pass and fix linker errors.

---------

Co-authored-by: Maksim Levental <maksim.levental@gmail.com>
2025-11-13 18:35:30 +09:00
Maksim Levental
140e07c862
Revert "Reland yet again: [mlir] Add FP software implementation lowering pass: arith-to-apfloat" (#167834)
Reverts llvm/llvm-project#167608

Broken builder https://lab.llvm.org/buildbot/#/builders/52/builds/12781
2025-11-12 23:02:21 -08:00
Maksim Levental
0bba1e7658
Reland yet again: [mlir] Add FP software implementation lowering pass: arith-to-apfloat (#167608)
Fix both symbol visibility issue in the mlir_apfloat_wrappers lib and the linkage issue in ArithToAPFloat.
2025-11-12 17:57:53 -08:00
Maksim Levental
e67ac07881
Revert "Reapply "Reapply "[mlir] Add FP software implementation lowering pass: arith-to-apfloat (#166618)" (#167431)"" (#167549)
Reverts llvm/llvm-project#167436 to fix sanitizers
2025-11-11 09:29:09 -08:00
Maksim Levental
75751f33a8
Reapply "Reapply "[mlir] Add FP software implementation lowering pass: arith-to-apfloat (#166618)" (#167431)" (#167436)
Reland https://github.com/llvm/llvm-project/pull/166618 by fixing
missing symbol issues by explicitly loading
`--shared-libs=%mlir_apfloat_wrappers` as well as
`--shared-libs=%mlir_c_runner_utils`.
2025-11-11 08:50:37 -08:00
Maksim Levental
93b3c1b7e1
Revert "Reapply "[mlir] Add FP software implementation lowering pass: arith-to-apfloat (#166618)" (#167431)" (#167435)
This reverts commit 0e639ae6e030ade849fa7a09cb7dc40b42f25373.
2025-11-10 17:40:51 -08:00
Maksim Levental
0e639ae6e0
Reapply "[mlir] Add FP software implementation lowering pass: arith-to-apfloat (#166618)" (#167431)
Reland https://github.com/llvm/llvm-project/pull/166618 with
MLIRFuncUtils linked in.
2025-11-10 17:13:29 -08:00
Maksim Levental
70d379fd7a
Revert "[mlir] Add FP software implementation lowering pass: arith-to-apfloat (#166618)" (#167429)
This reverts commit 222f4e494a0cd9515c242fd083c2776772734385.
2025-11-10 16:54:44 -08:00
Maksim Levental
222f4e494a
[mlir] Add FP software implementation lowering pass: arith-to-apfloat (#166618)
This commit adds a new pass that lowers floating-point `arith`
operations to calls into the execution engine runtime library. Currently
supported operations: `addf`, `subf`, `mulf`, `divf`, `remf`.

All floating-point types that have an APFloat semantics are supported.
This includes low-precision floating-point types such as `f4E2M1FN` that
cannot execute natively on CPUs.

This commit also improves the `vector.print` lowering pattern to call
into the runtime library for floating-point types that are not supported
by LLVM. This is necessary to write a meaningful integration test.

The way it works is 

```mlir
func.func @full_example() {
  %a = arith.constant 1.4 : f8E4M3FN
  %b = func.call @foo() : () -> (f8E4M3FN)
  %c = arith.addf %a, %b : f8E4M3FN
  vector.print %c : f8E4M3FN
  return
}
```

gets transformed to

```mlir
func.func private @__mlir_apfloat_add(i32, i64, i64) -> i6
func.func @full_example() {
  %cst = arith.constant 1.375000e+00 : f8E4M3FN
  %0 = call @foo() : () -> f8E4M3FN
  // bitcast operand A to integer of equal width
  %1 = arith.bitcast %cst : f8E4M3FN to i8
  // zext A to i64
  %2 = arith.extui %1 : i8 to i64
  // same for operand B
  %3 = arith.bitcast %0 : f8E4M3FN to i8
  %4 = arith.extui %3 : i8 to i64
  // get the llvm::fltSemantics(f8E4M3FN) as an enum
  %c10_i32 = arith.constant 10 : i32
  // call the impl against APFloat in mlir_apfloat_wrappers
  %5 = call @__mlir_apfloat_add(%c10_i32, %2, %4) : (i32, i64, i64) -> i64
  // "cast" back to the original fp type
  %6 = arith.trunci %5 : i64 to i8
  %7 = arith.bitcast %6 : i8 to f8E4M3FN
  vector.print %7 : f8E4M3FN
}
```

Note, `llvm::fltSemantics(f8E4M3FN)` is emitted by the pattern each time
an `arith` op is transformed, thereby making the call to
`__mlir_apfloat_add` correct (i.e., no name mangling on type necessary).


RFC:
https://discourse.llvm.org/t/rfc-software-implementation-for-unsupported-fp-types-in-convert-arith-to-llvm/88785

---------

Co-authored-by: Matthias Springer <me@m-sp.org>
2025-11-10 16:21:39 -08:00
Maksim Levental
cd9d48777e
[MLIR][ExecutionEngine] don't dump decls (#164478)
Currently ExecutionEngine tries to dump all functions declared in the
module, even those which are "external" (i.e., linked/loaded at
runtime). E.g.

```mlir
func.func private @printF32(f32)
func.func @supported_arg_types(%arg0: i32, %arg1: f32) {
  call @printF32(%arg1) : (f32) -> ()
  return
}
```
fails with
```
Could not compile printF32:
  Symbols not found: [ __mlir_printF32 ]
Program aborted due to an unhandled Error:
Symbols not found: [ __mlir_printF32 ]
```
even though `printF32` can be provided at final build time (i.e., when
the object file is linked to some executable or shlib). E.g, if our own
`libmlir_c_runner_utils` is linked.

So just skip functions which have no bodies during dump (i.e., are decls
without defns).
2025-10-27 12:22:13 -07:00
Maksim Levental
90b51c3939
[MLIR][ExecutionEngine] don't leak -Wweak-vtables (#164498)
I'm not 100% what this is used for in this lib but the compile flag
leaks out and prevents (in certain compile scenarios) linking
`mlir_c_runner_utils`.
2025-10-23 06:41:02 -07:00
Mehdi Amini
ff130f293d [MLIR] Apply clang-tidy fixes for misc-use-internal-linkage in LevelZeroRuntimeWrappers.cpp (NFC) 2025-09-30 01:26:40 -07:00
Mehdi Amini
a40918b3fe [MLIR] Apply clang-tidy fixes for misc-use-internal-linkage in JitRunner.cpp (NFC) 2025-09-29 01:10:16 -07:00
Mehdi Amini
a69a46486a [MLIR] Apply clang-tidy fixes for misc-use-internal-linkage in VulkanRuntime.cpp (NFC) 2025-08-27 08:54:13 -07:00
Shenghang Tsai
7610b13729
[MLIR] Split ExecutionEngine Initialization out of ctor into an explicit 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-17 23:07:24 +02:00
Mehdi Amini
bfd490e0cd
Revert "[MLIR] Split ExecutionEngine Initialization out of ctor into an explicit method call" (#153477)
Reverts llvm/llvm-project#153373

Sanitizer bot is broken
2025-08-13 19:43:04 +00:00
Shenghang Tsai
2f93693f76
[MLIR] Split ExecutionEngine Initialization out of ctor into an explicit 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-08-13 15:22:01 +02:00
Md Abdullah Shahneous Bari
281e6d2cc4
[mlir][ExecutionEngine] Add LevelZeroRuntimeWrapper. (#151038)
Adds LevelZeroRuntime wrapper and tests.

Co-authored-by: Artem Kroviakov <artem.kroviakov@intel.com>
Co-authored-by: Nishant Patel <nishant.b.patel@intel.com>

---------

Co-authored-by: Artem Kroviakov <artem.kroviakov@intel.com>
Co-authored-by: Nishant Patel <nishant.b.patel@intel.com>
2025-08-06 16:48:59 -05:00
Momchil Velikov
962c4217bc
[MLIR][AArch64] Change some tests to ensure SVE vector length is the same throughout the function (#147506)
This change only applies to functions the can be reasonably expected to
use SVE registers.

Modifying vector length in the middle of a function might cause
incorrect stack deallocation if there are callee-saved SVE registers or
incorrect access to SVE stack slots.

Addresses (non-issue) https://github.com/llvm/llvm-project/issues/143670
2025-07-09 09:32:25 +01:00
Karlo Basioli
cd585864c0
Pass memory buffer to RuntimeDyld::MemoryManager factory (#142930)
`RTDyldObjectLinkingLayer` is currently creating a memory manager
without any parameters.

In this PR I am passing the MemoryBuffer that will be emitted to the
MemoryManager so that the user can use it to configure the behaviour of
the MemoryManager.
2025-06-06 00:44:39 +01:00
Sang Ik Lee
3fa65dee14
[mlir] SYCL runtime wrapper: add memcpy support. (#141647) 2025-05-28 11:33:15 -07:00
Longsheng Mou
34be80aa6e
[mlir-runner] Check entry function does not expect arguments (#136825)
This PR fixes a crash if entry function has inputs. Fixes #136143.
2025-05-15 09:19:39 +08:00
Rahul Joshi
b17f3c63de
[NFC][MLIR] Add {} for else when if body has {} (#139422) 2025-05-12 10:29:03 -07:00
Christian Sigg
7851b1bcf1
[mlir][gpu] Change GPU modules to globals (#135478)
Load/unload GPU modules in global ctors/dtors instead of each time when
launching a kernel.

Loading GPU modules is a heavy-weight operation and synchronizes the GPU
context. Now that the modules are loaded ahead of time, asynchronously
launched kernels can run concurrently, see
https://discourse.llvm.org/t/how-to-lower-the-combination-of-async-gpu-ops-in-gpu-dialect.

The implementations of `embedBinary()` and `launchKernel()` use slightly
different mechanics at the moment but I prefer to not change the latter
more than necessary as part of this PR. I will prepare a follow-up NFC
for `launchKernel()` to align them again.
2025-04-22 13:49:58 +02:00
Nikita Popov
979c275097
[IR] Store Triple in Module (NFC) (#129868)
The module currently stores the target triple as a string. This means
that any code that wants to actually use the triple first has to
instantiate a Triple, which is somewhat expensive. The change in #121652
caused a moderate compile-time regression due to this. While it would be
easy enough to work around, I think that architecturally, it makes more
sense to store the parsed Triple in the module, so that it can always be
directly queried.

For this change, I've opted not to add any magic conversions between
std::string and Triple for backwards-compatibilty purses, and instead
write out needed Triple()s or str()s explicitly. This is because I think
a decent number of them should be changed to work on Triple as well, to
avoid unnecessary conversions back and forth.

The only interesting part in this patch is that the default triple is
Triple("") instead of Triple() to preserve existing behavior. The former
defaults to using the ELF object format instead of unknown object
format. We should fix that as well.
2025-03-06 10:27:47 +01:00
Lang Hames
b18e5b6a36 Re-apply "[ORC] Remove the Triple argument from LLJITBuilder::..." with fixes.
This re-applies f905bf3e1ef860c4d6fe67fb64901b6bbe698a91, which was reverted in
c861c1a046eb8c1e546a8767e0010904a3c8c385 due to compiler errors, with a fix for
MLIR.
2025-03-06 17:17:05 +11:00
Andrea Faulds
eb206e9ea8
[mlir] Rename mlir-cpu-runner to mlir-runner (#123776)
With the removal of mlir-vulkan-runner (as part of #73457) in
e7e3c45bc70904e24e2b3221ac8521e67eb84668, mlir-cpu-runner is now the
only runner for all CPU and GPU targets, and the "cpu" name has been
misleading for some time already. This commit renames it to mlir-runner.
2025-01-24 14:08:38 +01:00
Michał Górny
047e8e47c1
Reapply "[mlir] Link libraries that aren't included in libMLIR to libMLIR" (#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-22 09:01:50 +00:00
Michał Górny
9decc24c6b Revert "[mlir] Link libraries that aren't included in libMLIR to libMLIR (#123781)"
This reverts commit 4c6242ebf50dde0597df2bace49d534b61122496.  More
BUILD_SHARED_LIBS=ON regressions, sigh.
2025-01-22 09:09:52 +01:00
Michał Górny
4c6242ebf5
[mlir] Link libraries that aren't included in libMLIR to libMLIR (#123781)
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]
2025-01-22 07:54:54 +00:00
Andrea Faulds
e7e3c45bc7
[mlir] Remove mlir-vulkan-runner and GPUToVulkan conversion passes (#123750)
This follows up on 733be4ed7dcf976719f424c0cb81b77a14f91f5a, which made
mlir-vulkan-runner and its associated passes redundant, and completes
the main goal of #73457. The mlir-vulkan-runner tests become part of the
integration test suite, and the Vulkan runner runtime components become
part of ExecutionEngine, just as was done when removing other
target-specific runners.
2025-01-21 16:51:27 +01:00
Michał Górny
8b879d106b Revert "[mlir] Link libraries that aren't included in libMLIR to libMLIR (#123477)"
This reverts commit af6616676fb7f9dd4898290ea684ee0c90f1701d.  It broke
builds with `-DBUILD_SHARED_LIBS=ON`.
2025-01-20 19:33:51 +01:00