Skip to content

[HIP] [OPUS] [JIT] Fix the hardcoded die and CU counts in the opus kernels - #5848

Merged
yzhou103 merged 6 commits into
mainfrom
relbers/gfx950_opus_xcd_count
Nov 16, 2026
Merged

yzhou103 merged 6 commits into
mainfrom
relbers/gfx950_opus_xcd_count

Conversation

@RElbers

@RElbers RElbers commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Passes the build target's die count into the opus GEMM and MoE traits, sizes the persistent GEMM grid for the device's CUs at two workgroups each, and fixes a swizzle tail that drops work at any die count.

The persistent a16w16 GEMM sized its grid for one workgroup per CU with a hard-coded 256 CUs, though the kernel holds two; sizing it from the device's CUs at two per CU makes kid 30 (the heuristic's pick for most shapes above M=128) faster over the 94 tuned opus shapes: 1.17x on geomean on MI350P (at most 1.89x) and 1.09x on MI355X (at most 2.00x). The tuned GEMM and MoE rows keep their timings on MI355X.

Third of four, one per backend: FlyDSL (#5504), Triton (#5505), this one, HIP (#6877).

Motivation

The split-barrier traits already carried a NUM_XCD_ parameter, but codegen never emitted a value, so every instance took the default of eight. On a four-die part both the launcher and the kernel still group tiles for eight dies: the swizzle stays a bijection, but it lays work out for dies the part does not have.

Wiring it up surfaced an older defect. The tail covering a partial last group divides the covered tile count by the group width, while the layout it indexes uses that group's own row extent. When the last row group is shorter than the group width, the tail resumes too early in that group: it recomputes tiles the swizzle already wrote and runs out of workgroups before the group's last tiles, which keep whatever the output buffer held. This predates this branch. On 256-CU gfx950 parts it affects three shipped bf16 tuned rows (N=50016, K=6144) when a batch size between tuned sizes rounds up to them, for example M=2305 using the M=4096 row.

Technical Details

  • NUM_XCD_ moves ahead of the defaulted trait parameters so codegen can reach it positionally. Three of the five traits cannot drop the default, since C++ forbids a non-defaulted parameter after a defaulted one.
  • The count table lands in aiter/jit/utils/build_targets.py, so the opus codegen, the FlyDSL AOT and the HIP helper in [HIP] Fix the hardcoded die count in the HIP kernels #6877 can also use it.
  • The codegen shim catches ImportError only, so a real failure in target resolution surfaces rather than silently falling back to eight.
  • The compact MXFP8 BMM, added on main after this branch started, takes the baked count too: its tile spread and its grid padding both used eight.
  • The swizzle tail no longer has its own arithmetic: the remap applies only below the last full cycle, and the tail workgroups keep their index and go through the same row-group mapping. The remap permutes each full cycle onto itself, so this covers every tile, and the row-group mapping already handles a short last group. The same change is in the a16w16 GEMM pipeline and the two opus MoE stage-2 pipelines.
  • The persistent a16w16 launcher sizes split_m for two workgroups per CU, the residency its __launch_bounds__ declares. It aimed for one per CU with a hard-coded 256 CUs: on a 128-CU part that happened to be two per CU, so reading the device's CU count halved the grid there, and on 256-CU parts the grid was half what the kernel holds.
  • One kernel keeps eight on purpose: the fused split-K tail of the a8w8 MXFP8 wave1 kernel groups tiles by eight so that all splits of a tile run on one die and meet in its L2. That still holds on four dies, since workgroups equal modulo eight are also equal modulo four.

Testing

On an MI355X (eight dies):

  • The swizzle fix takes a launch sweep over the non-persistent a16w16 kernels from 253 wrong results in 3105 launches to zero.
  • test_gfx950_xcd_swizzle_tail_writes_every_tile runs kid 5 on 13x20 tiles into a NaN-filled output. It fails with the tail fix reverted and passes with it.
  • test_opus_a16w16_gemm.py passes (37 passed, 9 skipped), and so does test_gemm_codegen.py.
  • test_moe_2stage.py on the 24 shipped rows with a non-atomic opus a8w4 stage 2: logits_diff at most 0.0005.
  • Codegen is byte-identical to the base wherever the resolved count is eight, apart from the swizzle tail and the persistent launcher's split_m target.

At 59ee9a4, timed against the merge base, run base, head, base on one GPU; speedup is the mean of the two base runs over head:

What Shapes Geomean speedup Range
opus a16w16 tuned rows 94 1.00x 0.94x to 1.03x
opus MoE stage-2 tuned rows 31 1.00x 0.97x to 1.05x

The two GEMM rows at 0.94x match the second base run; their two base runs differ by 10% and 13%. The five tuned rows on a persistent kernel are not among the shapes the occupancy target changes. The MXFP8 BMM device code is identical at eight dies; its timings differ between builds by up to 11% in either direction, and swap sign between two measurements, so they are not attributed to this branch.

The persistent kernels are where the die and CU counts change performance. Persistent kid 30, the heuristic's pick for most shapes above M=128, over the 94 shapes of the tuned opus rows at batch 1, against main:

Geomean speedup Min Max Shapes below 0.95x
MI355X 1.09x 0.99x 2.00x 0
MI350P 1.17x 0.94x 1.89x 1

On MI350P the die count gives the small-M shapes up to 1.89x, and the two-per-CU target the large-N ones up to 1.78x; 3072x4096x1536 (0.94x) and 2268, 5994 and 16644 by 6144 by 6144 (0.96x to 0.97x) remain slightly slower. On MI355X only the occupancy target changes, giving the large-N and large-M shapes 1.1x to 2.0x. Persistent kid 76 refuses most of those shapes and stays within 1.5% on both. The MXFP8 BMM sweep is unchanged on MI350P (all shapes within 1.5%).

Persistent kid 30 on MI355X (µs)
M, N, K main this PR speedup
4096, 50016, 6144 7404.4 3707.9 2.00x
10240, 64640, 4096 14846.2 7470.7 1.99x
2048, 50016, 6144 3741.3 1886.5 1.98x
16384, 50016, 6144 29897.3 15079.8 1.98x
8192, 50016, 6144 14961.9 7547.9 1.98x
1024, 50016, 6144 1893.7 966.2 1.96x
1920, 64640, 4096 2922.1 1514.1 1.93x
1856, 64640, 4096 2893.7 1515.5 1.91x
9072, 6144, 6144 765.0 569.2 1.34x
49932, 1280, 5120 682.7 518.7 1.32x
27972, 6144, 6144 2580.1 1997.1 1.29x
16644, 6144, 6144 1497.3 1168.3 1.28x
15984, 6144, 6144 1164.2 917.3 1.27x
49932, 6144, 6144 3770.8 3008.3 1.25x
49932, 1280, 1280 249.4 199.1 1.25x
5994, 6144, 6144 502.1 404.6 1.24x
27972, 1280, 5120 442.1 357.7 1.24x
16644, 6144, 24576 5930.9 4825.4 1.23x
6993, 6144, 6144 508.2 444.3 1.14x
7992, 6144, 6144 531.0 466.4 1.14x
66576, 3840, 1280 773.2 727.5 1.06x
49932, 3840, 1280 604.3 588.6 1.03x
16384, 512, 7168 145.7 144.3 1.01x
33288, 1280, 1280 143.5 142.2 1.01x
7992, 1280, 5120 114.2 113.5 1.01x
256, 6144, 2048 50.4 50.1 1.01x
256, 6144, 3072 72.1 71.7 1.00x
6144, 1024, 4096 82.5 82.1 1.00x
12288, 512, 4096 83.6 83.2 1.00x
3072, 4096, 1536 55.1 54.9 1.00x
192, 3072, 6144 116.2 115.8 1.00x
66576, 1280, 5120 722.6 720.4 1.00x
3072, 2048, 4096 84.2 83.9 1.00x
10368, 6144, 6144 686.1 684.1 1.00x
12288, 1024, 4096 102.7 102.4 1.00x
23976, 6144, 6144 1439.7 1436.2 1.00x
8192, 1024, 4096 88.3 88.1 1.00x
6144, 2048, 7168 163.1 162.7 1.00x
33288, 6144, 6144 1936.8 1932.8 1.00x
2048, 2048, 6144 123.8 123.5 1.00x
80, 100032, 6144 1368.3 1365.7 1.00x
2268, 6144, 6144 251.3 250.9 1.00x
12288, 2048, 7168 313.7 313.2 1.00x
19980, 6144, 6144 1178.3 1176.8 1.00x
4096, 2048, 1536 43.9 43.8 1.00x
4, 50016, 6144 704.7 703.9 1.00x
256, 50016, 6144 886.2 885.2 1.00x
5184, 6144, 6144 397.6 397.3 1.00x
512, 6144, 3072 71.5 71.5 1.00x
64, 50016, 6144 723.1 722.7 1.00x
14336, 512, 4096 85.3 85.3 1.00x
1024, 2048, 6144 124.2 124.2 1.00x
512, 3072, 6144 125.6 125.5 1.00x
16, 50016, 6144 708.0 707.8 1.00x
16384, 2048, 6144 312.2 312.1 1.00x
320, 50016, 6144 841.3 841.2 1.00x
8, 50016, 6144 705.7 705.6 1.00x
512, 50016, 6144 963.8 963.8 1.00x
2, 50016, 6144 704.7 704.7 1.00x
2048, 3584, 7168 142.2 142.2 1.00x
16384, 512, 5120 112.4 112.4 1.00x
128, 50016, 6144 755.8 755.9 1.00x
192, 50016, 6144 789.6 789.9 1.00x
4096, 2048, 6144 127.4 127.5 1.00x
128, 3072, 6144 108.0 108.1 1.00x
512, 128, 6144 106.3 106.4 1.00x
256, 3072, 6144 129.4 129.6 1.00x
2048, 3072, 6144 127.5 127.6 1.00x
32, 50016, 6144 713.0 714.1 1.00x
8192, 1024, 5120 110.3 110.5 1.00x
1, 50016, 6144 703.8 705.3 1.00x
2048, 4096, 8192 160.8 161.1 1.00x
1024, 3072, 6144 125.8 126.1 1.00x
66576, 6144, 6144 3958.1 3968.2 1.00x
19980, 3840, 1280 231.3 231.9 1.00x
12288, 1024, 7168 161.8 162.3 1.00x
16384, 1024, 5120 139.9 140.3 1.00x
6144, 1024, 7168 137.5 137.9 1.00x
2048, 1024, 5120 106.2 106.5 1.00x
4096, 1024, 5120 105.5 105.9 1.00x
16384, 512, 4096 87.5 87.9 1.00x
12288, 512, 7168 141.1 141.7 1.00x
33288, 1280, 5120 369.7 371.5 1.00x
33288, 3840, 1280 367.9 369.8 0.99x
2048, 4096, 4096 90.2 90.7 0.99x
256, 2048, 6144 128.1 128.9 0.99x
256, 256, 5120 113.3 114.1 0.99x
6144, 2048, 4096 103.5 104.2 0.99x
4096, 2048, 4096 87.8 88.5 0.99x
12288, 2048, 4096 197.1 198.8 0.99x
1024, 6144, 2048 51.5 52.0 0.99x
14336, 512, 7168 142.6 143.9 0.99x
1024, 6144, 3072 72.5 73.3 0.99x
8192, 2048, 6144 162.3 164.5 0.99x
Persistent kid 30 on MI350P (µs)
M, N, K main this PR speedup
256, 6144, 3072 136.8 72.5 1.89x
80, 100032, 6144 2862.2 1520.8 1.88x
256, 6144, 2048 98.8 53.5 1.85x
32, 50016, 6144 1448.0 787.4 1.84x
128, 50016, 6144 1505.2 819.1 1.84x
8, 50016, 6144 1438.0 782.9 1.84x
16, 50016, 6144 1439.2 784.6 1.83x
2, 50016, 6144 1434.7 783.2 1.83x
64, 50016, 6144 1463.0 799.0 1.83x
4, 50016, 6144 1435.4 784.3 1.83x
1, 50016, 6144 1433.0 783.3 1.83x
192, 50016, 6144 1540.2 843.3 1.83x
256, 50016, 6144 1580.8 868.2 1.82x
512, 6144, 3072 134.4 75.3 1.78x
320, 50016, 6144 1491.2 838.5 1.78x
1856, 64640, 4096 5088.8 3018.0 1.69x
1024, 6144, 3072 136.9 81.7 1.68x
1920, 64640, 4096 5085.1 3088.2 1.65x
512, 50016, 6144 1480.6 905.0 1.64x
1024, 6144, 2048 99.3 61.5 1.61x
1024, 50016, 6144 2924.6 1847.8 1.58x
10240, 64640, 4096 25568.4 16214.7 1.58x
4096, 50016, 6144 11776.2 7508.9 1.57x
8192, 50016, 6144 23612.2 15097.7 1.56x
2048, 50016, 6144 5818.2 3726.2 1.56x
16384, 50016, 6144 47229.4 30537.8 1.55x
49932, 1280, 5120 1192.4 1077.4 1.11x
49932, 1280, 1280 396.4 370.8 1.07x
3072, 2048, 4096 100.8 97.0 1.04x
256, 3072, 6144 127.4 124.0 1.03x
8192, 1024, 5120 137.9 134.3 1.03x
15984, 6144, 6144 2152.1 2099.2 1.03x
8192, 1024, 4096 113.8 111.3 1.02x
1024, 3072, 6144 125.4 122.8 1.02x
512, 3072, 6144 126.2 123.6 1.02x
192, 3072, 6144 121.5 119.0 1.02x
256, 2048, 6144 123.3 120.8 1.02x
128, 3072, 6144 117.7 115.4 1.02x
6144, 2048, 4096 195.3 191.9 1.02x
16384, 1024, 5120 275.3 271.2 1.02x
6144, 1024, 7168 156.2 154.0 1.01x
27972, 6144, 6144 4044.3 3988.8 1.01x
16644, 6144, 24576 9530.0 9406.4 1.01x
4096, 1024, 5120 109.2 108.0 1.01x
14336, 512, 4096 106.2 105.2 1.01x
2048, 1024, 5120 103.0 102.2 1.01x
512, 128, 6144 112.7 111.9 1.01x
2048, 2048, 6144 126.3 125.5 1.01x
66576, 1280, 5120 1543.2 1533.7 1.01x
33288, 6144, 6144 4003.8 3980.8 1.01x
2048, 3584, 7168 170.1 169.2 1.01x
16384, 2048, 6144 644.4 641.2 1.00x
14336, 512, 7168 173.9 173.1 1.00x
33288, 1280, 5120 763.2 760.4 1.00x
6144, 2048, 7168 312.6 311.7 1.00x
12288, 1024, 7168 315.6 314.9 1.00x
4096, 2048, 4096 112.5 112.3 1.00x
1024, 2048, 6144 119.8 119.6 1.00x
16384, 512, 7168 189.9 189.6 1.00x
27972, 1280, 5120 707.1 706.0 1.00x
5184, 6144, 6144 700.0 699.2 1.00x
256, 256, 5120 104.7 104.6 1.00x
2048, 4096, 8192 212.4 212.2 1.00x
12288, 512, 7168 159.2 159.1 1.00x
7992, 6144, 6144 971.5 970.9 1.00x
6993, 6144, 6144 897.2 897.0 1.00x
4096, 2048, 1536 58.2 58.2 1.00x
12288, 1024, 4096 191.8 191.9 1.00x
4096, 2048, 6144 155.9 156.2 1.00x
23976, 6144, 6144 2864.9 2871.1 1.00x
7992, 1280, 5120 229.2 229.8 1.00x
16384, 512, 4096 115.2 115.6 1.00x
2048, 3072, 6144 138.1 138.6 1.00x
19980, 3840, 1280 437.9 439.5 1.00x
66576, 6144, 6144 8197.7 8234.2 1.00x
12288, 2048, 7168 542.6 545.2 1.00x
10368, 6144, 6144 1336.6 1343.3 1.00x
16384, 512, 5120 140.4 141.2 0.99x
8192, 2048, 6144 314.5 316.5 0.99x
12288, 512, 4096 98.1 98.8 0.99x
49932, 6144, 6144 6284.6 6335.8 0.99x
2048, 4096, 4096 121.3 122.3 0.99x
33288, 3840, 1280 715.8 721.8 0.99x
19980, 6144, 6144 2381.1 2403.4 0.99x
9072, 6144, 6144 1233.5 1245.5 0.99x
12288, 2048, 4096 326.0 329.9 0.99x
66576, 3840, 1280 1471.2 1490.8 0.99x
6144, 1024, 4096 96.2 97.5 0.99x
33288, 1280, 1280 259.1 264.4 0.98x
16644, 6144, 6144 2368.2 2436.3 0.97x
5994, 6144, 6144 814.1 839.0 0.97x
49932, 3840, 1280 1103.2 1139.3 0.97x
2268, 6144, 6144 372.8 387.9 0.96x
3072, 4096, 1536 96.2 102.2 0.94x

PR Self-Review

Reviewed revision

59ee9a4

Behavior and intent

The opus GEMM and MoE codegen bakes the build target's die count instead of 8. It also fixes a swizzle tail that skips tiles when the last group is short, at any die count, by sending the tail through the same row-group mapping as the rest. The persistent launcher now sizes its grid for two workgroups per CU.

Validation and unverified scope

On MI350P (gfx950, 128 CUs, 4 XCDs, ROCm 7.2.3), against main, at 8881187 (before the tail was simplified):

  • op_tests/test_gemm_codegen.py passes, and the generated instances bake 4.
  • Swizzle tail: 3213 launches over the non-persistent a16w16 kernels give 164 non-finite results on main and 0 on this branch.
  • The opus a16w16, a8w8 and BMM tests match main.

On a 256-CU gfx950, opus_gemm_512x256x256x64 at M=2305, N=50016 with a NaN-filled output leaves 168 tiles unwritten on main (96175f6) and none on this branch. On MI350P the affected kernels are not built by default.

At ebe1de5 on MI355X: the new swizzle-tail test fails with the fix reverted and passes with it, test_opus_a16w16_gemm.py passes, the 24 shipped non-atomic opus a8w4 MoE rows pass in test_moe_2stage.py, and timings match the merge base (see Testing). Persistent kid 30 is 1.09x faster on geomean on MI355X and 1.17x on MI350P, with one shape below 0.95x.

Unverified: none

PR-specific question

Only gfx950 opus kernels change. The die count is fixed per build from the build target, and the launcher and kernel read the same constant, so a mismatched part loses cache locality, not correctness. The tail change applies to workgroups past the last full swizzle cycle.

Changed op tests

  • op_tests/test_gemm_codegen.py: adds test_target_num_xcds, covering the die count per SKU. No other test covers that table.
  • op_tests/test_opus_a16w16_gemm.py: adds test_gfx950_xcd_swizzle_tail_writes_every_tile, the only test that reaches the swizzle tail with a short last row group.
  • op_tests/test_opus_co_integration.py: passes the CU count to kid_rejects_shape, which now takes it. No test is added.

@aiter-bot

aiter-bot commented Oct 29, 2026 •

Copy link
Copy Markdown

READY FOR HUMAN REVIEW

PR Self-Review

Revision 59ee9a404239 · mode shadow

Author self-review accepted. Readiness report:

Author answers

  • PASS — current-SHA answers are present and structurally specific
Show the author's self-review answers

Behavior and intent

The opus GEMM and MoE codegen bakes the build target's die count instead of 8. It also fixes a swizzle tail that skips tiles when the last group is short, at any die count, by sending the tail through the same row-group mapping as the rest. The persistent launcher now sizes its grid for two workgroups per CU.

Validation and unverified scope

On MI350P (gfx950, 128 CUs, 4 XCDs, ROCm 7.2.3), against `main`, at 8881187bf2 (before the tail was simplified):
- `op_tests/test_gemm_codegen.py` passes, and the generated instances bake 4.
- Swizzle tail: 3213 launches over the non-persistent a16w16 kernels give 164 non-finite results on `main` and 0 on this branch.
- The opus a16w16, a8w8 and BMM tests match `main`.

On a 256-CU gfx950, `opus_gemm_512x256x256x64` at M=2305, N=50016 with a NaN-filled output leaves 168 tiles unwritten on `main` (96175f6) and none on this branch. On MI350P the affected kernels are not built by default.

At ebe1de5d86 on MI355X: the new swizzle-tail test fails with the fix reverted and passes with it, `test_opus_a16w16_gemm.py` passes, the 24 shipped non-atomic opus a8w4 MoE rows pass in `test_moe_2stage.py`, and timings match the merge base (see Testing). Persistent kid 30 is 1.09x faster on geomean on MI355X and 1.17x on MI350P, with one shape below 0.95x.

Unverified: none

PR-specific question

Only gfx950 opus kernels change. The die count is fixed per build from the build target, and the launcher and kernel read the same constant, so a mismatched part loses cache locality, not correctness. The tail change applies to workgroups past the last full swizzle cycle.

Changed op tests

- `op_tests/test_gemm_codegen.py`: adds `test_target_num_xcds`, covering the die count per SKU. No other test covers that table.
- `op_tests/test_opus_a16w16_gemm.py`: adds `test_gfx950_xcd_swizzle_tail_writes_every_tile`, the only test that reaches the swizzle tail with a short last row group.
- `op_tests/test_opus_co_integration.py`: passes the CU count to `kid_rejects_shape`, which now takes it. No test is added.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • PASS — no active Copilot finding lacks a substantive author reply
  • ADVISORY — Copilot did not review the current head SHA

Code and op-test hygiene

  • PASS — no committed artifact or conflict marker detected

Required CI

  • PASS — Black: passed
  • PASS — Ruff: passed
  • PASS — Repository dependency: passed
  • PASS — Aiter Test Gate: passed

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 opus kernels [HIP] [OPUS] [JIT] Fix the hardcoded die and CU counts in the opus kernels Oct 29, 2026
@zufayu
zufayu requested a review from yzhou103 October 30, 2026 01:29
@zufayu
zufayu removed the request for review from yzhou103 October 30, 2026 01:54
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

The gfx950 generator ignores explicit target selection and can emit incorrect XCD traits, while the changes also break an existing caller and the generator test’s torch stub.

3 open issues
What changed in this PR

This PR updates gfx950 OPUS kernels to use build-target die counts and device CU counts, continuing the backend-wide hardware-count fixes. It also repairs partial swizzle tails that could leave output tiles unwritten.

Changes:

  • Pass build-target die counts through GEMM, BMM, and MoE code generation and traits.
  • Correct partial-group tile mapping in GEMM and MoE kernels.
  • Use device CU counts for persistent GEMM scheduling and add per-SKU die-count tests.
File Description
op_tests/​test_gemm_codegen.py Adds per-SKU die-count checks.
csrc/​opus_moe/​include/​gfx950/​a8w4/​opus_moe_traits_stage2_a8w4_decode_gfx950.cuh Parameterizes decode route-out die count.
csrc/​opus_moe/​include/​gfx950/​a8w4/​opus_moe_pipeline_stage2_a8w4_decode_main_gfx950.cuh Fixes partial-group tile mapping.
csrc/​opus_moe/​include/​gfx950/​a16w16/​opus_moe_traits_stage2_gfx950.cuh Parameterizes BF16 stage-2 die count.
csrc/​opus_moe/​include/​gfx950/​a16w16/​opus_moe_pipeline_stage2_gemmstyle_gfx950.cuh Fixes stage-2 swizzle tails.
csrc/​opus_moe/​gen_instances.py Emits target die counts in MoE traits.
csrc/​opus_gemm/​opus_gemm_tune.py Uses supplied CU counts in shape filtering.
csrc/​opus_gemm/​include/​gfx950/​opus_gemm_traits_a8w8_scale_gfx950.cuh Threads die counts through MXFP8 traits.
csrc/​opus_gemm/​include/​gfx950/​opus_gemm_traits_a16w16_gfx950.cuh Parameterizes standard and persistent GEMM die counts.
csrc/​opus_gemm/​include/​gfx950/​opus_gemm_pipeline_a8w8_mxscale_flatmm_splitk_gfx950.cuh Uses trait die counts for tile mapping.
csrc/​opus_gemm/​include/​gfx950/​opus_gemm_pipeline_a8w8_mxscale_bpreshuffle_wave8_gfx950.cuh Uses trait die counts for swizzling.
csrc/​opus_gemm/​include/​gfx950/​opus_gemm_pipeline_a16w16_persistent_gfx950.cuh Updates the swizzle comment only.
csrc/​opus_gemm/​include/​gfx950/​opus_gemm_pipeline_a16w16_persistent_4g_safe_gfx950.cuh Updates the swizzle comment only.
csrc/​opus_gemm/​include/​gfx950/​opus_gemm_pipeline_a16w16_gfx950.cuh Corrects partial-group resume offsets.
csrc/​opus_gemm/​include/​gfx950/​opus_bmm_traits_mxscale_compact_gfx950.cuh Adds a compact BMM die-count parameter.
csrc/​opus_gemm/​include/​gfx950/​opus_bmm_pipeline_mxscale_compact_gfx950.cuh Distributes BMM tiles using the trait count.
csrc/​opus_gemm/​codegen/​gen_instances_gfx950.py Emits die counts, matching grids, and device-CU scheduling.
csrc/​gemm_a16w16/​gemm_a16w16_tune.py Passes CU count into OPUS shape filtering.
aiter/​jit/​utils/​build_targets.py Adds die-count lookup and cached build-target resolution.

Review effort: Balanced

Comment thread csrc/opus_gemm/opus_gemm_tune.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

An unchanged caller fails because cu_num is now required, while gfx950 generation breaks standalone execution and can embed XCD counts inconsistent with explicit targets.

3 open issues

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 5, 2026 15:30

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.

- Bakes the build target's XCD count into the opus GEMM, BMM and MoE
  instances through build_num_xcds, instead of a fixed eight.
- Adds target_num_xcds and build_num_xcds to build_targets, resolving the
  count from the (gfx, CU count) targets a build compiles for.
- Reads the device's CU count in the generated GEMM launcher, and passes the
  tuned CU count to the tuners' shape check, where both assumed 256.
@RElbers
RElbers removed this pull request from stack #7002 November 5, 2026 15:55
@RElbers
RElbers changed the base branch from relbers/gfx950_triton_xcd_count to main November 5, 2026 15:57
@RElbers
RElbers force-pushed the relbers/gfx950_opus_xcd_count branch from 19b36a4 to d97a1ae 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.

@zufayu
zufayu requested a review from yzhou103 November 6, 2026 00:55
- Imports build_targets from aiter/jit/utils in the opus GEMM and MoE
  generators instead of through aiter.jit.utils, which ran aiter/__init__
  and its torch import during codegen.
- Shares the aiter/jit/utils lookup between the opus GEMM entry point and
  its gfx950 emitters through codegen/common.py.
Copilot AI balanced review requested due to automatic review settings November 6, 2026 15:23

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.

…argets

- Resolves the gfx950 die count once in gen_instances.py and passes it to the
  emitters on the codegen object, instead of each emitter resolving it from
  the environment.
- Takes the count from --targets when the generator is given them, so an
  explicit gfx950/128 build bakes four dies whatever GPU_ARCHS says; without
  them it resolves the build target as before.
Copilot AI balanced review requested due to automatic review settings November 6, 2026 15:40

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.

@vpietila-amd
vpietila-amd self-requested a review November 12, 2026 08:54
vpietila-amd
vpietila-amd previously approved these changes Nov 12, 2026

@vpietila-amd vpietila-amd 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.

Looks good to me. These are mostly mechanical changes. The only more complex change is the XCD swizzle fix where we could add a new test that fails prior to the fix and passes with the current code changes.

- Runs the a16w16 pipeline on a 13x20 tile grid into a NaN-filled output, where the per-cycle XCD remap covers only the first 256 tiles and the remaining 4 fall in a last row group shorter than the swizzle width, and checks that every tile is written and matches the reference.

The remap permutes whole cycles of dies times SWIZZLE_C workgroups, so the leftover partial cycle takes the tail path at both four and eight dies, and the previous tail resume left tiles of that short group unwritten.
- Applies the XCD remap only below the last full cycle and leaves the tail workgroups' indices as they are, so the same group mapping places every tile.
- Removes the separate tail arithmetic from the a16w16 GEMM pipeline and the two opus MoE stage-2 pipelines.

The remap permutes each full cycle onto itself, so keeping the tail's indices leaves a permutation of all tiles, and the group mapping already handles a short last row group.
- Targets twice the device's CU count when the persistent a16w16 launcher picks split_m, matching the two workgroups per CU its __launch_bounds__ keeps resident.

The launcher used to aim for one workgroup per CU. Its previous hard-coded 256 CUs happened to give two per CU on a 128-CU part, so reading the real CU count halved the grid there, and on 256-CU parts the grid was half what the kernel can hold.

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

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