Skip to content

[Triton/Gluon] Explicit tl.fma in blockscale GEMM kernels for Triton 3.9 - #7544

Merged
mengfei-jiang merged 9 commits into
ROCm:mainfrom
lijinpei-amd:2026-11-06-fused-a8w8-blockscale-a16w16-explicit-fma
Nov 23, 2026
Merged

mengfei-jiang merged 9 commits into
ROCm:mainfrom
lijinpei-amd:2026-11-06-fused-a8w8-blockscale-a16w16-explicit-fma

Conversation

@lijinpei-amd

@lijinpei-amd lijinpei-amd commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Triton 3.8 enables implicit FP contraction by default, but Triton 3.9 disables implicit FP contraction by default.
Expressions like accumulator += tl.dot(a, b) * scale are no longer lowered to a single FMA instruction — the compiler emits separate mul and add instead, causing performance regression.

Two changes in the fp8 K loop:

  1. Use tl.range(num_stages=2) for the loop. With num_stages on the loop, the Triton pipeliner also pipelines loads that do not feed tl.dot. The a_scale and b_scale loads are then issued one iteration ahead. Before, the wait for the scales also waited for the A/B prefetch.
  2. Compute the scale outer product first and use tl.fma for the accumulation. Triton 3.9 does not fuse mul and add by default, so the old expression gave separate mul and add instructions.

gfx950, M=4096 N8=512 N16=256 K=7168, median of 5 (us):

           3.9 fp8  3.9 both  3.8 fp8  3.8 both

before 129.9 141.5 122.8 131.6
after 77.8 120.3 76.9 119.7

The same explicit tl.fma fix is applied to four more kernels that had
the same Triton 3.9 regression:

  • gemm_a8w8_blockscale (and preshuffle variant): ~7% regression recovered.
  • gather_kv_b_proj: 12-15% regression recovered.
  • gemm_a16w8_blockscale (PREQUANT and plain branches).
  • batched_gemm_a8w8_a_per_token_group_prequant: explicit FMA + skip
    split-K range math when NUM_KSPLIT==1 to keep the K loop aligned.

Test: test_gemm_a16w8_blockscale.py now parametrizes prequant={False, True}.
The N=1280 K=8192 gfx950 retune config is in PR #8106

Summary

Use explicit tl.fma for scaled accumulation and pipeline scale loads in blockscale GEMM kernels to recover the Triton 3.9 FP contraction regression. Add prequant=True test coverage for gemm_a16w8_blockscale.

Motivation

Triton 3.9 no longer implicitly fuses multiply-add into FMA instructions. Expressions like acc += tl.dot(a, b) * scale now emit separate mul + add, which costs 7-15% throughput on gfx950 blockscale GEMM kernels compared to Triton 3.8. Using tl.fma(dot_result, scale, acc) restores the fused instruction.

In the FP8 fused kernel (fused_gemm_a8w8_blockscale_a16w16), scale loads also block the A/B prefetch pipeline. Wrapping the K loop with tl.range(num_stages=2) lets the pipeliner issue scale loads one iteration ahead.

Changes

  • fused_gemm_a8w8_blockscale_a16w16.py: pipeline scale loads with tl.range(num_stages=2), compute scale outer product first, use tl.fma for accumulation.
  • gemm_a8w8_blockscale.py (and preshuffle variant): explicit tl.fma for scaled dot accumulation.
  • gemm_a16w8_blockscale.py: explicit tl.fma in both PREQUANT and plain branches.
  • gather_kv_b_proj: explicit tl.fma.
  • batched_gemm_a8w8_a_per_token_group_prequant: explicit tl.fma and skip split-K range math when NUM_KSPLIT==1.
  • test_gemm_a16w8_blockscale.py: parametrize prequant={False, True}.

Performance (if applicable)

fused_gemm_a8w8_blockscale_a16w16 (gfx950, M=4096, N8=512, N16=256, K=7168):

Hardware Workload Triton 3.8 Triton 3.9 before Triton 3.9 after Change vs 3.9 before
gfx950 fp8 path 122.8 us 129.9 us 77.8 us +40% faster
gfx950 both path 131.6 us 141.5 us 120.3 us +15% faster

batched_gemm_a8w8 (gfx950, B=16, N=1280, K=8192, TFLOPS):

Hardware M Triton 3.8 Triton 3.9 before Triton 3.9 after Change vs 3.9 before
gfx950 64 226.8 224.6 243.8 +8.5%
gfx950 128 456.5 441.7 478.5 +8.3%
gfx950 192 619.3 570.2 605.1 +6.1%
gfx950 256 508.6 494.9 518.4 +4.7%

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Config-only and kernel-internal change, no API change.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None

PR Self-Review

Reviewed revision

7cdda42

Behavior and intent

Triton 3.9 drops implicit FP contraction, so scaled dot-product accumulation (acc += dot * scale) runs as two separate instructions. Each affected kernel now uses tl.fma(dot, scale, acc) to emit a single FMA. The fused FP8 kernel additionally pipelines scale loads with tl.range(num_stages=2) so the scale wait does not block A/B prefetch.

