Skip to content

[Codegen][CPU] Add AArch64 and RVV intrinsics to support inner_tiled materialization #24311

Open

Description

@egebeysel

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_tiled ops with these intrinsics.

Relevant PRs

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

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

  1. self-assigned this
    on Apr 30, 2026
  2. TMahlatini commented on Aug 17, 2026

    @TMahlatini
    Contributor

    @egebeysel please assign me this issue

  3. shuangjuliu commented on Aug 18, 2026

    @shuangjuliu

    @egebeysel please assign me this issue,.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions