← Back to Pull requests

fix(hip-kernel-provider): close ASM SDPA forward gaps left by #16302 #16450

Closed
unknown closed this pull request without merging on Nov 21, 2026 21:21 UTC
View on GitHub
unknown unknown commented on Nov 20, 2026 19:10 UTC
Author

Summary


Follows #16302 (merged as 30b361c538e). This PR makes the ASM SDPA forward engine decline graph layouts it cannot run correctly, and runs its applicability tests on CPU CI:

  • Group-mode stats with more than one head now need a head stride of at least B S_q.

  • The engine declines Q/K/V/O layouts its argument block cannot carry: a head-dim stride other than 1, a sequence stride below the tensor's own head dim, and an O that overlaps itself.

  • IsApplicableSdpaVariations, IsApplicableRaggedVariations, IsApplicableRaggedOffsetContract, IsApplicableCuSeqLenContract, IsApplicableStatsLayoutFollowsBatchMode, the head-dim truncation test and the 32-bit limit tests moved to TestSdpaFwdPlanBuilderOnArch and now run on CPU CI for gfx942 and gfx950, alongside the new IsApplicableDeclinesUnaddressableIoLayouts. The other forward applicability tests and the engine ranking test still need a matching GPU.
  • JIRA ID : ALMIOPEN-3366

    Also addresses ALMIOPEN-3378, ALMIOPEN-3041, ALMIOPEN-3042, ALMIOPEN-3182, ALMIOPEN-3329 (forward half) and ALMIOPEN-3361 (gap 1).

    Not in this PR:

  • fp8 causal with S_q > 256 on gfx942 (ALMIOPEN-3392, ROCm/aiter#7593): handled in a separate change by its assignee.

  • The hd128 (and wider) forward base-offset carry bug for tensors of about 4 GiB or more: drafts exist; it gets its own PR after a GPU reproduction.

  • ALMIOPEN-3329 backward half (dQ/dK/dV overlap).
  • Risk Assessment


    Risk 2 of 5. The engine only declines more graphs; no graph it still accepts changes kernel, arguments or launch. A declined graph falls through to the next engine when one serves it; on gfx942 and gfx950 a declined group-mode stats graph may have none, because FlyDSL declines head-major stats for H > 1 and the dense and unified engines decline ragged operands. Each new decline covers a graph the engine computed wrongly or wrote to the wrong place, or a graph the same rule cannot tell apart from one:

  • Group-mode stats with H > 1 and a head stride below B S_q, including 0. S_q is only a necessary lower bound: the frontend's default ragged stats strides [H S_q, S_q, 1, 1] meet it, yet with B > 1 a batch at offset S_q or later writes the next head's LSE (B = 2, H = 8, S_q = 256, offsets [0, 256, 512]: batch 1 / head 0 and batch 0 / head 1 both write rows 256..511). B S_q is the Q token capacity of a packed table. It declines AITER's packed [H, total_q] layout whenever total_q < B S_q, and such a graph is not guaranteed a fallback (see above). A table whose rows reach past B S_q stays a caller precondition.

  • A head-dim stride other than 1: the kernel treats it as 1.

  • A sequence stride below the tensor's own head dim, including 0: each (batch, head) slice ends early. A K sequence stride of 0 (a broadcast) was measured correct in ALMIOPEN-3182, so its decline is conservative. It is kept because the same rule catches Q/V stride 0 and short rows, which are wrong, and the kernel bounds each buffer at S x sequence stride.

  • An O layout whose elements share an address, over {B, H, S, D} in batch mode and {H, S, D} in group mode: workgroups overwrite each other's output.
  • Every in-tree bundle and integration test builds packed layouts, which none of these rules decline. The only unit tests that met a rule are the 32-bit dimension-limit tests, whose O shared one stride set across batch and head and so overlapped itself; they now keep every non-limit axis at 1, so O stays non-overlapping. Each limit case still turns on its one dimension. The head-dim truncation rows are also declined by the sequence-stride rule, so that test pins the decline rather than the 32-bit gate. The TestContainer test checks that the ASM engine still ranks first for the forward graphs it serves.

    ASIC Coverage


    Scoped to gfx942 and gfx950, the only archs the forward ASM engine serves. Device runs on MI300X (gfx942, MI300/ objects) and MI355X (gfx950) are in the checklist. The applicability rules for both archs also run on any host through TestSdpaFwdPlanBuilderOnArch. The change adds declines only, so it moves no other arch. MI308X (MI308/ objects) was not run: no kernel object or launch changed, and the declines run before any object is selected.

    Testing Summary


  • Applicability on CPU (new for this engine): SdpaFwdPlanBuilder reads the device arch through a virtual deviceArch hook, like maxThreadsPerBlock. TestSdpaFwdPlanBuilderOnArch overrides it and runs over gfx942 and gfx950. The tests listed in the Summary moved onto it, so the cu_seq_len, padding_mask, top-left and stats acceptance from #16302 now fails on CPU CI if a later change declines it again.

  • New applicability tests: IsApplicableDeclinesUnaddressableIoLayouts covers each IO layout rule and its accepted neighbours (padded rows, broadcast Q/K/V, group-mode O batch stride). The dense seq_len_q/kv decline gains rows. IsApplicableStatsLayoutFollowsBatchMode gains:

  • - batch-mode stats rows: an isolating row at B = 4, H = 1 with strides {255, 255, 1, 1}, and boundary rows where head stride 34636824 is accepted and 34636825 declined;
    - group-mode head stride rows: at B = 4, H = 8, a head stride of S_q and of B S_q - 1 is declined and the head-major B S_q baseline is accepted; a one-batch row at S_q, a row below S_q and a zero stride cover the rest.
  • Engine ranking: TestContainer.RanksTheAsmEngineFirstForTheSdpaForwardGraphsItServes.

  • GPU (needs gfx942/gfx950):

  • - StandardGroupCoverage instance of IntegrationGpuSdpaFwdBf16: on every group row that serves GQA, group-mode GQA (Hq = 4, Hkv = 2) with stats, cu_seq_len over edge lengths, and top-left for causal rows, and MQA (Hkv = 1) with stats. Every group row also runs with stats at B = 1, and every causal group row runs top-left with stats through one shared cu_seq_len table.
  • #16302 comment: this PR resolves the comment reporting 16 #15353 bundle cases (12 from the standard and comprehensive tiers, 4 added from the full tier) that ASM accepted and computed wrongly on MI300X: each has a head-dim stride other than 1, or a sequence stride below the head dim or 0, on Q, K, V or O. On MI300X at d00b76b2f53, with #15353's bundle directories (head ca1c7168838) copied into the checkout and no skip entries for them, ASM declined all 16, each for the expected reason: Q sequence stride 64 below head dim 128 (4 cases), K head-dim stride 8 or 32 (4), K sequence stride 0 (4), and V head-dim stride 8 or 32 in the ragged bundle (4).
  • Testing Checklist


  • pre-commit at d00b76b2f53: pre-commit run --from-ref 30b361c538e --to-ref HEAD - Status: Passed

  • clang-tidy at d00b76b2f53: clang-tidy-20 -p <build> SdpaFwdPlanBuilder.cpp TestSdpaFwdPlanBuilder.cpp TestContainer.cpp IntegrationGpuSdpaForward.cpp AsmSdpaConfigHelpers.cpp - Status: Passed

  • Host (gfx1151, so every gfx942/gfx950 device test skips) at d00b76b2f53: hip_kernel_provider_tests --gtest_filter='TestSdpaFwd:TestContainer.' - Status: Passed (130 passed). With the #16302 unit filter at 073532e3fad: 377 run, 305 passed, 72 skipped.

  • Host at 3024ee6556a (comment changes plus one accepted group-stats row): hip_kernel_provider_tests --gtest_filter='TestSdpaFwd:TestContainer.' - Status: Passed (130 passed, 31 skipped); pre-commit and clang-tidy on the two changed files passed

  • pre-commit at da7b45e82cc (comment-only change to the head-dim truncation test): pre-commit run --files TestSdpaFwdPlanBuilder.cpp - Status: Passed

  • gfx942 (MI300X) at 073532e3fad, kernel ingestor ON:

  • - hip_kernel_provider_tests with the #16302 filter - 405 run, 403 passed, 1 skipped, 1 failed (IsApplicableDeclinesHeadDimsThatTruncateToASupportedValue; fixed in d00b76b2f53, see below)
    - hip_kernel_provider_integration_tests --gtest_filter='IntegrationGpuSdpaFwd:IntegrationGpuAsmSdpaForwardRagged' - Status: Passed (199 run, 101 passed, 98 skipped for gfx950; StandardGroupCoverage 20 passed)
    - ASM_SDPA_ENGINE SdpaFwd bundles, quick / standard / comprehensive - Status: Passed (13 / 45 / 50 passed, 0 broken claims, 0 unclaimed), the same counts as #16302
    - ctest -R hip_kernel_provider_integration_tests_quick_suite - Status: Passed (228.1 s of its 300 s timeout, after #15484's backward cases)
  • gfx950 (MI355X) at 073532e3fad, kernel ingestor ON, the same commands:

  • - unit - 405 run, 399 passed, 5 skipped, 1 failed (the same test, same cause)
    - integration - Status: Passed (199 run, 102 passed, 97 skipped for gfx942; StandardGroupCoverage 23 passed)
    - bundles - Status: Passed (6 / 15 / 18 passed, no claim failures; the batch-mode unclaimed_support cases #16302 reported are still unclaimed)
    - quick suite - Status: Passed (204.1 s of 300 s)
  • gfx942 (MI300X) at d00b76b2f53: the 16 #15353 cases from the #16302 comment (12 standard/comprehensive, 4 full), hipdnn_integration_tests --test-engine ASM_SDPA_ENGINE one case at a time with #15353's bundles overlaid - Status: Passed (16 of 16 declined by areFwdIoLayoutsAddressable, none run)

  • Host (gfx1151) at f21f442a9e9 (develop merged): hip_kernel_provider_tests - Status: Passed (1102 passed, 99 skipped; all 18 TestSdpaFwdPlanBuilderOnArch cases pass for gfx942 and gfx950). Mutating the B S_q rule, the IO layout check or the deviceArch call each fails its tests. pre-commit and clang-tidy on the resolved files passed.

  • PR CI - GitHub PR checks - Status: Pending
  • The one device failure was a test bug: IsApplicableDeclinesHeadDimsThatTruncateToASupportedValue built its control graph with one stride set shared by 4 batches and 8 heads, so its O overlapped itself and the new O-overlap decline rejected it. d00b76b2f53 gives each case one batch and one head and moves the test onto TestSdpaFwdPlanBuilderOnArch, where it passes for gfx942 and gfx950 on the host. That commit changes only this test; the device runs above cover the engine at the same source.

    Technical Changes


  • Preconditions (SdpaFwdArgsBuilder.hpp, SdpaFwdLaunchParams.hpp): comments state what the caller must keep that the host cannot check, because only the device holds the offset and length tables: the group-mode LSE base (seqstart_q[b] + len_b <= head stride), each KV length at most S_kv (restoring max_b(kvOffset[b+1] - kvOffset[b])), and which table ptr_qseq reads when cu_seq_len is present.

  • Group-mode stats head stride (checkStatsTensor): with H > 1 the head stride must be at least B S_q, computed as headStride / B < S_q to avoid forming the product. It also declines a zero head stride.

  • IO layouts (checkFwdIoLayouts, isNonOverlappingView): head-dim stride 1, and sequence stride at least the tensor's own head dim. O must not overlap itself, with overflow checks; group mode skips O's batch axis. Rank-4 strides are checked once, in the Q/K/V/O rank-4 loop, before the ragged-addressing and layout checks read them.

  • Device hook (SdpaFwdPlanBuilder::deviceArch): virtual, returns std::optional<std::string> through plan_utils::tryGetDeviceString. Tests override it.

  • Test helpers (AsmSdpaConfigHelpers.{hpp,cpp}): support for the new integration instances.

  • Docs: SEM-026 gains an ASM entry (the ragged layouts it serves, gap rows of O and LSE left unwritten, and the callers' preconditions). SEM-028 calls cu_seq_len cumulative lengths rather than offsets. In the hipdnn-aiter-asm-sdpa-fwd-sync skill, new-values.md cites the v0.1.29 forward pin and records the layout declines a new kernel row must pass; validation.md lists StandardGroupCoverage and the host-runnable applicability tests.
  • Merge with #15148


    #15148 merged first and rewrote isApplicable as Rejection checks. Merge f21f442a9e9 ports this PR onto it: checkFwdIoLayouts, the B S_q rule in checkStatsTensor, and deviceArch() in checkFwdApplicability. Rejection messages are unchanged.

    Still open


  • ALMIOPEN-3361 gaps 2 and 3: overlap between batches depends on the offset values, which only the device holds.

  • Group-mode stats whose offset table puts rows past B S_q: offset-dependent, so a caller precondition.

  • ALMIOPEN-3329 backward half (dQ/dK/dV).

  • The hd128 (and wider) forward base-offset carry bug for tensors of about 4 GiB or more: own PR after a GPU reproduction.

  • ALMIOPEN-3155: the frontend half.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: BrianHarrisonAMD Review duration: 1571m
    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 #16450"
    general weight: 0.35
    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%