Skip to content

Lower 16x16 Triton tl.dot to mma.sync with scalar fallback - #179

Open
Srikanth1234567808 wants to merge 3 commits into
Zaneham:masterfrom
Srikanth1234567808:triton-tile-mma
Open

Srikanth1234567808 wants to merge 3 commits into
Zaneham:masterfrom
Srikanth1234567808:triton-tile-mma

Conversation

@Srikanth1234567808

Copy link
Copy Markdown

What this does

Bridges Triton tl.dot to Booth's existing matrix IR for 16x16x16 and 16x16x8 tiles, instead of materialising the tile and unrolling it into scalar FMAs.

  • Triton: the tile lowering stages row-major operand tiles and emits BIR_MMA (with a documented 0x80 subop flag marking f32-staged inputs).
  • NVIDIA PTX: is_mma() converts the staged f32 operands to half at fragment load and emits real mma.sync instructions.
  • Every other target: a new bir_expand_mma() IR pass rewrites the op into ordinary BIR loads/FMAs/stores via bir_insert(), so the same kernel compiles on CPU, RV64, AMD and Metal. Previously all matrix ops were refused by those backends.
  • Raises the CPU/RV64 code buffers for the expanded instruction stream.
  • Fixes a pre-existing strict-build failure (_GNU_SOURCE for MAP_ANONYMOUS / RTLD_DEFAULT).

Measured effect

Same 16x16x16 Triton matmul, compiled to PTX before and after:

before after
PTX instructions 10442 5021
mul.rn.f32 4096 0
add.rn.f32 3840 0
mma.sync.aligned 0 2

Verification

  • make test: 1075 tests, 1057 passed, 0 failed, 18 skipped (18 need llvm-objdump, absent here).
  • bash tests/diff/run_diff.sh: PASS, including a new numeric matmul differential (256/256 exact) with an --inject guard.
  • PTX inspected for mma.sync at both K=16 and K=8; multi-MMA kernels validated numerically on CPU.
  • AMD, Metal and RV64 compilation of the new kernel succeeds.

Scope and limitations (please review with these in mind)

This is a bring-up slice, not the whole Triton matrix-core roadmap item:

  • No GPU hardware validation was possible here (no NVIDIA/AMD device). The tensor-core path is verified as emitted PTX plus equivalent CPU numerics; a hardware run is still wanted.
  • AMD uses the scalar expansion, not MFMA. Triton -> MFMA is not wired up.
  • --nvidia-cubin has no SASS form for mma.sync (also true of the CUDA MMA builtins); use --nvidia-ptx. Large matmuls exceed cubin's code capacity regardless of this change.
  • Other tile shapes still take the scalar unroll path.
  • The expansion pass uses static BSS scratch (kath is single-threaded) and the code-buffer caps grew from 256 KiB to 4 MiB.

MAP_ANONYMOUS and RTLD_DEFAULT are hidden by -std=c99 -pedantic. Without _GNU_SOURCE the strict build fails before any compiler work can run.
The tile lowering stages row-major f32 operands and emits BIR_MMA for 16x16x16 and 16x16x8 dots. NVIDIA converts to half at fragment load and emits real mma.sync; targets without tensor cores run a new IR pass that expands the op into ordinary BIR FMAs, so the same kernel compiles and validates on CPU, RV64, AMD and Metal. Raises the CPU/RV64 code buffers for the expanded instruction stream.
Adds Triton matmul fixtures for K=16 and K=8, PTX and CPU regression tests, a numeric differential check with an injection guard, and updates the feature status, roadmap and changelog to describe what the new path does and does not cover.
@Zaneham Zaneham added the Triton Triton frontend (Python subset, tl.* intrinsics) label Dec 4, 2026
@Zaneham

Zaneham commented Dec 4, 2026

Copy link
Copy Markdown
Owner

Hello, letting CI run, don't worry about Tensix too much as that's an "on their side" issue. It'll just take me some time to test this on some hardware.

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

Labels

Triton Triton frontend (Python subset, tl.* intrinsics)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants