Repository navigation
Description
Following the footsteps of @bjacob , port AArch64 and RVV intrinsics to the inner_tiled mechanism.
Define the intrinsic and the data-tiled layouts
The current data-tiled layout enumeration mechanism for mmt4d from CPUEncodingExternalModels annotates the register-blocked ukernel tiles. The inner_tiled mechanism is based on the shape of one intrinsic, not the full tile, and the unrolling/blocking factors are handled explicitly by intrinsics_m/n/k. The transpose for narrow-M/N mechanisms are (to the best of my knowledge) replaced by explicitly transposed intrinsics for the M-N swapped variants.
getRowMajorTilesMNKShape, getABCElementTypes and getRegisterSpaceBytes are the relevant bits from IREECPUAttrs.cpp.
Adding a swizzle pattern is also possible, if an operand's in-register element order is not row major.
- Define the intrinsic and add the corresponding data-tiled layouts.
- Plumb through the intrinsic selection in CPUEncodingExternalModels so that we can emit
inner_tiledops with these intrinsics.
Relevant PRs
- [Codegen][CPU] Add x86 AVX-512 VNNI vpdpbusd MMA intrinsic. #24494
- Initial plumbing for inner_tiled on CPU with data-tiled MMA attribute. #23494
- [Codegen][CPU] Replace transposed_intrinsic with explicit pre-transposed enums. #24456
- [Codegen][CPU] Materialize data-tiled encodings to inner_tiled. #24289
- swizzle: [Codegen][CPU] Add x86 AVX-512 VNNI 16x16x2 i8 MMA intrinsic. #24534
Lower to the corresponding intrinsic calls
During LLVMCPUVirtualVectorLowering, the inner_tiled op is unrolled and lowered to the corresponding intrinsic calls. Plumb that in here and make sure that the operands are passed correctly, e.g. as scalars for *.vf RVV-intrinsics, or broadcasted, or replicated across lanes etc.
So it's worthwhile compiling the intrinsic you're targeting with the mmt4d path, and checking the corresponding microkernels to deduce the expected operand forms. (Here, there will be some zip/uzip-like intrinsics for both the AArch64 and RVV ukernels, which account for the mismatch in representation of the layout that the ukernel actually wants and what mmt4d layouts can represent. We can represent those layouts now.)
Relevant PRs
- [Codegen][CPU] Lower inner_tiled to llvm.call_intrinsic. #24345
- [Codegen][CPU] Route inner_tiled broadcast into m_bcst-foldable slot. #24516
- [Codegen][CPU] Add x86 AVX-512 VNNI 16x16x2 i8 MMA intrinsic. #24534
Existing x86 path
Currently, the x86 path exists and can be checked out via:
iree-compile matmul.mlir -o /dev/null \
--iree-hal-target-device=local \
--iree-hal-local-target-device-backends=llvm-cpu \
--iree-llvmcpu-target-triple=x86_64-unknown-linux-gnu \
--iree-llvmcpu-target-cpu-features=+avx2,+fma,+avx512f,+avx512bw,+avx512vl,+avx512dq,+avx512vnni,+avx512bf16 \
--iree-opt-data-tiling=true \
--iree-llvmcpu-enable-ukernels=none \
--iree-llvmcpu-enable-inner-tiled=true \
--mlir-print-ir-after-all --mlir-print-ir-after-change &> /tmp/x86.log// matmul.mlir
func.func @matmul(%A: tensor<8192x3072xf32>, %B: tensor<3072x8192xf32>) -> tensor<8192x8192xf32> {
%empty = tensor.empty() : tensor<8192x8192xf32>
%c0 = arith.constant 0.0 : f32
%C = linalg.fill ins(%c0 : f32) outs(%empty : tensor<8192x8192xf32>) -> tensor<8192x8192xf32>
%0 = linalg.matmul ins(%A, %B : tensor<8192x3072xf32>, tensor<3072x8192xf32>)
outs(%C : tensor<8192x8192xf32>) -> tensor<8192x8192xf32>
return %0 : tensor<8192x8192xf32>
}
func.func @matmul2(%A: tensor<8192x3072xi8>, %B: tensor<3072x8192xi8>) -> tensor<8192x8192xi32> {
%empty = tensor.empty() : tensor<8192x8192xi32>
%c0 = arith.constant 0 : i32
%C = linalg.fill ins(%c0 : i32) outs(%empty : tensor<8192x8192xi32>) -> tensor<8192x8192xi32>
%0 = linalg.matmul ins(%A, %B : tensor<8192x3072xi8>, tensor<3072x8192xi8>)
outs(%C : tensor<8192x8192xi32>) -> tensor<8192x8192xi32>
return %0 : tensor<8192x8192xi32>
}You can try it out and see how everything is lowered.
NOTE: Possibly, the support we have for different SIMD lengths on the RVV side through the +zvl*b flags are not 1:1 portable to inner_tiled directly, since the intrinsics currently bake-in the static shape of the intrinsic operands. That would lead to the duplication of the same intrinsic over all possible vector lengths, which we do not want and is currently also not fit into the enum bit schema. I'm taking a look at this currently, so while I'm at it, please go ahead and start from AArch64 intrinsics if you don't mind, or pick a vector length of your choice (256 should be good for the SpaceMiT K1) and start with that one. We might have to re-wire those to accept every VLEN later though.
Activity
TMahlatini commentedon Aug 17, 2026
@egebeysel please assign me this issue
shuangjuliu commentedon Aug 18, 2026
@egebeysel please assign me this issue,.
[LLVMCPU] `vlen` attribute for DataTiledMMAAttr for RISCV + FP16 port (…
[Codegen][CPU] Add RISC-V V f32 vfmacc.vf inner_tiled MMA.
[Codegen][CPU] Add RISC-V V f32 vfmacc.vf inner_tiled MMA.
[Codegen][CPU] Add RISC-V V f32 vfmacc.vf inner_tiled MMA. (#24933)
[Codegen][CPU] Lower RISC-V V f16 vfmacc, vfwmacc, and Zvfhmin inner_…
[Codegen][CPU] Lower RISC-V V f16 vfmacc, vfwmacc, and Zvfhmin inner_…
[Codegen][CPU] Add AArch64 SVE f32 inner_tiled support
[Codegen][CPU] Lower RISC-V V f16 vfmacc, vfwmacc, and Zvfhmin inner_…
[Codegen][CPU] Lower RISC-V V f16 vfmacc, vfwmacc, and Zvfhmin inner_…
[Codegen][CPU] Add RISC-V V bf16 vfwmaccbf16 inner_tiled MMA.
[Codegen][CPU] Add RISC-V V bf16 vfwmaccbf16 inner_tiled MMA.
[Codegen][CPU] Add RISC-V V bf16 vfwmaccbf16 inner_tiled MMA.
[Codegen][CPU] Add RISC-V V bf16 vfwmaccbf16 inner_tiled MMA. (#25120)