Skip to content

[FlyDSL] [gfx1250] DSv4.1 Flash 32x32 GEMMs: tune C1024 decode, prefetch a8w8/a4w4 compute kernel code - #7827

Merged
amd-ruitang3 merged 7 commits into
mainfrom
gfx1250/dsv41-flydsl-fp8-gemm-c1024
Nov 20, 2026
Merged

amd-ruitang3 merged 7 commits into
mainfrom
gfx1250/dsv41-flydsl-fp8-gemm-c1024

Conversation

@aoli26

@aoli26 aoli26 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Tunes the DSv4.1 Flash 32x32 GEMMs on gfx1250 for C1024 decode (100 rows, six per-layer GEMMs), and makes the FlyDSL a8w8 and a4w4 compute kernels prefetch their own code at entry, so a compute kernel runs as fast right after another compute kernel as it does alone. Merge after #7659 and #7667 (see Dependencies).

Motivation

  • C1024 decode M moves over ~700..1536, but [FlyDSL] [gfx1250] mxfp8 compute GEMM: 32x32 scale + bmm, DSv4.1 Flash tuning #7659 tuned only M=768.
  • A compute kernel that runs right after another compute kernel was 10-25 us slower in the model (a8w8 wo_a M=1344: 26.7 us isolated, 46.2 us in the model); two a4w4 compute kernels cost 1.5-2.2x of back to back. The 64 KB instruction cache cannot hold two of them (31-84 KiB), and s_prefetch_inst is a no-op while MODE.SCALAR_PREFETCH_EN is clear, which is how waves start once the program was preloaded on the WGP. bmm kernels (<= 25 KiB) are not affected.

Changes

  • dsv41 tuned CSVs (gfx1250, cu_num 256, 32x32): 100 rows for six GEMMs (83 dense, 17 batched O-A) at M=608..1536; 55 pick a compute kernel, 45 a bmm kernel; 92 are new keys, 8 replace an existing row.
  • gemm_common_gfx1250.py: prefetch_kernel_code sets MODE.SCALAR_PREFETCH_EN and prefetches the kernel's code (up to 56 KiB) with s_prefetch_inst, split across the waves. func_index is the kernel's position in its module, for its label and .Lfunc_end.
  • gemm_a8w8_256x256_gfx1250.py, gemm_a4w4_256x256_gfx1250.py: call it at kernel entry. a4w4 launches up to three kernels per module (tail_mode 2, 0, -1), one call each; a8w8 uses index 0 and its code objects are unchanged.
  • Tests: test_compute_switch_penalty in test_flydsl_batched_gemm.py (a8w8) and test_gemm_a4w4.py (a4w4, only with FlyDSL installed); each first checks both kernels against a reference.

Performance (if applicable)

Hardware Workload/configuration Before After Change
gfx1250 Tuned rows, isolated, 102 decode points, 6 GEMMs #7659 pick this PR mean -9.8%, best -28.5%, none slower
gfx1250 a8w8 wo_a B=8 M=1344, right after another compute kernel 30.7 us 21.9 us -29% (alone: 21.2 us)
gfx1250 14 tuned a8w8 compute rows, after another compute kernel / alone (geomean) 1.231 0.985
gfx1250 a8w8 switch test, alternating / back to back 1.37 1.03-1.05
gfx1250 a4w4 t256x256x256 pairs, alternating / back to back 1.5-2.2 0.94-1.06
gfx1250 SQC_ICACHE_MISSES per dispatch, a8w8 repro / a4w4 ~20K / ~45K 768 / 1152

Solo times are unchanged (geomean a8w8 1.0004, a4w4 1.0003).

e2e (DSv4.1 Flash, e2e machine, paired alternating runs of base4 and the build with the a8w8 prefetch; measured before the rebase and the a4w4 change; 2 of 3 pairs per concurrency done). The gain is mainly from the instruction prefetch. Accuracy stays within 54.4-55.7.

Concurrency Pair Throughput tok/s/GPU TPOT p50 ms
c512 a 12745 → 13016 (+2.1%) 5.330 → 5.129 (-3.8%)
c512 b 12606 → 12758 (+1.2%) 5.421 → 5.287 (-2.5%)
c1024 a 15674 → 16541 (+5.5%) 9.433 → 9.114 (-3.4%)
c1024 b 15972 → 16589 (+3.9%) 9.590 → 9.032 (-5.8%)