Validation and unverified scope

Benchmarked all changed kernels on gfx950 with their existing benchmarks. The fused FP8 kernel is 40% faster than the 3.9 regression and matches 3.8. Batched GEMM is 5-8% faster than both 3.8 and 3.9-before. The N=1280 K=8192 gfx950 retune config was split to separate PR #8106.

PR-specific question

N/A

Changed op tests

Added prequant=True parametrization to test_gemm_a16w8_blockscale.py to cover the PREQUANT branch that received the tl.fma change.

…_blockscale_a16w16

Two changes in the fp8 K loop:

1. Use tl.range(num_stages=2) for the loop. With num_stages on the loop,
   the Triton pipeliner also pipelines loads that do not feed tl.dot.
   The a_scale and b_scale loads are then issued one iteration ahead.
   Before, the wait for the scales also waited for the A/B prefetch.
2. Compute the scale outer product first and use tl.fma for the
   accumulation. Triton 3.9 does not fuse mul and add by default, so
   the old expression gave separate mul and add instructions.

gfx950, M=4096 N8=512 N16=256 K=7168, median of 5 (us):

               3.9 fp8  3.9 both  3.8 fp8  3.8 both
  before        129.9    141.5     122.8    131.6
  after          77.8    120.3      76.9    119.7

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lijinpei-amd
lijinpei-amd requested review from a team, Dewei-Wang-sh and mengfei-jiang and a balanced review from Copilot November 6, 2026 03:44
@github-actions github-actions Bot changed the title [Triton] Pipeline scale loads and use explicit FMA in fused_gemm_a8w8_blockscale_a16w16 [Triton/Gluon] Pipeline scale loads and use explicit FMA in fused_gemm_a8w8_blockscale_a16w16 Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 7544 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@aiter-bot

aiter-bot commented Nov 6, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 7cdda42456d9 · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. What behavior would each changed op test fail on before this PR, and why is that coverage not already provided by an existing canonical test?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — PR-specific question has no substantive answer
  • FAIL — validation answer must name a command, result, or evidence link
  • FAIL — validation answer must explicitly state what remains unverified (or say none with a reason)

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The kernel hard-codes a loop-stage tuning value contrary to the JSON-only rule and multiplies FP16 scales before promotion, which can underflow and incorrectly produce zero.

2 open issues
What changed in this PR

This PR optimizes the FP8 K loop in the fused block-scaled FP8 and 16-bit GEMM kernel.

Changes:

  • Uses a two-stage tl.range loop to pipeline scale loads.
  • Computes the scale outer product first and uses explicit fused multiply-add accumulation.
File Description
aiter/​ops/​triton/​_triton_kernels/​gemm/​fused/​fused_gemm_a8w8_blockscale_a16w16.py Updates FP8 loop pipelining and scaled accumulation.

Review effort: Balanced

…proj

