Skip to content

feat(cutile): legalize mixed FP8xFP4 mmaf_scaled for Tile IR 13.3 - #230

Open
lucifer1004 wants to merge 1 commit into
NVlabs:mainfrom
lucifer1004:pr/mixed-mmaf-scaled
Open

feat(cutile): legalize mixed FP8xFP4 mmaf_scaled for Tile IR 13.3#230
lucifer1004 wants to merge 1 commit into
NVlabs:mainfrom
lucifer1004:pr/mixed-mmaf-scaled

Conversation

@lucifer1004

Copy link
Copy Markdown
Contributor

Motivation

W4A8 kernels (e.g. MoE weight-path GEMMs with FP4 weights and FP8 activations) naturally want a block-scaled MMA with one FP8 and one FP4 operand. Today mmaf_scaled requires both operands to share a single element type (EIn), so this combination is not expressible in the DSL at all.

What this adds

  • cutile::core::mmaf_scaled is generalized from one element-type parameter (EIn) to two (ELhs, ERhs).
  • Compiler legalization: CUDA Tile IR 13.3 requires both mmaf_scaled operands to have the same element type, so a mixed FP8×FP4 call is legalized at emission time: the logical FP4 tile is widened to the FP8 type with an exact ftof (nearest-even — every FP4 E2M1 value is exactly representable in FP8 E4M3/E5M2), keeping the original block scales unchanged. Unsupported mixed combinations are rejected with a clear error.

This is documented honestly in cutile-book: the legalization preserves W4A8 values and W4 storage, but it is a semantic fallback — it does not claim native mixed-input MMA throughput. If Tile IR later exposes a native mixed-input scaled MMA, the legalization can be retired behind the same DSL signature.

Tests

compile_raw_mmaf_scaled_fp8_fp4_legalizes_for_tile_ir_13_3 compiles a kernel feeding an f8e4m3fn lhs tile and an unpacked f4e2m1fn rhs tile (with E8M0 block scales) into mmaf_scaled and asserts the emitted MLIR contains the unpack, the widening ftof, and a same-type mmaf_scaled. The full tensor_and_matrix_ops suite (19 tests, including the existing same-type scaled-MMA coverage) passes.

Generalize mmaf_scaled to distinct lhs/rhs element types. CUDA Tile IR
13.3 requires both scaled-MMA operands to share an element type, so a
mixed FP8 x FP4 call is legalized by widening the FP4 tile to the FP8
type with an exact nearest-even ftof while retaining the original block
scales. This keeps W4A8 kernels expressible in the DSL without claiming
native mixed-input MMA throughput.
@copy-pr-bot

copy-pr-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@elibol elibol modified the milestone: cuTile Rust v0.3.1 Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants