← Back to Pull requests

[CK_TILE] FMHA bwd: unify gfx1250 deterministic on the persistent kernel #14750

Closed
unknown closed this pull request without merging on Nov 09, 2026 17:26 UTC
View on GitHub
unknown unknown commented on Oct 30, 2026 10:38 UTC
Author

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_sink
bit-reproducible in deterministic runs.

Technical Details

Persistent deterministic kernel on gfx1250

1. dQ write path. The tdm_kr_ktr pipeline has a tuned schedule (kTunedSched) that defers each
tile'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, with
DqAccHdim() sizing the workspace), so the tuned dQ window still covers whole rows. ConvertQGrad
gets 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 through FmhaBwdWorkspaceManager /
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 readfirstlane waterfall loop. It is now made
wave-uniform with amd_wave_read_first_lane.

Deterministic d_sink. fmha_bwd_dot_do_o stores one partial sum per block in the workspace, and
the partials are folded in a fixed order. The fold is done by fmha_bwd_convert_dq, or by the last
OGradDotO block of each head for kernel sets without it. The launcher sizes the extra workspace
(fmha_bwd_traits::has_sink_grad).

Other changes

  • A sync between group-mode persistent jobs before LDS reuse.

  • gfx90a: the MFMA->VALU wait states in the IGLP tail are padded with s_nop (compiler hazard workaround).

  • Kernel names are reported from codegen, so they match the generated file names.

  • The g: mask's second value is now parsed, and the reference aligns window_generic to the bottom-right like the kernel.

  • Runner: fmha_bwd_capture repeats the validation run and checks that the results are bitwise identical.

  • New tests: DeterministicRepeat and DeterministicSink.
  • 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

  • gfx1250: tile_example_fmha_bwd -v=1 on 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
  • gfx1250: test_ck_tile_fmha_bwd_bf16, the full suite once, plus the deterministic suites 5 times.

  • gfx950: an example sweep over hdim 32-256, the deterministic suites 3 times, and the full bf16 suite.

  • gfx90a: compile-only ISA comparison of all fp16 instances against the previous revision.
  • Test Result

  • gfx1250: 1152/1152 valid. Full suite: 736 passed. Deterministic suites: 68/68 passed in each of 5 runs.

  • gfx950: sweep 265/265. Deterministic suites: 68/68 passed 3 times. Full suite: 730 passed.

  • The only failures are the 16 DecodeDropout tests, which need the storerandval decode instances

  • that receipt 2 does not build. They fail identically without this change.
  • gfx90a: 321 non-deterministic kernels identical. The 250 deterministic ones differ only by the

  • wave-uniform offset.

    Submission Checklist

  • Look over the contributing guidelines at https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: DDEle Review duration: 14808m
    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
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%