Triton 3.9 disables implicit FP fusion by default (#11270, #12479),
turning every fused multiply-add into separate mul + add instructions.
This causes ~7% regression in gemm_a8w8_blockscale and 12-15% in
gather_kv_b_proj. Replace `accumulator += tl.dot(a, b) * scale` with
explicit `tl.fma(tl.dot(a, b), scale, accumulator)` to restore FMA
codegen without relying on environment variables.

Co-Authored-By: Claude <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 13, 2026 03:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Both GEMM kernels multiply scales before FP32 promotion, causing FP16 underflow that turns valid nonzero outputs into zero; the scale casts need correction and an FP16 regression test is missing.

3 open issues

Review effort: Balanced

… K=8192

Triton 3.9 does not fuse mul and add by default, so
`accumulator += tl.dot(a, b) * scale` in the non-preshuffle
_gemm_a16w8_blockscale_kernel became separate mul + add. Use
tl.fma for both the PREQUANT and the plain branch, as was done for
gemm_a8w8_blockscale. The preshuffle kernel showed no regression and is
unchanged.

The explicit FMA made M=32/64 at N=1280 K=8192 (the default benchmark
shape) 4-6% slower with the DEFAULT config. Add a gfx950
N=1280-K=8192 config that copies DEFAULT.json and only changes
M_LEQ_32 / M_LEQ_64 to NUM_KSPLIT=8, num_warps=4 (80 -> 160 blocks).

gfx950, N=1280 K=8192, kernel time with L2 flushed, vs 3.8 (us):

  M        3.8     3.9 before   3.9 after
  32       19.7    19.5         8.5
  64       19.7    19.8         10.7
  1024     79.8    86.2         78.8
  2048     87.4    94.0         88.8
  16384    489.3   522.8        487.9

On N=7168 K=2048 (DeepSeek shape with its own config) the change is
within +-2% of 3.8 for all M. test_gemm_a16w8_blockscale.py passes on
Triton 3.8.0 (git7cb7b059) and 3.9.0 (gitf1bf9132).

Co-Authored-By: Claude <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 16, 2026 07:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The scale products in both GEMM kernels can underflow in FP16 before FP32 accumulation, incorrectly zeroing small results; both scales need FP32 casts before multiplication.

4 open issues

Review effort: Balanced

… 3.9

Two changes in the K loop path of
_batched_gemm_a8w8_a_per_token_group_prequant_w_per_batched_tensor_quant_kernel:

1. Use tl.fma for `accumulator += tl.dot(a, b) * a_scale`. Triton 3.9
   does not fuse mul and add by default, so the old expression gave
   separate mul and add instructions (24 FMA vs. 60 on 3.8).
2. With NUM_KSPLIT == 1, skip the split-K range math added in ROCm#6727.
   SPLITK_BLOCK_SIZE >= K in that case, so k_span is always K and the
   result does not change. On 3.9 the extra scalar code moved the K loop
   by 20 bytes, so the loop spans 26 instead of 25 64-byte fetch blocks.
   With this change the loop is at the same place as before ROCm#6727.

gfx950, bench default shapes (B=16, N=1280, K=8192), TFLOPS:

  M      3.8.0    3.9 before   3.9 after
  64     226.8    224.6        243.8
  128    456.5    441.7        478.5
  192    619.3    570.2        605.1
  256    508.6    494.9        518.4

All other default shapes are 2.8% to 8.1% faster than 3.8.0 on 3.9.
On 3.8.0 the change is neutral (-0.9% to +0.1%). M=192 is still 2.3%
below 3.8.0; this gap also shows before ROCm#6727 with FP fusion on.

Co-Authored-By: Claude <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 16, 2026 14:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The loop stage count is hardcoded instead of controlled by the required family JSON configs, and an unrelated shape-specific retune violates the one-problem-per-PR rule.

4 open issues

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 17, 2026 09:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The changed PREQUANT arithmetic lacks coverage against an independent activation-quantized reference, and the unrelated shape-specific retune needs to be moved to a separate PR.

5 open issues

Review effort: Balanced

…to separate PR

Move the N=1280 K=8192 gfx950 config to a separate PR to keep one
problem per PR. Add prequant=True parametrization to test_gemm so
the PREQUANT accumulation path with tl.fma has test coverage.

Co-Authored-By: Claude <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 12:48
@mengfei-jiang mengfei-jiang changed the title [Triton/Gluon] Pipeline scale loads and use explicit FMA in fused_gemm_a8w8_blockscale_a16w16 [Triton/Gluon] Explicit tl.fma in blockscale GEMM kernels for Triton 3.9 Nov 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Both GEMM kernels can now underflow FP16 scale products to zero before FP32 accumulation, losing previously nonzero results.

4 open issues
1 resolved since last review

Review effort: Balanced

@mengfei-jiang
mengfei-jiang removed their request for review November 18, 2026 02:44
Copilot AI balanced review requested due to automatic review settings November 18, 2026 05:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Unavailable GPU validation leaves the fused pipeline changes and reassociated FP32 scale products requiring human correctness and base/head latency checks on supported GPUs with Triton 3.8 and 3.9.

4 open issues

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 19, 2026 09:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 20, 2026 12:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

mengfei-jiang added a commit to mengfei-jiang/aiter that referenced this pull request Nov 21, 2026
Add a shape-specific config for N=1280 K=8192 on gfx950. With the
explicit tl.fma change (PR ROCm#7544), M=32/64 at this shape regressed
4-6% with DEFAULT. The new config uses NUM_KSPLIT=8, num_warps=4 for
small M buckets, recovering performance to match Triton 3.8.

gfx950, N=1280 K=8192, kernel time (us):

  M        3.8     3.9+fma+retune
  32       19.7    8.5
  64       19.7    10.7
  1024     79.8    78.8
  2048     87.4    88.8
  16384    489.3   487.9

Co-Authored-By: Claude <[email protected]>

@Dewei-Wang-sh Dewei-Wang-sh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mengfei-jiang
mengfei-jiang merged commit 1223841 into ROCm:main Nov 23, 2026
98 of 100 checks passed
azaidy pushed a commit that referenced this pull request Nov 30, 2026
… config (#8106)

* [Tune] gfx950 gemm_a16w8_blockscale: add N=1280 K=8192 config

Add a shape-specific config for N=1280 K=8192 on gfx950. With the
explicit tl.fma change (PR #7544), M=32/64 at this shape regressed
4-6% with DEFAULT. The new config uses NUM_KSPLIT=8, num_warps=4 for
small M buckets, recovering performance to match Triton 3.8.

gfx950, N=1280 K=8192, kernel time (us):

  M        3.8     3.9+fma+retune
  32       19.7    8.5
  64       19.7    10.7
  1024     79.8    78.8
  2048     87.4    88.8
  16384    489.3   487.9

* [Triton] [Test] Add M=64 shape for N=1280 K=8192 split-K path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants