You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Triton/Gluon] gfx1151 gemm_a16w16: round before the activation to avoid spills - #6676
On gfx1151, gemm_a16w16 now rounds the fp32 accumulator to the 16-bit output type before a fused activation. This removes the epilogue register spills for bf16 and reduces them for fp16.
Motivation
On gfx1151 a fused activation makes gemm_a16w16 much slower: PixArt-XL FF1 (8192 x 4608 x 1152, fp16) gives 21.9 TFLOPS with gelu_tanh and 29.9 without. The cause is register pressure: the any bucket of configs/gfx1151/triton/gemm/gemm_a16w16/DEFAULT.json uses a 128 x 128 tile whose fp32 accumulator needs 128 VGPRs, and the epilogue spills 134 registers.
Changes
The kernel casts the accumulator to the output type before the activation, so it stays in packed registers. An unfused GEMM rounds the same way, so fused now matches unfused.
A new constexpr ROUND_BEFORE_ACT controls the step. The wrapper sets it for gfx1151. The step also needs a 16-bit output and NUM_KSPLIT == 1.
For fp16 the kernel holds the lower bound with tl.where: a cast below -65504 gives -inf, and gelu and silu give a NaN from it. tl.clamp and tl.maximum default to PropagateNan.NONE and would hide a real NaN.
Elsewhere the constexpr is False and Triton drops the step: a compile for gfx1100 and gfx1201 gives 20 AMDGCN kernels identical to main. Forced on, gfx1201 is 1.3% to 3.7% slower, so adding an architecture needs a benchmark first.
Performance (if applicable)
Radeon 8060S (gfx1151, 40 CU), ROCm 7.15, torch 2.13, Triton 3.8.0, layout TN. Median of interleaved rounds with alternating order, 3 for rows 1 and 3 and 6 for row 2; brackets give spread.
Hardware
Workload/configuration
Before
After
Change
Radeon 8060S (gfx1151, 40 CU)
PixArt-XL FF1, 8192 x 4608 x 1152, fp16, gelu_tanh
21.93 TFLOPS (0.3%)
26.05 TFLOPS (0.8%)
1.188x
Radeon 8060S (gfx1151, 40 CU)
SD3.5-Large FF1, 2048 x 9728 x 2432, bf16, gelu_tanh
16.18 TFLOPS (17.6%)
18.53 TFLOPS (23.6%)
1.145x
Radeon 8060S (gfx1151, 40 CU)
PixArt-XL FF1, fp16, no activation (control)
29.89 TFLOPS (1.7%)
29.71 TFLOPS (1.6%)
0.994x
Controls: base against base gives 0.997x on row 1 and 1.019x on row 2; the no-activation row gives 0.994x, as both trees compile the same kernel. Row 2 is noisy — both sides spread well over the 5% bar, and the instability does not sort by side. Its median was measured twice in separate sessions, giving 1.139x and 1.145x, so the ratio holds where the absolute values move.
Spills
Shape
dtype
Before
After
8192 x 4608 x 1152
fp16
134
112
2048 x 9728 x 2432
fp16
134
112
8192 x 4608 x 1152
bf16
135
0
2048 x 9728 x 2432
bf16
135
0
This sorts by dtype, not shape. The cast alone reaches 0 on fp16 too: removing only the tl.where bound gives 254 VGPRs and 0 spills, against 256 and 112 as shipped. So the fp16 bound costs the whole saving. bf16 keeps the same bound and still reaches 0, unexplained here.
Testing
Unit tests added or updated
Performance benchmarks run
Tested on MI250X
Tested on MI300X
Documentation
No documentation change is needed: the public API and numerical contract do not change.
On gfx1151, with a 16-bit output and NUM_KSPLIT == 1, the activation now gets a value already rounded to the output type instead of the fp32 accumulator. The spills made fusing slower than a separate activation. Other architectures are unchanged.
Validation and unverified scope
This PR does not change a test. A reviewer asked to remove the two op tests of an earlier revision, so I did the checks below by hand on a Radeon 8060S (gfx1151, 40 CU), ROCm 7.15, torch 2.13, Triton 3.8.0. The kernel and wrapper files of this revision are byte-identical to the revision that I tested.
pytest op_tests/triton_tests/gemm/basic/test_gemm_a16w16.py -q --tb=line on main and on this PR: 517 failed, 757 passed on main and 517 failed, 769 passed on the PR, 2560 skipped on both. The failed test IDs are the same on both sides. All 517 failures raise Required config file doesn't exist for gfx1151: a missing tuned config, not this PR.
The removed tests, run on this kernel: 12 passed. They force the accumulator to -98304 and +98304 for fp16 and bf16 with gelu, gelu_tanh and silu. fp16 below the range gives 0.0, fp16 above gives inf and bf16 keeps 98304.0. A NaN input stays NaN in the output.
Spills from the AMDGCN, main against this PR: fp16 gelu_tanh 136 to 40 VGPR spills (plus 13 SGPR spills), bf16 gelu_tanh 136 to 114.
With ROUND_BEFORE_ACT=False, the gfx1151 AMDGCN of 8 cases is the same as main, except for debug information.
Caveat: the --shape path of bench_gemm_a16w16.py does not forward --activation, so it times use_activation_0. Both trees were patched identically to forward it, and the kernel name was checked every run. That bug is on main, not fixed here.
Unverified: the gfx1201 figure and the AMDGCN comparison for gfx1100 and gfx1201 were not repeated here. MI250X and MI300X were not used: the step is off there. CI does not run the new branch, because CI has no gfx1151 runner.
PR-specific question
Before this PR the new tests cannot run, because ROUND_BEFORE_ACT does not exist. The canonical test_gemm_a16_w16_activation uses random data and a loose tolerance, so its accumulator never leaves the fp16 range.
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 6676 --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.
klin-amd
changed the title
[Triton] gemm_a16w16: round to the output type before the activation (GELU 19-34% faster on gfx1151)
[Triton] gemm_a16w16: on gfx1151, round to the output type before the activation (GELU up to 36% faster)
Oct 20, 2026
menglcai-amd
changed the title
[Triton] gemm_a16w16: on gfx1151, round to the output type before the activation (GELU up to 36% faster)
[Triton/Gluon] gfx1151 gemm_a16w16: round before the activation to avoid spills
Oct 22, 2026
This three-sentence docstring exceeds the Triton documentation limit of two sentences. Shorten it to state the fp16 overflow cases and the finite bf16 case checked by this test.
Hi @omuhamma — this PR went stale, so I rebased it onto current main. The rebase dismissed your approval — could you please take another look when you get a chance? Thank you.
The only code difference from the version you approved is the conflict fix in the kernel signature: main's #5505 added NUM_XCDS next to this PR's ROUND_BEFORE_ACT, so both now sit together.
The description also carries new measurements taken on this revision, and some of the figures changed.
Hi @omuhamma, thank you for the review! I trimmed the kernel comment at L176-180 and the test comments in 24c3b64, with no code change.
The push dismissed your approval, so could you please take another look when you have time? Thank you!
With activation="gelu" or "gelu_tanh", gemm_a16w16 on gfx1151 ran 19-34%
slower than with this change. The kernel now rounds the fp32 accumulator
to the fp16/bf16 output type before it applies the activation. An unfused
GEMM followed by an activation does the same rounding.
The change applies only to 16-bit outputs with NUM_KSPLIT == 1. Other
paths are not changed.
Co-Authored-By: Claude <[email protected]>
Add the ROUND_BEFORE_ACT constexpr. The wrapper sets it only on gfx1151,
the arch where the change was measured. The original activation path was
benchmarked on gfx942 and gfx950 (#736). With ROUND_BEFORE_ACT=False, the
kernel compiles to the same instructions as before on gfx942, gfx950 and
gfx1100.
Co-Authored-By: Claude <[email protected]>
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.
Thanks @azaidy, I removed the test changes in db57388. The PR now changes only the kernel and the wrapper.
I verified the fp16 bound and NaN propagation on gfx1151 by hand, and the results are in the description.
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.
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.
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.
This branch has not been deployed
No deployments
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
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.
Summary
On gfx1151,
gemm_a16w16now rounds the fp32 accumulator to the 16-bit output type before a fused activation. This removes the epilogue register spills for bf16 and reduces them for fp16.Motivation
On gfx1151 a fused activation makes
gemm_a16w16much slower: PixArt-XL FF1 (8192 x 4608 x 1152, fp16) gives 21.9 TFLOPS withgelu_tanhand 29.9 without. The cause is register pressure: theanybucket ofconfigs/gfx1151/triton/gemm/gemm_a16w16/DEFAULT.jsonuses a 128 x 128 tile whose fp32 accumulator needs 128 VGPRs, and the epilogue spills 134 registers.Changes
ROUND_BEFORE_ACTcontrols the step. The wrapper sets it for gfx1151. The step also needs a 16-bit output andNUM_KSPLIT == 1.tl.where: a cast below -65504 gives -inf, and gelu and silu give a NaN from it.tl.clampandtl.maximumdefault toPropagateNan.NONEand would hide a real NaN.Falseand Triton drops the step: a compile for gfx1100 and gfx1201 gives 20 AMDGCN kernels identical tomain. Forced on, gfx1201 is 1.3% to 3.7% slower, so adding an architecture needs a benchmark first.Performance (if applicable)
Radeon 8060S (gfx1151, 40 CU), ROCm 7.15, torch 2.13, Triton 3.8.0, layout
TN. Median of interleaved rounds with alternating order, 3 for rows 1 and 3 and 6 for row 2; brackets give spread.gelu_tanhgelu_tanhControls: base against base gives 0.997x on row 1 and 1.019x on row 2; the no-activation row gives 0.994x, as both trees compile the same kernel. Row 2 is noisy — both sides spread well over the 5% bar, and the instability does not sort by side. Its median was measured twice in separate sessions, giving 1.139x and 1.145x, so the ratio holds where the absolute values move.
Spills
This sorts by dtype, not shape. The cast alone reaches 0 on fp16 too: removing only the
tl.wherebound gives 254 VGPRs and 0 spills, against 256 and 112 as shipped. So the fp16 bound costs the whole saving. bf16 keeps the same bound and still reaches 0, unexplained here.Testing
Documentation
Dependencies
Breaking Changes
None.
PR Self-Review
Reviewed revision
db57388
Behavior and intent
On gfx1151, with a 16-bit output and
NUM_KSPLIT == 1, the activation now gets a value already rounded to the output type instead of the fp32 accumulator. The spills made fusing slower than a separate activation. Other architectures are unchanged.Validation and unverified scope
This PR does not change a test. A reviewer asked to remove the two op tests of an earlier revision, so I did the checks below by hand on a Radeon 8060S (gfx1151, 40 CU), ROCm 7.15, torch 2.13, Triton 3.8.0. The kernel and wrapper files of this revision are byte-identical to the revision that I tested.
pytest op_tests/triton_tests/gemm/basic/test_gemm_a16w16.py -q --tb=lineonmainand on this PR: 517 failed, 757 passed onmainand 517 failed, 769 passed on the PR, 2560 skipped on both. The failed test IDs are the same on both sides. All 517 failures raiseRequired config file doesn't existfor gfx1151: a missing tuned config, not this PR.gelu,gelu_tanhandsilu. fp16 below the range gives 0.0, fp16 above gives inf and bf16 keeps 98304.0. A NaN input stays NaN in the output.mainagainst this PR: fp16gelu_tanh136 to 40 VGPR spills (plus 13 SGPR spills), bf16gelu_tanh136 to 114.ROUND_BEFORE_ACT=False, the gfx1151 AMDGCN of 8 cases is the same asmain, except for debug information.Caveat: the
--shapepath ofbench_gemm_a16w16.pydoes not forward--activation, so it timesuse_activation_0. Both trees were patched identically to forward it, and the kernel name was checked every run. That bug is onmain, not fixed here.Unverified: the gfx1201 figure and the AMDGCN comparison for gfx1100 and gfx1201 were not repeated here. MI250X and MI300X were not used: the step is off there. CI does not run the new branch, because CI has no gfx1151 runner.
PR-specific question
Before this PR the new tests cannot run, because
ROUND_BEFORE_ACTdoes not exist. The canonicaltest_gemm_a16_w16_activationuses random data and a loose tolerance, so its accumulator never leaves the fp16 range.Changed op tests
None.