Skip to content

[Triton/Gluon] [JIT] [Bugfix] add support for MI300A and fix XCD count - #6327

Merged
azaidy merged 1 commit into
ROCm:mainfrom
aurianer:mi300a_xcd_count
Oct 19, 2026
Merged

azaidy merged 1 commit into
ROCm:mainfrom
aurianer:mi300a_xcd_count

Conversation

@aurianer

@aurianer aurianer commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Motivation

The tritons kernels are hardcoding the XCD count to 8. On our MI300A (arch=gfx942) we have 6. The number of compute unit we have on MI300A was also missing, I've added it. I also updated the XCD count for MI308X.

Technical Details

  • get_num_xcds() hardcoded 8, wrong on the MI300A (6 XCDs and 228 compute units) and MI308X (4 XCDs, 80 compute units)
  • the count is now looked up from the _XCDS_BY_GFX_AND_CU_NUM, 8 stays the fallback. MI300X and MI350X are unchanged. The one additional line to specify the compute units of MI300A in chip_info.py and a unit test under op_tests/triton_tests/.

Test Plan

Test that the correct XCDs number is returned for MI300A (I cannot test the other hardware) and verify that the tests pass:

git clone -b mi300a_xcd_count [email protected]:aurianer/aiter.git /iopsstor/scratch/cscs/aurianer/aiter-xcd
$  srun -N1 -n1 -p mi300  -t 00:10:00 bash -c '
cd /scratch/aiter-xcd && export PYTHONPATH=/scratch/aiter-xcd
python3 -m pytest -q op_tests/triton_tests/test_device_info.py
python3 -c "from aiter.ops.triton.utils.device_info import get_num_xcds; print(get_num_xcds())"'

Test Result

6 passed in 26.92s
[aiter] import [module_aiter_core] under <path>/.aiter-a68888a/jit/module_aiter_core.so
6

Submission Checklist

@aurianer
aurianer requested a review from a team October 9, 2026 14:15
@github-actions

github-actions Bot commented Oct 9, 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: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: 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 6327 --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.

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 test location violates repository structure, and the new legacy mapping lacks direct coverage.

4 open findings
What changed in this PR

Updates Triton/Gluon device detection to return hardware-specific XCD counts.

Changes:

  • Maps architecture/CU combinations to XCD counts.
  • Adds the 228-CU legacy gfx942 mapping.
  • Adds device-info unit tests.
File Description
aiter/​ops/​triton/​utils/​device_info.py Adds XCD lookup logic.
aiter/​jit/​utils/​chip_info.py Adds the 228-CU legacy mapping.
op_tests/​triton_tests/​test_device_info.py Tests XCD selection and fallback.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread aiter/jit/utils/chip_info.py Resolved
Comment thread aiter/ops/triton/utils/device_info.py Resolved
@azaidy
azaidy requested a review from Boss2002n October 9, 2026 19:40
@aurianer
aurianer force-pushed the mi300a_xcd_count branch 2 times, most recently from f3e3190 to bf4e33b Compare October 12, 2026 08:56
@aurianer

Copy link
Copy Markdown
Contributor Author

I've also rebased, let me know if I should change anything

@zufayu
zufayu requested review from a team and Boss2002n October 14, 2026 01:29

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 six-XCD count exposes a spatial-attention mapping defect that leaves output tiles unwritten.

1 open finding
4 resolved since last review

🧠 Review effort: Balanced

Comment thread aiter/ops/triton/utils/device_info.py Resolved

@rahulbatra85 rahulbatra85 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!

