Repository navigation
[Triton/Gluon] Fix the hardcoded die and CU counts in the Triton kernels - #5505
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
PR title tags & labels: |
6589da6 to
79b189c
Compare
bc66791 to
47d4b6c
Compare
NOT READY FOR HUMAN REVIEWPR Self-ReviewRevision 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
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
There was a problem hiding this comment.
🟡 Changes recommended
Explicit grid sizes are incorrectly capped, and the preshuffle kernel still assumes eight XCDs instead of using the queried count, leaving incorrect behavior on four-die devices.
2 open issues
What changed in this PR
This PR updates AITER’s Triton/Gluon kernels to use device die and compute-unit counts instead of fixed hardware assumptions. It is the Triton/Gluon part of the backend-specific series.
Changes:
- Pass device die counts through GEMM, MoE, and attention launch paths.
- Scale persistent grids and attention launch budgets by compute-unit count, with opt-in device sizing for collectives.
- Reject incomplete MLA batch groups and align the existing MLA test with device-based sizing.
| File | Description |
|---|---|
op_tests/test_mla.py |
Match MLA split expectations to device counts. |
aiter/ops/triton/utils/device_info.py |
Avoid stale CU overrides; cache torch queries per device. |
aiter/ops/triton/moe/moe_op_gemm_a8w8.py |
Query die count for MoE swizzling. |
aiter/ops/triton/moe/moe_op_gemm_a8w8_blockscale.py |
Query die count for blockscale MoE. |
aiter/ops/triton/moe/moe_op_gemm_a8w4.py |
Query die count for Triton MoE. |
aiter/ops/triton/moe/moe_op_gemm_a16w4.py |
Query die count across Triton/Gluon MoE paths. |
aiter/ops/triton/gluon/mla_gluon.py |
Scale split budgets and check batch divisibility. |
aiter/ops/triton/gemm/grouped/gmm.py |
Cap automatic grids and pass die counts. |
aiter/ops/triton/gemm/fused/fused_gemm_afp4wfp4_split_cat.py |
Pass die count to split-cat kernels. |
aiter/ops/triton/gemm/fused/fused_gemm_afp4wfp4_mul_add.py |
Pass die count to mul-add kernels. |
aiter/ops/triton/gemm/fused/fused_gemm_afp4wfp4_a16w16.py |
Pass die count to mixed-precision kernels. |
aiter/ops/triton/gemm/fused/fused_gemm_a16w16_quant_x.py |
Pass die count to fused quantization GEMM. |
aiter/ops/triton/gemm/basic/gemm_afp8wfp8.py |
Pass die count to FP8 GEMM launches. |
aiter/ops/triton/gemm/basic/gemm_afp4wfp4.py |
Pass die count to FP4 GEMM variants. |
aiter/ops/triton/gemm/basic/gemm_a8w8.py |
Pass die count to the standard GEMM kernel. |
aiter/ops/triton/gemm/basic/gemm_a16w16.py |
Pass die count to standard and persistent kernels. |
aiter/ops/triton/gemm/basic/gemm_a16w16_atomic.py |
Pass die count to atomic GEMM. |
aiter/ops/triton/comms/reduce_scatter.py |
Allow device-sized grids through num_sms=None. |
aiter/ops/triton/comms/all_gather.py |
Allow device-sized grids through num_sms=None. |
aiter/ops/triton/attention/pod_attention.py |
Pass the launch CU count to the kernel. |
aiter/ops/triton/attention/pa_decode_sparse.py |
Scale workgroup budgets by CU count. |
aiter/ops/triton/attention/mla_decode_rope.py |
Pass die count to both attention stages. |
aiter/ops/triton/_triton_kernels/gemm/grouped/gmm.py |
Thread die count through grouped tile mapping. |
aiter/ops/triton/_triton_kernels/gemm/fused/fused_gemm_afp4wfp4_split_cat.py |
Parameterize split-cat remapping. |
aiter/ops/triton/_triton_kernels/gemm/fused/fused_gemm_afp4wfp4_mul_add.py |
Parameterize mul-add remapping. |
aiter/ops/triton/_triton_kernels/gemm/fused/fused_gemm_afp4wfp4_a16w16.py |
Parameterize mixed-precision remapping. |
aiter/ops/triton/_triton_kernels/gemm/fused/fused_gemm_a16w16_quant_x.py |
Parameterize GEMM-branch remapping. |
aiter/ops/triton/_triton_kernels/gemm/basic/gemm_afp8wfp8.py |
Use supplied die counts in FP8 remapping. |
aiter/ops/triton/_triton_kernels/gemm/basic/gemm_afp4wfp4.py |
Use supplied die counts in FP4 remapping. |
aiter/ops/triton/_triton_kernels/gemm/basic/gemm_a8w8.py |
Parameterize standard GEMM remapping. |
aiter/ops/triton/_triton_kernels/gemm/basic/gemm_a16w16.py |
Parameterize standard GEMM remapping. |
aiter/ops/triton/_triton_kernels/gemm/basic/gemm_a16w16_persistent.py |
Parameterize persistent tile remapping. |
aiter/ops/triton/_triton_kernels/gemm/basic/gemm_a16w16_atomic.py |
Parameterize atomic GEMM remapping. |
aiter/ops/triton/_triton_kernels/flash_attn_triton_amd/utils.py |
Require an explicit remapping die count. |
aiter/ops/triton/_triton_kernels/flash_attn_triton_amd/fwd_prefill.py |
Query die count for non-RDNA prefill. |
aiter/ops/triton/_triton_kernels/flash_attn_triton_amd/bwd.py |
Query die count for non-RDNA backward attention. |
aiter/ops/triton/_triton_kernels/common/pid_preprocessing.py |
Require explicit counts in selected mapping helpers. |
aiter/ops/triton/_triton_kernels/attention/pod_attention.py |
Replace fixed program-ID folding with CU count. |
aiter/ops/triton/_triton_kernels/attention/mla_decode_rope.py |
Use supplied die counts in both stages. |
aiter/ops/triton/_gluon_kernels/gfx950/gemm/basic/gemm_afp4wfp4.py |
Parameterize Gluon FP4 remapping. |
aiter/ops/triton/_gluon_kernels/gfx1250/gemm/basic/gemm_a16w16_persistent.py |
Parameterize both persistent Gluon variants. |
Review effort: Balanced
- Takes the XCD count from the device in the Triton and Gluon kernels that remapped work over a fixed eight dies, through device_info.get_num_xcds. - Sizes grids and workgroup budgets from the device's CU count where they assumed a full-size part. - Remembers a failed chip_info CU lookup per CU_NUM value, so get_num_sms falls back to torch without searching for rocminfo on every call.
6c267be to
cbe1d19
Compare
|
I undid the PR stack, based each branch on main as one commit, and force-pushed. They don't depend on each other, so they can merge in any order. |
… = 32 after #5505 #5505 changed the tile remap of _gemm_a8w8_preshuffle_kernel from a hardcoded NUM_XCDS=8 to the device's XCD count (1 on gfx1150). The first values all had GROUP_SIZE_M 1 and became 1.15x-2.1x slower at M = 256 and M >= 1024. The re-search adds GROUP_SIZE_M 8; M_LEQ_8/16/32 keep the first values (re-search within 1%). Co-Authored-By: Claude <[email protected]> Signed-off-by: Lin, KuanTing <[email protected]>
#5505 #5505 replaced the hardcoded NUM_XCDS=8 in the tile remap with the device's XCD count (1 on gfx1201); the GROUP_SIZE_M 1 entries became much slower on wide N. Re-picked on 34 shapes: geomean of time / fastest 1.428 -> 1.034 (M_LEQ_1024) and 1.142 -> 1.034 (any). Co-Authored-By: Claude <[email protected]> Signed-off-by: Lin, KuanTing <[email protected]>
#5505 #5505 replaced the hardcoded NUM_XCDS=8 in the tile remap with the device's XCD count (1 on gfx1201); the GROUP_SIZE_M 1 entries became much slower on wide N. Re-picked on 34 shapes: geomean of time / fastest 1.428 -> 1.034 (M_LEQ_1024) and 1.142 -> 1.034 (any). Co-Authored-By: Claude <[email protected]> Signed-off-by: Lin, KuanTing <[email protected]>
…5505 The first shape files were tuned before #5505 changed the tile remap. Fresh tuner run on the current kernel; the large-M buckets re-timed with and without gelu / gelu_tanh / silu (48 of 54 changed). Co-Authored-By: Claude <[email protected]> Signed-off-by: Lin, KuanTing <[email protected]>
… = 32 after #5505 #5505 changed the tile remap of _gemm_a8w8_preshuffle_kernel from a hardcoded NUM_XCDS=8 to the device's XCD count (1 on gfx1150). The first values all had GROUP_SIZE_M 1 and became 1.15x-2.1x slower at M = 256 and M >= 1024. The re-search adds GROUP_SIZE_M 8; M_LEQ_8/16/32 keep the first values (re-search within 1%). Co-Authored-By: Claude <[email protected]> Signed-off-by: Lin, KuanTing <[email protected]>
… = 32 after #5505 #5505 changed the tile remap of _gemm_a8w8_preshuffle_kernel from a hardcoded NUM_XCDS=8 to the device's XCD count (1 on gfx1150). The first values all had GROUP_SIZE_M 1 and became 1.15x-2.1x slower at M = 256 and M >= 1024. The re-search adds GROUP_SIZE_M 8; M_LEQ_8/16/32 keep the first values (re-search within 1%). Co-Authored-By: Claude <[email protected]> Signed-off-by: Lin, KuanTing <[email protected]>
Resolve the two conflicts in aiter/ops/triton/moe/moe_op_gemm_a16w4.py: - _GLUON_SUPPORTED_ARCHS keeps gfx1250-strict (ROCm#6767) and adds gfx942. - the launch block keeps the gfx942 Gluon branch first, then the gfx1250/gfx1250-strict branch from main. Also follow ROCm#5505 in get_kernel_config_gluon_gfx942: num_xcds comes from get_num_xcds() instead of the hardcoded 8. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nt8) (#7282) * [Triton] gfx1150: add gemm_a8w8_preshuffled configs gfx1150 had no gemm_a8w8_preshuffled config, so the wrapper failed. Add DEFAULT.json and the N=2112 K=7168 specialized file (as on gfx950), from a search on gfx1150 (Radeon 890M). int8 W8A8; 1.35x faster than the gfx1151 value used on gfx1150, 1.47x-4.03x faster than bf16. * [Triton] gfx1150 gemm_a8w8_preshuffled: re-search the buckets above M = 32 after #5505 #5505 changed the tile remap of _gemm_a8w8_preshuffle_kernel from a hardcoded NUM_XCDS=8 to the device's XCD count (1 on gfx1150). The first values all had GROUP_SIZE_M 1 and became 1.15x-2.1x slower at M = 256 and M >= 1024. The re-search adds GROUP_SIZE_M 8; M_LEQ_8/16/32 keep the first values (re-search within 1%). Co-authored-by: menglcai <[email protected]>
#5505 #5505 replaced the hardcoded NUM_XCDS=8 in the tile remap with the device's XCD count (1 on gfx1201); the GROUP_SIZE_M 1 entries became much slower on wide N. Re-picked on 34 shapes: geomean of time / fastest 1.428 -> 1.034 (M_LEQ_1024) and 1.142 -> 1.034 (any). Signed-off-by: Lin, KuanTing <[email protected]>
#5505 #5505 replaced the hardcoded NUM_XCDS=8 in the tile remap with the device's XCD count (1 on gfx1201); the GROUP_SIZE_M 1 entries became much slower on wide N. Re-picked on 34 shapes: geomean of time / fastest 1.428 -> 1.034 (M_LEQ_1024) and 1.142 -> 1.034 (any). Signed-off-by: Lin, KuanTing <[email protected]>
…5505 The first shape files were tuned before #5505 changed the tile remap. Fresh tuner run on the current kernel; the large-M buckets re-timed with and without gelu / gelu_tanh / silu (48 of 54 changed). Signed-off-by: Lin, KuanTing <[email protected]>
…AULT.json re-pick 18 GEMM-A16W16-N=<N>-K=<K>.json files from the official tuner on gfx1151, with the large-M buckets re-timed with and without fused activations, and the DEFAULT.json buckets above M = 64 re-picked: #6671 was tuned before #5505 changed the tile remap, and its GROUP_SIZE_M 1 entries are now much slower on wide N. Signed-off-by: Lin, KuanTing <[email protected]>

Takes the die count and the launch budgets from the running device instead of assuming eight dies and one part's CU count.
Second of four, one per backend: FlyDSL (#5504), this one, opus (#5848), HIP (#6877).
Motivation
The program-id remap assumed eight dies and several launch budgets were written against 256 or 304 units. Both are already wrong on MI308X, which is gfx942 with 80 CUs and four dies, and wrong again on MI350P, gfx950 with 128 CUs and four dies.
Technical Details
None. That path needs several GPUs and the Iris module, so it ships as opt-in rather than as an unmeasured change.batch_size % 64check already rules such batches out, so the new check matters on six-die parts (MI300A).pod_attentionchange is correct on inspection but unexercised: that module does not import, here or on main, for two unrelated reasons that predate this branch.Testing
test_gemm_a8w8.pywith the counts forced to four and 128 gives 1089 passed and 4 skipped, identical to the unpatched baseline. GEMM at die counts of one, three, four, eight and sixteen stays at bf16 noise, including a shape the count does not divide. The GMM variants match the torch reference at every combination.Measured before the branch was updated with main and not re-run since; the code they cover is unchanged.
PR Self-Review
Reviewed revision
24bd906
Behavior and intent
Triton kernels take the die count and launch budgets from the device instead of assuming 8 dies and 256 or 304 CUs, which is wrong on MI308X and MI350P.
Validation and unverified scope
On MI350P (gfx950, 128 CUs, 4 XCDs, ROCm 7.2.3), the Gluon MLA decode case of
op_tests/test_mla.pypasses onmain, this branch and the full stack, with timings within noise. At 128 CUs it now uses fewer KV splits for three of the six cases.Unverified on MI350P:
op_tests/test_gemm_a8w8.pyandop_tests/triton_tests/, which passed earlier with the counts forced to 4 dies and 128 CUs; and the opt-in collectives path.PR-specific question
op_tests/test_mla.pyhardcoded 8 dies and 256 CUs, so on a 4-die part it would predict a different split count than the wrapper launches. It now reads the same device counts as the wrapper, updating the existing test rather than adding one.Changed op tests
op_tests/test_mla.py: the Gluon MLA decode case reads the device's die and CU counts, as the wrapper does. It updates the existing test, so nothing is duplicated.