[CK_TILE] FMHA bwd: unify gfx1250 deterministic on the persistent kernel #14750
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #14750"
general
weight: 0.35
DDEle
JIRA ID : AICK-2309
Motivation
Deterministic FMHA backward on gfx1250 ran 1.5-2.7x slower than the non-deterministic kernel. The
gap comes from four issues, none of them inherent to the persistent algorithm. This PR fixes them,
which brings deterministic within 1.2-1.45x of non-deterministic. It also makes
d_sinkbit-reproducible in deterministic runs.
Technical Details
Persistent deterministic kernel on gfx1250
1. dQ write path. The
tdm_kr_ktrpipeline has a tuned schedule (kTunedSched) that defers eachtile's dQ atomics into the next tile's gemm_0 and issues them from one base VGPR plus immediate
offsets. It excluded deterministic, dropout, alibi, hdim 32/64/256 and padded hdim. On the generic
path every atomic recomputes its address into the same VGPR and waits on
s_wait_xcnt(246 waits vs 5 in the tuned d128 kernel). All of these now use the tuned schedule. Elementwise
bias stays out, because its LDS tile aliases the double-buffered dS.
2. Padded hdim. With padding, each dq_acc row is padded to the tile hdim (
kPadDqAccRow, withDqAccHdim()sizing the workspace), so the tuned dQ window still covers whole rows. ConvertQGradgets a matching template parameter, set by codegen for TDM tiles.
The SWDEV-559729 dummy dependencies pinned both dK/dV accumulators; in the persistent kernel this
spilled into the hot loop. The TDM dK/dV store has no divergent branches, so they are dropped
there, which removes all scratch use in the padded kernels.
3. hdim 32. Two workgroups fit on a CU, so the persistent kernel now runs two workers per CU
(
kPersistentWorkersPerCu, plumbed throughFmhaBwdWorkspaceManager/FmhaBwdPrepareWorkspaceKernel).4. Group mode. The dq_acc batch offset was loaded from the workspace into a VGPR, which made the
buffer descriptor divergent, so every atomic ran a
readfirstlanewaterfall loop. It is now madewave-uniform with
amd_wave_read_first_lane.Deterministic
d_sink.fmha_bwd_dot_do_ostores one partial sum per block in the workspace, andthe partials are folded in a fixed order. The fold is done by
fmha_bwd_convert_dq, or by the lastOGradDotO block of each head for kernel sets without it. The launcher sizes the extra workspace
(
fmha_bwd_traits::has_sink_grad).Other changes
s_nop(compiler hazard workaround).g:mask's second value is now parsed, and the reference alignswindow_genericto the bottom-right like the kernel.fmha_bwd_capturerepeats the validation run and checks that the results are bitwise identical.DeterministicRepeatandDeterministicSink.Non-gfx1250 kernels are unchanged apart from the wave-uniform offset in deterministic kernels. The
gfx90a non-deterministic kernels are instruction-identical to the previous revision.
Performance (gfx1250, bf16, b2 h32, median of 4 interleaved runs, ms)
| shape | non-det before | non-det after | det before | det after | det speedup | det / non-det after |
|---|---|---|---|---|---|---|
| d32 s8192 | 1.36 | 1.27 | 2.08 | 1.52 | 1.37x | 1.20 |
| d32 s8192 causal | 0.81 | 0.77 | 1.58 | 0.95 | 1.66x | 1.24 |
| d64 s8192 | 2.82 | 2.66 | 4.51 | 3.29 | 1.37x | 1.24 |
| d64 s8192 causal | 2.10 | 1.69 | 2.67 | 2.26 | 1.18x | 1.34 |
| d96 (padded) s8192 | 4.93 | 4.44 | 12.61 | 5.34 | 2.36x | 1.20 |
| d96 (padded) s8192 causal | 3.18 | 2.56 | 3.97 | 3.35 | 1.19x | 1.31 |
| d128 s8192 | 4.03 | 4.03 | 8.59 | 5.47 | 1.57x | 1.36 |
| d128 s8192 causal | 2.48 | 2.49 | 5.05 | 3.37 | 1.50x | 1.36 |
| d128 s16384 | 15.81 | 15.83 | 34.21 | 21.90 | 1.56x | 1.38 |
| d200 (padded) s8192 | 14.57 | 12.33 | 28.13 | 17.71 | 1.59x | 1.44 |
| d256 s8192 | 14.21 | 12.41 | 27.40 | 17.85 | 1.53x | 1.44 |
| d256 s8192 causal | 12.73 | 7.66 | 15.75 | 11.35 | 1.39x | 1.48 |
| d128 sink s8192 | 4.04 | 4.04 | 8.59 | 5.49 | 1.57x | 1.36 |
| d128 GQA 32:8 s8192 | 4.03 | 4.03 | 8.58 | 5.48 | 1.57x | 1.36 |
| d128 dropout 0.1 s8192 | 10.83 | 6.74 | 11.65 | 7.86 | 1.48x | 1.17 |
| d128 alibi s8192 causal | 4.53 | 2.96 | 5.32 | 3.65 | 1.46x | 1.23 |
| d128 group s8192 | 4.03 | 4.03 | 10.96 | 5.47 | 2.00x | 1.36 |
| d128 group s8192 causal | 2.66 | 2.66 | 6.31 | 3.41 | 1.85x | 1.28 |
No non-deterministic shape got slower. Dropout, alibi, hdim 256 and padded hdim are 1.1-1.8x faster,
since they now use the tuned schedule too. gfx950 performance is unchanged (within ±0.3% on batch
shapes); group-mode deterministic is 3-6% faster there.
Test Plan
tile_example_fmha_bwd -v=1on 1152 configurations:- hdim 32/64/96/128/256 and padded 40/72/100/120/200, plus d≠d_v
- masks none, top-left and bottom-right; batch and group; GQA; alibi; sink
- dropout, checked with storerandval instances
test_ck_tile_fmha_bwd_bf16, the full suite once, plus the deterministic suites 5 times.Test Result
DecodeDropouttests, which need thestorerandvaldecode instancesthat receipt 2 does not build. They fail identically without this change.
wave-uniform offset.
Submission Checklist