feat(cutile): legalize mixed FP8xFP4 mmaf_scaled for Tile IR 13.3 - #230
Open
lucifer1004 wants to merge 1 commit into
Open
feat(cutile): legalize mixed FP8xFP4 mmaf_scaled for Tile IR 13.3#230lucifer1004 wants to merge 1 commit into
lucifer1004 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_scaledrequires 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_scaledis generalized from one element-type parameter (EIn) to two (ELhs,ERhs).mmaf_scaledoperands 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 exactftof(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_3compiles a kernel feeding anf8e4m3fnlhs tile and an unpackedf4e2m1fnrhs tile (with E8M0 block scales) intommaf_scaledand asserts the emitted MLIR contains theunpack, the wideningftof, and a same-typemmaf_scaled. The fulltensor_and_matrix_opssuite (19 tests, including the existing same-type scaled-MMA coverage) passes.