c1024 is consistent across pairs (run-to-run spread 0.3-1.9%); c512 is within noise (+-1-2%) and needs the third pair (pair b's base overlapped with a CPU compile). TTFT p50 rises 6-11% at c1024 and is mixed at c512, probably queueing (not confirmed).

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Tuned-config rows and kernel prologues; no user-facing change.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Merge order: #7659, then #7667, then this PR; rebase afterwards.

Breaking Changes

None once the dependencies above are merged.

PR Self-Review

Reviewed revision

01043f3

Behavior and intent

Every a8w8 (mx32, mx128) and a4w4 FlyDSL compute kernel sets MODE.SCALAR_PREFETCH_EN and prefetches its own code at entry; output is unchanged. The previous head's in-model picks that worked around the slowdown (Q-B M=576/672 -> bmm _pl, O-A M>=1024 -> bmm, shared down / O-B M=2048/3072 rows) are removed and not retuned here.

Validation and unverified scope

All on gfx1250.

  • a8w8: output byte-identical on 51/51 tuned compute cases with and without the prefetch. After the func_index change, the code objects, LLVM IR and ISA of 64 variants (61 compute) are identical to before (only the label name and source locations differ), and the switch ratio is unchanged (1.021-1.046 vs 1.028-1.059, 3 alternating runs each).
  • Rebased onto [FlyDSL] [gfx1250] mxfp8 compute GEMM: 32x32 scale + bmm, DSv4.1 Flash tuning #7659's head 6c05f98beb (one conflict, in the test file's main()). The 100 rows added or changed here, at M and M-31, through the public entries with FLYDSL_RUNTIME_RUN_ONLY=1 on an AOT cache: 200/200 pass (finite, mismatch 0 against a dequantized fp32 reference); the lookup returns the row's kernelName; the 13 batched compute rows pass [FlyDSL] [gfx1250] mxfp8 compute GEMM: 32x32 scale + bmm, DSv4.1 Flash tuning #7659's batch > 1 stride guard. AOT --check passes (388 dense + 57 batched rows) and fails on an empty cache. Runtime lookup of the six GEMMs over M 1..20000 vs [FlyDSL] [gfx1250] mxfp8 compute GEMM: 32x32 scale + bmm, DSv4.1 Flash tuning #7659's tables: the selected kernel changes only for M 577..1536 (4736 points).
  • a4w4: 22 compute variants (40 kernels) have one prefetch per kernel against its own .Lfunc_end, with the same VGPR/SGPR/scratch (+0.3 KiB each). The 16 tuned compute rows with a cluster of at most 8 workgroups give identical output with and without the prefetch and 0 mismatch against the torch reference. The existing test_gemm_a4w4.py (20 shapes, tuned and asm, off-grid M included) passes, and AOT --check passes on all 24 tuned compute rows. The 8 rows with a 16-workgroup cluster were only compiled.
  • After the review fixes (8080371): each switch test checks both kernels against a dequantized reference (output poisoned with NaN first) before timing. All pass: 2 a8w8 pairs (alternating / back to back 1.033-1.045) and 3 a4w4 pairs (0.93-1.06, two runs). The 5 batched compute cases still match with mismatch 0, and the full test_gemm_a4w4.py (138 shapes, tuned and asm, off-grid M included) has mismatch 0. With fake kernels on CPU, a kernel that writes finite wrong values, nothing, or a wrong batch fails the new check; the previous test passed all three.
  • black 26.3.0 and ruff 0.16.0 pass on the changed files; duplicate-shape guard: 33 tests pass.
  • Unverified: e2e on this head (the e2e above predates the rebase and the a4w4 change; its third pair is running); the rows were tuned in isolation and not re-tuned after the fix; gfx1250-strict, where the compute cases and switch tests now also run (no hardware). a4w4 keeps a data-side cost of 1.1-1.2 at K=6144/7680/8192 with the prefetch (same instruction-cache misses as K=7168), so the new test uses other K.

PR-specific question

Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?

Keys, all gfx1250 / cu_num 256 / w_scale_block 32x32; dense in dsv41_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csv as (N, K): M list, batched in dsv41_batched_gemm_a8w8_blockscale_mxscale_bpreshuffle_tuned.csv as (b, n, k): m list. All are new keys except those marked as replacing an existing row (8):

  • Q-A/KV-A (1792, 5120): 800, 928, 960, 992, 1024 (these five replace existing rows), 1088..1536 step 64
  • Q-B (32768, 1280): 736, 800..1024 step 32, 1088..1536 step 64 (1152, 1344, 1536 replace existing rows)
  • O-B (5120, 8192), shared gate/up (4608, 5120), O-A batched (8, 1024, 4096): 736, 800..1024 step 32, 1088..1536 step 64
  • Shared down (5120, 2304): 608, 704, 736, 800..1024 step 32, 1088..1536 step 64

Evidence: the CSV diff against #7659's head touches only these 100 keys and removes no row. Runtime lookup over M 1..20000, #7659's tables vs this branch's: the selected kernel changes only for M 577..1536 (Q-A/KV-A 769..800 and 897..1536; Q-B, O-B, shared gate/up and O-A 705..736 and 769..1536; shared down 577..608, 673..736 and 769..1536) and for no M outside it. The prefetch selects nothing.

Changed op tests

  • op_tests/test_flydsl_batched_gemm.py: adds test_compute_switch_penalty (two a8w8 wo_a pairs on compute kernels; alternating must stay within 1.10x of back to back). Not redundant: the compute cases time each kernel alone and cannot see a cost that only appears right after another compute kernel; it fails without the prefetch (1.37x). Each kernel's output is first checked against the dequantized reference, so a wrong but finite result fails too.
  • op_tests/test_gemm_a4w4.py: adds test_compute_switch_penalty for a4w4 (K=7168, 3584, 7936, one per kernel of a launch; limit 1.15). It fails without the prefetch (1.5-2.2x); the existing test_gemm times kernels one at a time. Each kernel's output is first checked against the torch reference, and the cases run only when FlyDSL is installed.

@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter standard tests on MI35X
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
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:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
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: 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 7827 --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.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@aoli26 aoli26 changed the title [FlyDSL] [gfx1250] DSv4.1 Flash 32x32 GEMMs: tune decode for C1024 [FlyDSL] [gfx1250] DSv4.1 Flash 32x32 GEMMs: tune decode (C512/C1024) and M 2048/3072 Nov 13, 2026
@aoli26
aoli26 force-pushed the gfx1250/dsv41-flydsl-fp8-gemm-c1024 branch 2 times, most recently from d39fa0c to f6089a0 Compare November 14, 2026 06:10
@aoli26 aoli26 changed the title [FlyDSL] [gfx1250] DSv4.1 Flash 32x32 GEMMs: tune decode (C512/C1024) and M 2048/3072 [FlyDSL] [gfx1250] DSv4.1 Flash 32x32 GEMMs: tune C1024 decode, prefetch compute kernel code Nov 14, 2026
@aoli26
aoli26 force-pushed the gfx1250/dsv41-flydsl-fp8-gemm-c1024 branch from f6089a0 to 17608d9 Compare November 14, 2026 08:01
@aoli26
aoli26 marked this pull request as ready for review November 14, 2026 08:05
@aoli26
aoli26 requested review from a team and a balanced review from Copilot November 14, 2026 08:05
@aiter-bot

aiter-bot commented Nov 14, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision 01043f351280 · 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

Every a8w8 (mx32, mx128) and a4w4 FlyDSL compute kernel sets MODE.SCALAR_PREFETCH_EN and prefetches its own code at entry; output is unchanged. The previous head's in-model picks that worked around the slowdown (Q-B M=576/672 -> bmm `_pl`, O-A M>=1024 -> bmm, shared down / O-B M=2048/3072 rows) are removed and not retuned here.

Validation and unverified scope

All on gfx1250.

- a8w8: output byte-identical on 51/51 tuned compute cases with and without the prefetch. After the `func_index` change, the code objects, LLVM IR and ISA of 64 variants (61 compute) are identical to before (only the label name and source locations differ), and the switch ratio is unchanged (1.021-1.046 vs 1.028-1.059, 3 alternating runs each).
- Rebased onto #7659's head `6c05f98beb` (one conflict, in the test file's `main()`). The 100 rows added or changed here, at M and M-31, through the public entries with `FLYDSL_RUNTIME_RUN_ONLY=1` on an AOT cache: 200/200 pass (finite, mismatch 0 against a dequantized fp32 reference); the lookup returns the row's kernelName; the 13 batched compute rows pass #7659's `batch > 1` stride guard. AOT `--check` passes (388 dense + 57 batched rows) and fails on an empty cache. Runtime lookup of the six GEMMs over M 1..20000 vs #7659's tables: the selected kernel changes only for M 577..1536 (4736 points).
- a4w4: 22 compute variants (40 kernels) have one prefetch per kernel against its own `.Lfunc_end`, with the same VGPR/SGPR/scratch (+0.3 KiB each). The 16 tuned compute rows with a cluster of at most 8 workgroups give identical output with and without the prefetch and 0 mismatch against the torch reference. The existing `test_gemm_a4w4.py` (20 shapes, tuned and asm, off-grid M included) passes, and AOT `--check` passes on all 24 tuned compute rows. The 8 rows with a 16-workgroup cluster were only compiled.
- After the review fixes (`8080371`): each switch test checks both kernels against a dequantized reference (output poisoned with NaN first) before timing. All pass: 2 a8w8 pairs (alternating / back to back 1.033-1.045) and 3 a4w4 pairs (0.93-1.06, two runs). The 5 batched compute cases still match with mismatch 0, and the full `test_gemm_a4w4.py` (138 shapes, tuned and asm, off-grid M included) has mismatch 0. With fake kernels on CPU, a kernel that writes finite wrong values, nothing, or a wrong batch fails the new check; the previous test passed all three.
- black 26.3.0 and ruff 0.16.0 pass on the changed files; duplicate-shape guard: 33 tests pass.
- Unverified: e2e on this head (the e2e above predates the rebase and the a4w4 change; its third pair is running); the rows were tuned in isolation and not re-tuned after the fix; `gfx1250-strict`, where the compute cases and switch tests now also run (no hardware). a4w4 keeps a data-side cost of 1.1-1.2 at K=6144/7680/8192 with the prefetch (same instruction-cache misses as K=7168), so the new test uses other K.

PR-specific question

Which exact workload keys consume these configuration changes, and what evidence shows that unrelated shapes keep their previous selection?

Keys, all gfx1250 / cu_num 256 / w_scale_block 32x32; dense in `dsv41_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csv` as (N, K): M list, batched in `dsv41_batched_gemm_a8w8_blockscale_mxscale_bpreshuffle_tuned.csv` as (b, n, k): m list. All are new keys except those marked as replacing an existing row (8):

- Q-A/KV-A (1792, 5120): 800, 928, 960, 992, 1024 (these five replace existing rows), 1088..1536 step 64
- Q-B (32768, 1280): 736, 800..1024 step 32, 1088..1536 step 64 (1152, 1344, 1536 replace existing rows)
- O-B (5120, 8192), shared gate/up (4608, 5120), O-A batched (8, 1024, 4096): 736, 800..1024 step 32, 1088..1536 step 64
- Shared down (5120, 2304): 608, 704, 736, 800..1024 step 32, 1088..1536 step 64

Evidence: the CSV diff against #7659's head touches only these 100 keys and removes no row. Runtime lookup over M 1..20000, #7659's tables vs this branch's: the selected kernel changes only for M 577..1536 (Q-A/KV-A 769..800 and 897..1536; Q-B, O-B, shared gate/up and O-A 705..736 and 769..1536; shared down 577..608, 673..736 and 769..1536) and for no M outside it. The prefetch selects nothing.

Changed op tests

- `op_tests/test_flydsl_batched_gemm.py`: adds `test_compute_switch_penalty` (two a8w8 wo_a pairs on compute kernels; alternating must stay within 1.10x of back to back). Not redundant: the compute cases time each kernel alone and cannot see a cost that only appears right after another compute kernel; it fails without the prefetch (1.37x). Each kernel's output is first checked against the dequantized reference, so a wrong but finite result fails too.
- `op_tests/test_gemm_a4w4.py`: adds `test_compute_switch_penalty` for a4w4 (K=7168, 3584, 7936, one per kernel of a launch; limit 1.15). It fails without the prefetch (1.5-2.2x); the existing `test_gemm` times kernels one at a time. Each kernel's output is first checked against the torch reference, and the cases run only when FlyDSL is installed.

PR state

  • PASS — pull request is marked ready for review

Copilot findings

  • FAIL — an active Copilot finding has no substantive reply from the PR author
  • FAIL — an active Copilot finding has no substantive reply from the PR author

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.

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

All 13 new O-A compute rows select kernels rejected by the fused-quant path, causing ValueError instead of quantized output and requiring a fallback with regression coverage.

1 open issue
What changed in this PR

This PR tunes AITER’s gfx1250 DSv4.1 Flash 32×32-scale GEMMs for C1024 decode and adds instruction prefetching to reduce slowdowns when switching between compute kernels. It builds on #7659 and is intended to land after #7667.

Changes:

  • Adds or updates 100 tuning rows across six dense and batched GEMMs.
  • Enables scalar instruction prefetching at a8w8 compute-kernel entry.
  • Adds alternating-kernel performance coverage alongside the stacked compute-path and scale-layout tests.
File Description
op_tests/​test_gemm_a8w8_blockscale.py Adds 32×32 weight-scale testing from the prerequisite stack.
op_tests/​test_flydsl_batched_gemm.py Adds compute cases, operand guards, and switch-penalty checks.
aiter/​ops/​flydsl/​mxfp8_bpreshuffle_gemm_gfx1250.py Supports batched compute dispatch, 32×32 scales, and cluster fallback.
aiter/​ops/​flydsl/​kernels/​gemm_common_gfx1250.py Adds the instruction-prefetch helper.
aiter/​ops/​flydsl/​kernels/​gemm_a8w8_256x256_gfx1250.py Calls prefetch at entry; includes stacked scale and batching support.
aiter/​ops/​flydsl/​batched_gemm_a8w8_gfx1250.py Routes compute kernel names through the dense compute runner.
aiter/​configs/​model_configs/​dsv41_batched_gemm_a8w8_blockscale_mxscale_bpreshuffle_tuned.csv Extends tuned batched O-A decode selections.
aiter/​configs/​model_configs/​dsv41_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csv Extends tuned dense decode selections.

Review effort: Balanced

@aoli26 aoli26 changed the title [FlyDSL] [gfx1250] DSv4.1 Flash 32x32 GEMMs: tune C1024 decode, prefetch compute kernel code [FlyDSL] [gfx1250] DSv4.1 Flash 32x32 GEMMs: tune C1024 decode, prefetch a8w8/a4w4 compute kernel code Nov 14, 2026
Copilot AI balanced review requested due to automatic review settings November 14, 2026 10: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 switch tests can fail on gfx1250 when optional FlyDSL is absent, and they do not independently validate each kernel’s output against a reference, allowing incorrect finite results to pass.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment thread op_tests/test_gemm_a4w4.py Resolved
Comment thread op_tests/test_gemm_a4w4.py Resolved
@aoli26
aoli26 force-pushed the gfx1250/dsv41-flydsl-fp8-gemm-c1024 branch from b91d1a1 to 8080371 Compare November 14, 2026 16:56
Copilot AI balanced review requested due to automatic review settings November 14, 2026 16:56

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

ISA-level prefetch and MODE-register changes depend on compiler-generated labels and require hardware review, with no head-bound runtime validation for graph replay, gfx1250-strict, or a4w4 16-workgroup configurations.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@zufayu
zufayu requested a review from coderfeli November 15, 2026 07:38
Boss2002n pushed a commit that referenced this pull request Nov 16, 2026
A launch preloads only the first ~32 KiB of a kernel into the
instruction cache. The S1F tile-256 kernel (~46 KiB) and the stage-1
GEMM (up to ~62 KiB) ran their tails cold whenever another large kernel
had evicted them, so UT gains did not always show up end to end.

Add prefetch_kernel_code(num_waves) to gemm_common_gfx1250, following
#7827: set MODE.SCALAR_PREFETCH_EN through llvm.amdgcn.s.setreg, find
the kernel span with s_getpc_b64 and .Lfunc_end0, and have each wave
issue every num_waves-th 4 KiB s_prefetch_inst chunk up to 56 KiB,
without branches. S1F replaces its old inline-asm prefetch, which was a
no-op without MODE[24]; the a8w4 TDM GEMM calls it at kernel entry and
tags the kernel name with _ipf. AITER_FLYDSL_INST_PREFETCH=0 turns it off.

Co-authored-by: Cursor <[email protected]>
amd-ruitang3
amd-ruitang3 previously approved these changes Nov 17, 2026
@aoli26
aoli26 force-pushed the gfx1250/dsv41-flydsl-fp8-gemm-c1024 branch from 8080371 to 7db7abc Compare November 17, 2026 08:46
Copilot AI balanced review requested due to automatic review settings November 17, 2026 08:46

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

The gfx1250 prefetch prologue depends on compiler function ordering and hardware MODE behavior, requiring hardware review because no head-matched GPU correctness or performance validation was supplied.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 19, 2026 01:58

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

The gfx1250 prologues depend on compiler function numbering and hardware prefetch behavior, requiring specialist review because head-matched GPU validation of graph replay, a4w4 16-workgroup clusters, and switch latency is unavailable.

No open issues 🎉

Review effort: Balanced

amd-ruitang3
amd-ruitang3 previously approved these changes Nov 19, 2026
Copilot AI balanced review requested due to automatic review settings November 19, 2026 10:14

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 added/refreshed bandwidth fields in both tuning CSVs use TB/s instead of the expected GB/s, understating values by roughly 1000× and requiring recomputation.

1 open issue

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 20, 2026 02:42

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

The prefetch relies on gfx1250 cache behavior and assembler function ordering that require unavailable GPU validation, while 16-workgroup a4w4 execution and exact-head end-to-end behavior remain unverified.

1 open issue

Review effort: Balanced

XingerZhu added a commit that referenced this pull request Nov 20, 2026
A launch preloads only the first ~32 KiB of a kernel into the
instruction cache. The S1F tile-256 kernel (~46 KiB) and the stage-1
GEMM (up to ~62 KiB) ran their tails cold whenever another large kernel
had evicted them, so UT gains did not always show up end to end.

Add prefetch_kernel_code(num_waves) to gemm_common_gfx1250, following
#7827: set MODE.SCALAR_PREFETCH_EN through llvm.amdgcn.s.setreg, find
the kernel span with s_getpc_b64 and .Lfunc_end0, and have each wave
issue every num_waves-th 4 KiB s_prefetch_inst chunk up to 56 KiB,
without branches. S1F replaces its old inline-asm prefetch, which was a
no-op without MODE[24]; the a8w4 TDM GEMM calls it at kernel entry and
tags the kernel name with _ipf. AITER_FLYDSL_INST_PREFETCH=0 turns it off.

Co-authored-by: Cursor <[email protected]>
@amd-ruitang3
amd-ruitang3 merged commit 908a0b0 into main Nov 20, 2026
@amd-ruitang3
amd-ruitang3 deleted the gfx1250/dsv41-flydsl-fp8-gemm-c1024 branch November 20, 2026 08:03
aoli26 added a commit that referenced this pull request Nov 23, 2026
Conflicts resolved:
- aot/flydsl README and gemm.py: take main's wording (compute kernel).
- splitk_fused_epilogue_gfx1250: keep main's stripe_rows cap (rows past M can exceed 4 GiB per stripe) in the lean output descriptor, and keep the idle-row path (rows_per_iter > reduce_m) and the _store helper from this branch. Both branches removed bounded_m; the store branches are identical.
yhl-amd added a commit to yhl-amd/aiter that referenced this pull request Nov 23, 2026
…j at decode M 928..1536

Two DSv4.1 dense MXFP8 (32x32 weight scale) shapes at the high-concurrency
decode widths:

- engram wkv (N=25600, K=6144): M 928 / 960 / 992 / 1024 move from the
  batched kernel to the 2-D compute kernel t256x256x128 nb2 cm4 cn1; M 1216,
  1280, 1344, 1408, 1472, 1536 had no row (they used the M 2048 row) and get
  the same kernel.
- DSpark main_proj (N=5120, K=15360): M 928 / 960 / 992 / 1024 move to the
  compute kernel t128x256x128 nb3 cm2 cn2; M 1088..1536 (step 64) had no row
  and get the same kernel.

Rows were chosen from measurements inside the decode layer sequence (other
large GEMMs before and after), not back-to-back runs of one kernel. Outputs
are bit identical to the previous kernels. Prefill rows and other shapes are
unchanged.

The 32x32-scale compute kernel these rows name is already in main
(ROCm#7659, ROCm#7827).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
aoli26 added a commit to XiaobingSuper/aiter that referenced this pull request Nov 23, 2026
Resolve the conflicts with ROCm#7868 (cluster_m is a launch argument) and ROCm#7827:
keep main's profile asserts and the PR's (256, 128, 128, 2, 2, 2) profile, drop
the compile-time cluster_m check from the ragged_n assert, and drop bounded_m,
which no longer has a reader after ROCm#7868.
junhaha666 pushed a commit that referenced this pull request Nov 26, 2026
* [FlyDSL] [gfx1250] Absorb grouped MoE GEMM1 prefill opts into mega stage-1 (#7919)

* Optimize FlyDSL grouped MoE kernels

* improve test

* support a preshuffle

* add csv support

* update quant and shuffle

* update

* update mega-moe

* update

* update csv

* update

* simplify code

* fix accuracy drop

* update csv

* fix format

* fix(flydsl): align A-preshuffle guards and AOT coverage

* improve cs test

* fix ruff

* Tune conc16384 benchmark with WPT2 and cluster sync disabled

* Add standalone conc16384 GEMM1 performance reproducer

Rename the benchmark to reproduce.sh and pin the validated zero-input configuration. Include standalone activation/quantization dependencies and tests so the script does not rely on stashed implementation changes. Preserve unrelated work in stash. GPU timing was not rerun for this commit.

* Tune grouped MoE LDS scheduling and prologue initialization

Use normal WMMA order with operand B reuse and precomputed payload LDS bases. Initialize accumulators before the prologue TDM wait and select WPT1 for the conc16384 tuned configuration.

Include the local benchmark scripts and the reproducer iteration update.

* Pin FlyDSL WMMA scale registers to disjoint low VGPR slots

* update

* update

* update

* remove useless tests

* add script

* update script

* update script and wheel

* update

* update1

* update

* Fix LDS helper shadowing after GEMM task refactor

* Simplify gfx1250 prefill scheduling and add reproducible MoE benchmarks

* Keep local GPU benchmark scripts and microtests out of the branch

* Restore LDS layout controls and decouple interleaving from scheduling

* Fix strict VGPR pinning with FlyDSL 0.5.0

Resolve sched_vgpr through rocdl.experimental on FlyDSL 0.5.0 while retaining compatibility with the older public API. Keep strict placement enabled for prefill kernels.

Validated DSV4 Pro conc16384 with three const/random runs at 32 iterations. Both GEMMs have zero scratch instructions and accumulator placement at physical v512-v1023; median const GEMM1/GEMM2 is 465.77/322.86 us.

* update for ds flash v4.1

* Tune DSV4.1 Flash 8192 prefill configuration

* update for release

* add csv

* update csv

* update csv for dsr1 fused expert

* Move DSR1 grouped MoE configs into a dedicated CSV

* remove useless csv

* update csv

* [FlyDSL] Simplify prefill WMMA emission and barriers

* Tune DSR1 65-expert (64 routed + 1 shared, topk 9) grouped MoE rows for 1-1024 tokens

The single 16x256x256 four-wave as-prologue row left gemm1 at ~16 TB/s for decode-sized
batches (three workgroup rounds, extra round at 4 tokens, and a 64-row tile that doubled
weight reads at 1024 tokens). Re-swept tiles and knobs for this shape on gfx1250:
narrower gemm1 tiles (tile_n 64/128) with deeper buffering for 1-32 tokens, as-prologue
kept only at 64 and 256 tokens where it measures faster, and 128x256 tiles at 1024 tokens.

gemm1+gemm2 vs the previous rows (test_flydsl_grouped_gemm, constant + uniform init):
1 tok 1.81x, 2 1.11x, 4 1.25x, 8-256 1.12-1.16x, 512 1.08x, 1024 1.38x; >= 2048 unchanged.

* Simplify FlyDSL KSL0 fence configuration and kernel symbols

* Merge PR #5899 (zxe/mega_stage1_compact_overlap) for local benchmarking

Co-authored-by: Cursor <[email protected]>

* mega: adapt S1F/GEMM2 to the MoE prefill path, tune DSV4.1 Flash EP4 buckets

- Pin VGPRs only for the 2x2 256^3 tile; S1F's 1x4 256 variant overflowed the map.
- S1F GEMM1 warp grid per tile_m (2x2 at 256, AITER_MEGA_S1F_WARPS override)
  and pass the GEMM kernel_attrs to the S1F launch.
- DSV4.1 Flash E96 rows: GEMM2 next_stage_prefetch + lds_soa_load_interleave
  at 8192+, add the missing 131072 bucket (tpr 32768: 3783 -> 3258 us/layer).

Co-authored-by: Cursor <[email protected]>

* [FlyDSL] [gfx1250] Pack GEMM1 A inside mega stage-1 for large prefill buckets

The stage-1 producer writes the M16 packed A layout, and the 256-row GEMM1
turns on a_preshuffle, lds_soa and next_stage_prefetch together with the
grouped-MoE prefill schedule. This runs only when the recv bound is at least
65536, which for EP4 top-6 is tpr 16384 and 32768. Payload and scale use
separate buffer resources so the masked store sentinel stays out of range.

DSV4.1 Flash EP4, 8-layer graph: 1654 vs 1704 us/layer at tpr 16384 (-2.9%)
and 3111 vs 3258 at tpr 32768 (-4.5%). Smaller buckets stay on the 128-tile path.

Co-authored-by: Cursor <[email protected]>

---------

Co-authored-by: yadaish <[email protected]>
Co-authored-by: JiaoliangYu <[email protected]>
Co-authored-by: lalala-sh <[email protected]>
Co-authored-by: hyi <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: XingerZhu <[email protected]>

* [FlyDSL] [gfx1250] Defer the mega GEMM2 EP-scatter wait; tune DSV4.1 EP4 buckets

A persistent bf16 EP scatter now stages its rows in the last pipeline stage
and skips the tensor_wait after the remote gather-store (defer_c_wait): the
next tile's first fence retires it and the persistent loop drains at exit.
It turns on by itself when the rows fit there (tile_m > 32, > 2 buffers, no
planar LDS / A-scale prologue / k_waves); AITER_FLYDSL_EP_DEFER_C_WAIT=0
turns it off.

DSV4.1-Flash EP4 a4w4 fp4-wire, mega S1F+S2F, uniform routing, 3x A/B:
- tpr 512 (token 2048): persistent_workers2=512 -> GEMM2 57.6 -> 55.2 us,
  layer 217.0 -> 214.7 us (-1.1%).
- tpr 1024 (token 4096): num_buffer_stage2=3 -> GEMM2 81.2 -> 78.9 us.
Accuracy (layers=2) PASS at both with an unchanged logits_diff.

Co-authored-by: Cursor <[email protected]>

* [FlyDSL] [gfx1250] Skip pinned VGPRs when the prefill slot exceeds 128 dwords

FP4 256x256 at 1x4 needs 160 dwords and asserts in make_rmem_slot. Gate the
explicit map on the same slot width, so that shape stays on the ordinary
allocator while 2x2 (128 dwords) keeps the pinned schedule.

Co-authored-by: Cursor <[email protected]>

* [FlyDSL] [gfx1250] Prefetch kernel code past the launch window

A launch preloads only the first ~32 KiB of a kernel into the
instruction cache. The S1F tile-256 kernel (~46 KiB) and the stage-1
GEMM (up to ~62 KiB) ran their tails cold whenever another large kernel
had evicted them, so UT gains did not always show up end to end.

Add prefetch_kernel_code(num_waves) to gemm_common_gfx1250, following
#7827: set MODE.SCALAR_PREFETCH_EN through llvm.amdgcn.s.setreg, find
the kernel span with s_getpc_b64 and .Lfunc_end0, and have each wave
issue every num_waves-th 4 KiB s_prefetch_inst chunk up to 56 KiB,
without branches. S1F replaces its old inline-asm prefetch, which was a
no-op without MODE[24]; the a8w4 TDM GEMM calls it at kernel entry and
tags the kernel name with _ipf. AITER_FLYDSL_INST_PREFETCH=0 turns it off.

Co-authored-by: Cursor <[email protected]>

---------

Co-authored-by: Satya Nikhil Kodukula <[email protected]>
Co-authored-by: yadaish <[email protected]>
Co-authored-by: JiaoliangYu <[email protected]>
Co-authored-by: lalala-sh <[email protected]>
Co-authored-by: hyi <[email protected]>
Co-authored-by: Cursor <[email protected]>
yifehuan pushed a commit that referenced this pull request Nov 27, 2026
…j at decode M 928..1536 (#8048)

Two DSv4.1 dense MXFP8 (32x32 weight scale) shapes at the high-concurrency
decode widths:

- engram wkv (N=25600, K=6144): M 928 / 960 / 992 / 1024 move from the
  batched kernel to the 2-D compute kernel t256x256x128 nb2 cm4 cn1; M 1216,
  1280, 1344, 1408, 1472, 1536 had no row (they used the M 2048 row) and get
  the same kernel.
- DSpark main_proj (N=5120, K=15360): M 928 / 960 / 992 / 1024 move to the
  compute kernel t128x256x128 nb3 cm2 cn2; M 1088..1536 (step 64) had no row
  and get the same kernel.

Rows were chosen from measurements inside the decode layer sequence (other
large GEMMs before and after), not back-to-back runs of one kernel. Outputs
are bit identical to the previous kernels. Prefill rows and other shapes are
unchanged.

The 32x32-scale compute kernel these rows name is already in main
(#7659, #7827).

Co-authored-by: Claude Opus 5.5 <[email protected]>
gbyu-amd pushed a commit that referenced this pull request Dec 3, 2026
…15808c7, head 2026-11-19T10:14:52Z)

Applied as the diff ce334d0..15808c7 (26 files) onto the rebased 1116 tree; PR state: open, author aoli26, base main.

Squash-applied: #8246's branch merges main (ce334d0, this tree's base) and carries rebased copies of aoli26's
#7827 (head 9d38b5c, every added line present here) and #7868 (head 570805d; 3 of its added lines
are superseded by #8246's later edits), so this one diff applies the #7827 -> #7868 -> #8246 stack as #8246 has it.

(cherry picked from commit f58bb7e)

Rebase onto main 12-03: kept at the 15808c7 snapshot (the PR head is now c4f8a6d, see the rebase report). Main's #8678 (AOT launchers) and #7449 (deferred split-K partials) conflict with it in the two wrappers: bpreshuffle_gemm_gfx1250.py takes both fused_splitk and main's partials (a launch with partials runs unfused, main's _launch_splitk_reduce / reduce_splitk_partials_gfx1250 kept, skipped when fused); mxfp8_bpreshuffle_gemm_gfx1250.py keeps fused_splitk_ok (generic kernel included) and launches gemm_a8w8_launcher.lazy() with this PR's argument layout (arg_out, runtime cluster_m, fused_splitk). Same as the PR author's own merge of main, without the later lean_stripe_fits guard. aiter/aot/flydsl/sources.py: the gemm_a8w8_gfx1250 cache now also hashes kernels/splitk_fused_epilogue_gfx1250.py, which the kernel imports (as on the PR head).

Rebase onto main 12-03: op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py counts reduce launches through splitk_reduce_launcher.lazy (main #8678 replaced _compile_splitk_reduce), as on the PR head.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants