Skip to content

[Triton/Gluon] Fix the hardcoded die and CU counts in the Triton kernels - #5505

Merged
RElbers merged 1 commit into
mainfrom
relbers/gfx950_triton_xcd_count
Nov 5, 2026
Merged

RElbers merged 1 commit into
mainfrom
relbers/gfx950_triton_xcd_count

Conversation

@RElbers

@RElbers RElbers commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

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

  • The remap helper keeps its default of eight. Thirteen call sites invoke it as a bare statement and discard the result, so the swizzle is already inert there; removing the default would make those compile errors, which is a larger change.
  • The two collectives keep 256 as their declared default and take the device count only when a caller passes None. That path needs several GPUs and the Iris module, so it ships as opt-in rather than as an unmeasured change.
  • An MLA batch the die count cannot divide is now refused. The batch index strides by the count, so such a batch previously lost its tail with nothing reported. On four- and eight-die parts the existing batch_size % 64 check already rules such batches out, so the new check matters on six-die parts (MI300A).
  • The pod_attention change 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.py with 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.py passes on main, 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.py and op_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.py hardcoded 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.

@github-actions

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; main branch always runs both MI35X and MI300X
multigpu 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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 5505 --add-label <label>

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 opt this PR out.

@aiter-bot

aiter-bot commented Oct 29, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision cbe1d192eb62 · 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 — Reviewed revision must contain at least the first 7 characters of the current head SHA

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

@RElbers
RElbers marked this pull request as ready for review October 29, 2026 22:48
@RElbers
RElbers requested a review from a team October 29, 2026 22:48
@github-actions github-actions Bot changed the title Fix the hardcoded die and CU counts in the Triton kernels [Triton/Gluon] Fix the hardcoded die and CU counts in the Triton kernels Oct 29, 2026
@zufayu
zufayu requested review from a team and vgokhale October 30, 2026 01:29
@zufayu
zufayu removed the request for review from vgokhale October 30, 2026 01:54
@Boss2002n
Boss2002n requested a balanced review from Copilot October 30, 2026 02:49

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

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

Comment thread aiter/ops/triton/gemm/grouped/gmm.py Resolved
Copilot AI balanced review requested due to automatic review settings November 2, 2026 10:13

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

When rocminfo is unavailable, repeated get_cu_num() probes and executable searches bypass the cached fallback, adding avoidable work on kernel-launch paths.

1 open issue
2 resolved since last review

Review effort: Balanced

Comment thread aiter/ops/triton/utils/device_info.py Resolved
Copilot AI balanced review requested due to automatic review settings November 2, 2026 10:28

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

When rocminfo is unavailable, the uncached fallback causes every get_num_sms() call to retry the failed probe, adding repeated process-launch overhead to kernel dispatch.

1 open issue

Review effort: Balanced

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.

- 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.
@RElbers
RElbers removed this pull request from stack #7002 November 5, 2026 15:55
@RElbers
RElbers changed the base branch from relbers/gfx950_flydsl_xcd_count to main November 5, 2026 15:58
@RElbers
RElbers force-pushed the relbers/gfx950_triton_xcd_count branch from 6c267be to cbe1d19 Compare November 5, 2026 15:59
Copilot AI balanced review requested due to automatic review settings November 5, 2026 15:59

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.

@RElbers

RElbers commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

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.

@Boss2002n Boss2002n 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

@RElbers
RElbers merged commit 796ff6a into main Nov 5, 2026
@RElbers
RElbers deleted the relbers/gfx950_triton_xcd_count branch November 5, 2026 20:09
klin-amd added a commit that referenced this pull request Nov 9, 2026
… = 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]>
klin-amd added a commit that referenced this pull request Nov 10, 2026
#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]>
klin-amd added a commit that referenced this pull request Nov 10, 2026
#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]>
klin-amd added a commit that referenced this pull request Nov 10, 2026
…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]>
menglcai-amd pushed a commit that referenced this pull request Nov 10, 2026
… = 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]>
menglcai-amd pushed a commit that referenced this pull request Nov 13, 2026
… = 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]>
ishara0925 pushed a commit to ishara0925/aiter that referenced this pull request Nov 24, 2026
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]>
azaidy pushed a commit that referenced this pull request Nov 24, 2026
…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]>
klin-amd added a commit that referenced this pull request Nov 30, 2026
#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]>
klin-amd added a commit that referenced this pull request Nov 30, 2026
#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]>
klin-amd added a commit that referenced this pull request Nov 30, 2026
…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]>
klin-amd added a commit that referenced this pull request Nov 30, 2026
…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]>
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.

7 participants