Repository navigation
[FlyDSL] [gfx1250] TDM HGEMM: FP32 cluster split-K, and DSV4.1 BF16 rows where TDM measures faster - #8031
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
584421b to
c23cfe1
Compare
PR 8031: same-session measurements (review item 2)All numbers below were taken on 2026-11-24 in one session on one machine. Each run used one GPU and nothing else ran on that GPU. Setup
1. DSV4.1 rows: the row on main against the row this PR proposedBoth rows go through
Decision taken in this branch: a row stays on TDM only if the pooled new/old is at or below 1.0. 16 rows go back to the row on main; 111 rows stay on TDM. The M=768, N=384, K=5120 row is not counted: main moved it to a Triton row in #7663. Rows put back (16)
Rows kept on TDM (111): new/old median 0.923, range 0.691 to 0.999; 5 of them are within 2% of the previous row
2. The two
|
| Rows | Without/with, median | Range | Faster without by more than 2% | Within 2% | Slower without by more than 2% | Outputs bitwise equal |
|---|---|---|---|---|---|---|
| 132 | 0.922 | 0.806 to 1.008 | 107 | 25 | 0 | 132 of 132 |
The rows within 2% are the large shapes (N = 32320 and 129280, and M of 2048 and above), where the kernel is bound by memory, not by the schedule.
3. The five Qwen 3.5 rows
Three arms per row, pre-PR kernel (from the merge base) and this PR's kernel in the same process: the pre-PR kernel with the old tile, the new kernel with the old tile, the new kernel with the new tile. Ten blocks per arm.
| M | N | K | Pre-PR reduction | Pre-PR kernel, old tile µs | New kernel, old tile µs | New kernel, new tile µs | New/pre-PR | Error ratio pre-PR | Error ratio new |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 128 | 4096 | BF16 packed atomic | 4.494 | 3.461 | 3.465 | 0.771 | 0.0078 | 0.0000 |
| 2 | 128 | 4096 | BF16 packed atomic | 4.552 | 3.507 | 3.520 | 0.773 | 0.0195 | 0.0000 |
| 4 | 128 | 4096 | BF16 packed atomic | 4.566 | 3.508 | 3.494 | 0.765 | 0.0273 | 0.0000 |
| 8 | 128 | 4096 | BF16 packed atomic | 4.646 | 3.548 | 3.542 | 0.762 | 0.0215 | 0.0000 |
| 16 | 128 | 4096 | BF16 workspace | 4.572 | 3.378 | 3.379 | 0.739 | 0.0088 | 0.0000 |
The gain comes from the kernel. The tile change in these five rows is within 0.5% and could be dropped.
4. Split-K stress
Every shipped TDM row with split_k > 1 at the time of the run (106 rows) was launched repeatedly through tuned.flydsl_gemm on two alternating input sets. The output buffer is filled with NaN before each launch and compared bit for bit with the first result for that input, so a stale partial from the previous launch would show.
| Rows | Launches | Bitwise mismatches | Rows with errors | Error ratio against the FP32 reference |
|---|---|---|---|---|
| 106 | 91200 | 0 | 0 | 0.0000 at most |
The 22 rows that use t16x32x128x6_ks8 (the kernel the review asks about) ran 3000 launches each; the others 300. This run does not reproduce or explain the earlier illegal instruction on GPU 0 or the page fault in row 371: which kernel was running then is only in the logs of that tuning run.
…M rows for every M bucket up to 1024 Rows for the router (896x7168), latent down (3584x7168) and latent up (7168x3584) GEMMs of Kimi-K3's latent MoE on gfx1250 / 256 CUs: one row for every decode M bucket up to 1024 (16-aligned to 256, 32-aligned to 1024), so no decode M falls through to a power-of-two row. Each bucket was picked inside a decode-step proxy (92 layers x the three GEMMs, per-layer weights, CUDA graph) at every multiple of 5 in the bucket, since DP8EP8 decode with DSpark k=4 gives M = 5 x requests per rank. Step proxy, every multiple of 5 from M 100 to 960: -4.6% on average, worst +0.6%; c256 -11.4%, c512 -7.0%, c1024 -9.2%. The latent rows at M 1/2/4/8 and 2048-32768 are #8348's, with the _i0_ptdm / _i1_ptdm names written as _ptdm / _ptdmi. The TDM rows need #8031's kernel. Co-Authored-By: Claude Opus 5.5 <[email protected]>
valarLip
left a comment
There was a problem hiding this comment.
⚠️ Action required before merge (2)
- Make
flydsl_hgemm_policy_runs_onthe one gate, or stop calling it that (follow-up to item 1).- The body and commit 79b6913 say it "is the one place that says which policy an architecture can run". The predicate does answer for sk/bs/ft/ht/hti too (
aiter/ops/flydsl/gemm_kernels.py:238-242). - But
flydsl_hgemmcalls it only for TDM (:309). The sk and ft/ht branches keep their own copies of the same arch rules (:367/:374-375,:388/:395,:406/:414-417). - Every copy agrees today, but the tuned-row filter (
aiter/tuned_gemm.py:193-201) and the launcher can drift apart. - Fix: call the predicate once at the top of
flydsl_hgemmfor every policy and drop the per-branch copies. No route changes, and no test matches the removed messages. The alternative is to reword the claim to "TDM availability" in the body and squash text.
- The body and commit 79b6913 say it "is the one place that says which policy an architecture can run". The predicate does answer for sk/bs/ft/ht/hti too (
- Drop the test for a name format that never shipped.
op_tests/tuning_tests/test_a16w16_tuned_config_lookup.py:394asserts that the_gm0_i{0,1}_pspelling is rejected. That spelling existed only in this PR's earlier revisions, so this is the same "assert a removed thing is absent" test that item 10 asked to remove.
Prior asks at f5ec86c:
- Done: items 1 (except the leftover above), 3, 5, 6, 7, 8, 9 and 10, each checked in code.
- Item 2: the same-session ABBA tables, the 16 rows put back, the
sched_barrierA/B (median 0.92, bitwise equal) and the split-K stress (91,200 launches, 0 mismatches) are all done. I no longer require the kernel IDs for the tuning-run illegal instruction and page fault. Every shipped split-K row was stressed with no fault, and the body lists the faults as unverified. They stay a residual risk. - Item 4 (split): not pursued, per your reply.
Checked and fine:
- Shipped rows: all 116 TDM rows parse and round-trip, and are valid for their real M/N/K (ks ≤ 9, K divisible by ks·block_k, LDS ≤ 320 KiB).
- CSV keys: no duplicate key, and no other key changed.
- Lookup cost: the strict-row filter sits behind the
lru_cachelookup, so it runs and warns once per shape. - FP32 workspace: bounds and the store →
s_wait_storecnt→ cluster barrier → load order hold, and so does the graph-capture/stream behaviour. - CI: all green.
Reviewed at f5ec86c (deep re-review, two independent passes, CPU name/shape probes). Already fixed: items 3, 5-10; item 1 except the leftover above; item 2 except the fault IDs, now dropped.
flydsl_hgemm asks flydsl_hgemm_policy_runs_on once, after the argument checks and before any branch, for every policy; the skinny branch's gfx950 check and the trailing gfx950/gfx1250 check go, so the launcher and the tuned-row filter read the same rule. No route changes: gfx1250 vs gfx950 still picks the kernel. A policy without a kernel on the runtime raises RuntimeError("FlyDSL HGEMM policy ... has no kernel for <gfx>"); bs on a non-gfx950 runtime now raises it here instead of the band launcher's ValueError, which still checks the CU count.
Drop the lookup-test assertion that the never-shipped _gm0_i{0,1}_p spelling is rejected, and match the strict-runtime test to the new message.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@valarLip Thanks. Both items are addressed in
Validation at
The Testing and Self-Review sections of the description are updated to this revision. |
…spatch (#8960) * [GEMM] gemm_a16w16: return the empty result for M=0 before backend dispatch An idle data-parallel rank's dummy step reaches the lm_head GEMM with no rows. _gemm_a16w16 looked up a tuned config for M=0 and dispatched it; on gfx1250 DSV4.1 BF16 shapes resolve to the FlyDSL TDM kernel (#8031), whose validator rejects a zero dimension. The idle ranks crashed and the serving rank hung in a collective (DSV4.1-Flash DEP4). Answer M=0 before the lookup with the [*A.shape[:-1], N] result of otype, or `out` viewed to that shape. The out-dtype check still runs first; M>0 is unchanged. Add op_tests/test_gemm_a16w16.py -t empty. Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs(gemm_a16w16): spell out K=0 vs M=0 behavior in the docstring Per review feedback on #8960: document that the M=0 early return is independent of K=0, which still falls through to the normal tuned dispatch and is only as well-defined as the selected backend's handling of a zero contraction. Co-Authored-By: Claude Sonnet 5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: root <[email protected]>
…does (_ptdm / _ptdmi) The rebase onto main 12-03 dropped k3-455-dev's pre-merge copy of #8031 (b445370, PR head 520f0bb) for main's merged deca29e. The two spell a TDM HGEMM's wave schedule differently: the PR head wrote it as a name token, `..._gm{g}_i0_ptdm_gfx1250` / `..._gm{g}_i1_ptdm_gfx1250`, while main's final version folds it into the policy, `..._gm{g}_ptdm_gfx1250` (plain) / `..._gm{g}_ptdmi_gfx1250` (interleaved), and its _HGEMM_KERNEL_RE has no `_i` token. Main converted its own CSV rows; the K3 rows tuned on the PR head kept the old spelling, so get_flydsl_hgemm_kernel_params() returns None for them and every lookup logs "not recognized by the current catalog; falling back to next candidate" and runs the default Triton gemm_a16w16 (C1203 on e17: 1332 warnings per D tray, all during graph capture). Rows affected, all gfx1250 bf16 -> bf16: - kimik3_bf16_tuned_gemm.csv, 256 rows from #9096: LM / DSpark draft head, N 163840, K 7168, M 1-256; - kimik3_bf16_tuned_gemm.csv, 20 rows from #8348: latent-MoE routed_expert_down_proj (N 3584, K 7168) and routed_expert_up_proj (N 7168, K 3584), M 1-32768; - op_tests/k3_latent_bf16_tuned_rows.csv, the same 20 latent rows. Rename only: `_i0_ptdm_` -> `_ptdm_`, `_i1_ptdm_` -> `_ptdmi_`; no other byte changes. Every renamed name parses with this tree's get_flydsl_hgemm_kernel_params() (TDM validator included) to the same tile / stages / waves / split-K / group_m / interleave the old parser read from the old name, and no file in the tree keeps `_i[01]_ptdm`. The TDM kernel builder is unchanged between the two trees apart from the cache-policy constant's name and the AOT factory wrapper. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
On gfx1250 the TDM HGEMM kernel reduces split-K partials in FP32 inside a cluster, and 111 DeepSeek-V4.1 BF16 rows plus the five Qwen 3.5 TDM rows use it. Every row that changes kernel was re-timed against the row it replaces in one session.
Motivation
tdma/tdmia). The second is not deterministic and both lose the fractional part of a partial.Changes
kernels/gemm_a16w16_tdm_gfx1250.py,gemm_a16w16_tdm.py): split_k > 1 stores FP32 partials to a per-launch workspace with device scope, waits for the wave's stores, passes one cluster barrier, and rank 0 adds the partials in a fixed order. Output is rounded once, then bias is added. split_k = 1 writes the output directly and uses no workspace and no cluster. The packed-atomic reduction and its arguments are removed. Tworocdl.sched_barrier(0)in the compute loop are removed.gemm_kernels.py):tdmandtdmi(interleaved wave schedule).tdma/tdmiaare no longer emitted; a persisted name that still carries one maps totdm/tdmi.flydsl_hgemm_policy_runs_on(policy, gfx)is the one predicate for "this policy has a kernel on this runtime".flydsl_hgemmchecks it once for every policy, after the argument checks and before routing, and raisesRuntimeErroron a False answer (the per-branch gfx checks are gone); the tuned-row lookup skips the row, so a gfx1250-strict runtime that borrows gfx1250 rows falls back instead of raising.gemm_a16w16_policy.py): the gfx1250 race for same-dtype output is TDM plus the original FT/HT configs;block_n160 is added to the TDM grid.tdma/tdmtotdmon the new kernel.Performance
gfx1250, 256 CUs, one GPU per run, all arms in one session,
run_perftest(num_warmup=10, num_iters=101)per block, arms alternated A B B A. Per-row tables are in the measurement comment below.tuned.gemm_a16w16sched_barrier(0)Rows that did not measure faster are not in this PR: 16 rows the tuning run had moved to TDM are back on their previous row (TDM/previous 1.005 to 1.156), and 42 OPUS rows that only changed their recorded time are back to main's text.
How the shipped rows were produced: the tuning run raced TDM candidates only (plus the row's own OPUS kernel for rows that were OPUS), at source
6acacf2, with FlyDSL 0.5.0. It did not race FT/HT. The FT/HT comparison is the same-session A/B above, done afterwards for every row. Theuscolumn of the kept rows is from the tuning run, not from the A/B session.Testing
Run on gfx1250 (256 CUs), FlyDSL 0.5.0, at
f5ec86c46:python3 -m pytest op_tests/tuning_tests/test_a16w16_tuned_config_lookup.py: 24 passed, 4959 subtests.python3 op_tests/test_flydsl_hgemm.py: exit 0.black --check(26.5.1) andruff check(0.16.7) on the changed files: clean.Review round 2, at
2b070061d, on a gfx1250 node (256 CUs) with the compiled modules of the 2026-11-24 main image (FlyDSL 0.5.3) and this branch's Python sources:python3 -m pytest op_tests/tuning_tests/test_a16w16_tuned_config_lookup.py: 24 passed, 4959 subtests.flydsl_hgemmagainst a float reference:tdmwith split_k 1 and 4,ft,ht(M 64, N 1024, K 2048), andtdmiandtdmwith thet256x256x128x2_ks1_w2x2x1config of a DSV4.1 row (M 160, N 4096, K 5120): rel err 1.65e-3 to 1.67e-3.skandbsraiseRuntimeError: FlyDSL HGEMM policy ... has no kernel for gfx1250.black --check(26.10.1) andruff check(0.16.0) on the changed files: clean.Documentation
Dependencies
Breaking Changes
flydsl_gemm_a16w16_tdmno longer acceptssplit_k_atomicandsplit_k_policy._ptdma_/_ptdmia_still parse; they now run the FP32 reduction.PR Self-Review
Reviewed revision
2b070061dBehavior and intent
On gfx1250, TDM HGEMM with split_k > 1 now reduces FP32 partials in a cluster in a fixed order; before, partials were rounded to BF16 or added with BF16 atomics in arrival order, which loses precision and (for the atomic path) is not deterministic. The tuner races TDM and FT/HT for same-dtype output; before it raced TDM only. 111 DSV4.1 rows and 5 Qwen 3.5 rows select the TDM kernel. A gfx1250-strict runtime skips TDM rows instead of raising.
Validation and unverified scope
Validated on one gfx1250 machine (256 CUs), FlyDSL 0.5.0: the commands and results under Testing, and the same-session A/B under Performance (
ab.py rows|barrier|qwen|stress, results posted in the measurement comment).Remains unverified (not run):
op_tests/test_flydsl_hgemm.pywas not rerun at2b070061d; that revision only moves the architecture check and changes two test lines, and the checks under Testing cover the moved check.usvalues in the CSV are from the earlier tuning sessions.PR-specific question
Workload keys that consume the configuration changes: 111 keys in
dsv41_bf16_tuned_gemm.csvand 5 keys inqwen3_5_397b_bf16_tuned_gemm.csv. All aregfx1250, 256 CUs, BF16 input and output, no bias, no scaling, no preshuffle. The DSV4.1 keys are listed with their before and after times in the measurement comment; the Qwen keys are M 1, 2, 4, 8, 16 with N 128, K 4096.Unrelated shapes keep their previous selection:
gfx1250-strictruntime the five Qwen keys change behaviour: they raised inflydsl_hgemm, and now the lookup skips the TDM row and the default path runs. The 111 DSV4.1 keys fall back the same way there.Selection boundary of the changed kernel: TDM runs only on a
gfx1250runtime, for BF16 or FP16 input with the same output dtype,k_waves= 1, and a tile thatvalidate_gemm_gfx1250_configaccepts. The name parser rejects any other name andflydsl_hgemmraises for any other runtime or dtype. FP32 output keeps the FT/HT path.Changed op tests
op_tests/test_flydsl_hgemm.py:test_hgemm_tdmandtest_hgemm_tdm_tunedrun the TDM kernel directly and through the tuned dispatch for both schedules and for split_k 1, 3 and 8 with guard pages;check_tdm_contractschecks rejected inputs and that fractional partials survive the FP32 workspace (the old same-dtype partials rounded them away);run_torch_tdmis their reference. They are the only on-device coverage of the new reduction.op_tests/tuning_tests/test_a16w16_tuned_config_lookup.py: name round-trips fortdm/tdmiand the mapping of removed names; the catalog contains both backends, with one concrete name of each; every TDM row in the CSVs routes to the TDM wrapper on gfx1250 and is refused on gfx1250-strict; the lookup skips a borrowed TDM row on gfx1250-strict. At2b070061dthe strict-runtime case matches the single gate's message, and the assertion about the never-shipped_gm0_i{0,1}_pspelling is gone. None of this is covered elsewhere.