@azaidy
azaidy merged commit 16979d7 into ROCm:main Oct 19, 2026
Liang-jianhao97 added a commit that referenced this pull request Oct 26, 2026
get_num_xcds (#6327) now imports aiter.jit.utils.chip_info on every call.
Under AITER_TRITON_ONLY=1, which bench_flash_kda.py sets, that import fails
and is retried each time, about 2 ms. Pass A and pass C call it on every
launch, so after the merge of main bench_flash_kda.py read 2-4 ms for every
FlashKDA call. Cache the count, as build_layouts already is.
azaidy pushed a commit that referenced this pull request Oct 26, 2026
* [Triton/Gluon] perf(flash-kda): gfx1250 Gluon K1 and K2

Port the Gluon FlashKDA kernels to gfx1250, in the gfx950 layout, and route
flash_kda_fwd to them there.

- _gluon_kernels/gfx1250/kimi_delta_attn/flash_kda_k1.py: the prepare kernel.
  q, k and g arrive by one fused TDM load, and the [C, C] products and the
  (I - L)^-1 solve run on wave32 WMMA. Same workspace contract and the same
  gluon_k1_prepare entry point as the gfx950 K1.
- _gluon_kernels/gfx1250/kimi_delta_attn/flash_kda_k2.py: the chunk walk.
  Pass A computes b_seg and A_seg in one launch; pass C computes the outputs
  and the final state, paged state_cache included. The state stays transposed
  in a WMMA accumulator, the workspace tiles and v arrive by fused TDM loads
  into a double buffer, and the outputs leave LDS by async copy.
- flash_kda.py: on gfx1250, K1 and both K2 passes go to Gluon. Routing on
  gfx950 is unchanged; pass C stays on Triton there. _k2_gluon_schedule now
  takes the pass name, so each pass has its own wide and narrow entries.
- configs/gfx1250/gluon/attention/chunk_delta_attn/DEFAULT.json: BW 128 and
  BW 64 at four warps. The wide floors were calibrated on the bench_chunk_kda
  and bench_flash_kda shapes: 2 blocks per CU for pass A, 0.3 for pass C.
- test_flash_kda.py: the schedule and routing tests also cover pass C on
  archs where it has a Gluon kernel, and import that arch's K2 module.

Tests on gfx1250: op_tests/triton_tests/kimi_delta_attn/test_flash_kda.py,
76 passed, 1 skipped (this device has no K2 autotune candidates to switch
between).

Performance on gfx1250 (one GPU, 256 CUs), upstream 428af1c -> this commit,
both runs with the same environment.

bench_chunk_kda.py, the FlashKDA line ("triton"), us:

   H  B     T        do_bench             cudagraph
  24  1  1024   178.8 ->  62.3 2.87x   176.9 ->  37.1 4.77x
  24  1  4096   486.0 ->  99.7 4.87x   487.9 ->  97.8 4.99x
  24  3  1024   190.8 ->  67.0 2.85x   184.8 ->  54.6 3.38x
  24  3  4096   448.1 -> 170.1 2.63x   449.7 -> 168.7 2.67x
  24  8  1024   295.1 -> 102.7 2.87x   302.2 -> 101.1 2.99x
  24  8  4096   925.2 -> 340.5 2.72x   924.1 -> 343.2 2.69x
  12  1  1024   171.4 ->  61.9 2.77x   199.4 ->  34.6 5.76x
  12  1  4096   410.8 -> 106.0 3.87x   398.5 ->  98.7 4.04x
  12  3  1024   220.4 ->  65.9 3.34x   170.5 ->  40.9 4.17x
  12  3  4096   561.2 -> 126.1 4.45x   546.9 -> 134.1 4.08x
  12  8  1024   207.6 ->  69.8 2.97x   205.6 ->  65.1 3.16x
  12  8  4096   542.5 -> 205.7 2.64x   534.6 -> 207.3 2.58x

The FlashKDA line is now faster than the chunk_kda Gluon line ("gluon") on
every shape in both timings. Upstream, it was slower on every shape.

bench_flash_kda.py, ms:

  B      T   H   upstream   this    speedup
  1    256  12    0.0479   0.0417   1.15x
  1    512  12    0.0753   0.0396   1.90x
  1   1664  12    0.1119   0.0418   2.68x
  1   2048  12    0.3429   0.0700   4.90x
  1   8192  12    0.4866   0.1050   4.63x
  1  16384  12    0.6712   0.1489   4.51x
  1  16384  64    2.0335   0.5721   3.55x
  1  16384  96    1.7003   0.7673   2.22x
  1   8192  32    0.7352   0.1615   4.55x
  1   8192  64    1.2016   0.3074   3.91x
  2   2664  12    0.3962   0.0839   4.72x
  4   4096  16    0.7366   0.1587   4.64x
  8   2048  16    0.3784   0.1278   2.96x

Tests on gfx1250: test_flash_kda.py and test_fast_launch.py, 107 passed,
2 skipped; test_chunk_delta_attn_fwd.py, 39 passed;

* [Triton/Gluon] refactor(flash-kda): shared helpers, launch config in JSON

Address the review of the gfx1250 Gluon FlashKDA kernels: share the Gluon
helpers, and read the K1 and K2 launch values from the published config.

- _gluon_kernels/common/utils.py: sigmoid_log2, fast_sigmoid, sum_combine
  and l2norm, in the form that the FlashKDA kernels used. The sigmoid that
  is already in this file uses tanh and gives different results.
- _gluon_kernels/gfx1250/kimi_delta_attn/flash_kda_k1.py: import these
  helpers and call gl.exp2 directly. gluon_k1_prepare takes num_warps and
  waves_per_eu; the kernel still requires four warps.
- _gluon_kernels/gfx1250/kimi_delta_attn/flash_kda_k2.py: import
  fast_sigmoid. Both launchers take CPL, the number of chunks in one TDM
  load, in place of the module constant _CPL.
- flash_kda.py: _k1_gluon_schedule reads the k1_prepare_gluon entry, and
  _k2_gluon_schedule returns the whole entry, so pass A and pass C also get
  CPL. The fallbacks do not depend on the arch.
- configs/gfx1250/gluon/attention/chunk_delta_attn/DEFAULT.json: a
  k1_prepare_gluon entry with 4 warps and waves_per_eu 5, and CPL 2 in the
  four K2 entries. These are the values that were in Python.
- test_flash_kda.py: read BW and num_warps from the returned config.

The outputs, the final states and the ISA of all K1 and K2 variants do not
change.

Tests on gfx1250: test_flash_kda.py and test_fast_launch.py, 108 passed,
1 skipped (this device has no K2 autotune candidates to switch between).

* [Triton] perf(flash-kda): prefetch pass B's loads on gfx1250

Pass B, the cross-segment scan, is a chain of dependent updates, and
_flash_kda_seg_scan_kernel loads b_seg in the update that adds it: two
exposed memory round trips per update. _flash_kda_seg_scan_prefetch_kernel
does two updates per loop trip and loads the next trip's b_seg, two to three
updates ahead, while the software pipeliner prefetches A_seg. It also skips
the last segment's update, which nothing reads.

It is pass B on gfx1250 (AITER_FDA_SCAN_PREFETCH=0 goes back to the old
kernel) at BV=16, 4 warps and the default 2 stages; other archs keep the old
kernel and its schedule.

On H=12 forwards of 1 to 3 sequences, 13 to 20 segments deep, pass B is
1.8-2.5x faster and the forward's kernel time 6-17% lower. h_in matches the
old kernel to 2.4e-7 with dense, no and paged initial states.

* [Triton] bench(flash-kda): add the Kimi-K3 cases to bench_flash_kda.py

Time FlashKDA on the calls that Kimi-K3 makes, and chunk_kda on the same
inputs.

- --k3-tp8: the 26 prefill forwards of Kimi-K3 TP8+DCP8 rank 0 (H=12), in
  order. Each forward is one varlen call. A sequence that continues a cached
  prefix reads its initial state from a paged state cache; the others start
  from zero. The table and the CSV gain a seqlens column.
- --qkv-bands: pass q, k and v as views of one fused [B, T, 3 * H * 128]
  projection, as the model does, instead of three packed tensors.
- --impl chunk_kda: time the Gluon chunk_kda on the inputs that FlashKDA
  gets; a batch becomes one varlen call. --seg-sweep needs --impl flash_kda.
- --shape can repeat. It and --k3-tp8 exclude each other.

The default sweep and its inputs do not change.

Run on gfx1250 with --k3-tp8, --k3-tp8 --impl chunk_kda, --qkv-bands with
repeated --shape, and the default sweep.

* [Triton/Gluon] perf(flash-kda): look up the XCD count once in K2

get_num_xcds (#6327) now imports aiter.jit.utils.chip_info on every call.
Under AITER_TRITON_ONLY=1, which bench_flash_kda.py sets, that import fails
and is retried each time, about 2 ms. Pass A and pass C call it on every
launch, so after the merge of main bench_flash_kda.py read 2-4 ms for every
FlashKDA call. Cache the count, as build_layouts already is.

---------

Co-authored-by: jianlian <[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.

6 participants