Skip to content

[Codegen][AMDGPU] Unsigned i8 matmuls use signed i8 MMA intrinsics #25375

Todo

Description

@roberto-laudani

What happened?

On AMDGPU, unsigned i8 matmuls lower to the signed i8 MMA intrinsics. gfx1100 emits:

v_wmma_i32_16x16x16_iu8 v[1:8], v[9:12], v[13:16], v[1:8] neg_lo:[1,1,0]

neg_lo:[1,1,0] marks A and B as signed, so values from 128 to 255 are read as negative. gfx1201 emits the same. gfx942 and gfx950 use the i8 MFMA intrinsics, which are signed only.

Expected: the llvm-cpu result. With --input=16x16xi8=-1 for both operands, every element is 1040400.

Steps to reproduce your issue

matmul_u8.mlir:

func.func @matmul_u8(%lhs: tensor<16x16xi8>, %rhs: tensor<16x16xi8>) -> tensor<16x16xi32> {
  %c0 = arith.constant 0 : i32
  %empty = tensor.empty() : tensor<16x16xi32>
  %fill = linalg.fill ins(%c0 : i32) outs(%empty : tensor<16x16xi32>) -> tensor<16x16xi32>
  %0 = linalg.matmul {cast = #linalg.type_fn<cast_unsigned>}
      ins(%lhs, %rhs : tensor<16x16xi8>, tensor<16x16xi8>)
      outs(%fill : tensor<16x16xi32>) -> tensor<16x16xi32>
  return %0 : tensor<16x16xi32>
}
iree-compile --iree-hal-target-device=hip --iree-rocm-target=gfx1100 \
  --iree-hal-dump-executable-intermediates-to=out matmul_u8.mlir -o matmul_u8.vmfb
grep v_wmma out/*.rocmasm

What component(s) does this issue relate to?

Compiler

Version information

IREE main (ba3c176)

Additional context

The intrinsic is picked by element type only. canTargetIntrinsic and convertContractionToInnerTiledMma don't check the signedness of the operands, and the amdgpu.wmma ops never set unsignedA or unsignedB.

With the torch-mlir bump in #25365, the ONNX tests test_qlinearmatmul_{2D,3D}_uint8_{float16,float32} return all zeros on rdna3 and rdna4 and are expected run failures. The same tests pass on llvm-cpu.

Assisted-by: Claude Code

Activity

  1. added
    bug 🐞
    codegen/rocm
    on Dec 2, 2026
  2. payal101 commented on Dec 3, 2026

    @payal101

    can you assign this?

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

Metadata

Metadata

Assignees

Labels

bug 🐞codegen/rocm

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions