Skip to content

rdna2spirv: write out a carry-out subtract of a register from itself (AMD Windows driver crash) (OLD-10058) - #1093

Closed
LewisCodesWebsites wants to merge 1 commit into
ProjectLeonida:mainfrom
LewisCodesWebsites:carry/old-10058
Closed

LewisCodesWebsites wants to merge 1 commit into
ProjectLeonida:mainfrom
LewisCodesWebsites:carry/old-10058

Conversation

@LewisCodesWebsites

Copy link
Copy Markdown

Claimed in the coordination issue as: OLD-10058 (#14)

Supersedes: #324 (carries forward old PR 10058 by @wail-arch, rebased onto main 3aa9754; their commit and authorship are kept, the only change is resolving a docs/design.md conflict by adding the new contract row next to main's current pc-tail row)

What and why

v_sub_co_u32 / v_subrev_co_u32 (and the _ci_ forms) with the same register as both sources were translated to OpISubBorrow %x %x, and AMD's Windows driver crashes (0xC0000005 in amdvlk64.dll) creating a native wave64 pipeline in which that borrow predicates a subgroup shuffle. x - x is always 0 with no borrow, so this writes the result out directly. It is the same crash as my finding in #14.

Tested

  • python -I tools/crosslane_fuzz.py --ext --dpp --wave 64 --modes native --w64-native --no-maskdata --programs 1000 --seed 20261124: main gives 6 harness errors (exit 3221225477, all in amdvlk64.dll at the same offset); this branch gives 0 (999 match, 1 hyp_only).
  • The reduced 7-instruction reproducer from my finding in Coordinating who works on what #14 crashes on main and runs with 0 mismatches on this branch.
  • tests/semantic/test_sub_co_same_operand.py: 6/6. scripts/run_semantic_tests.py tests/semantic: 6173 of 6174 pass; the one failure, test_image_cube_store_glc, fails the same way on main on this machine (FileNotFoundError launching a tool at line 282), so it is unrelated.
  • tests/test_docs_design_rows.py, tests/test_docs_table_rows.py, tests/test_docs_links.py, tests/test_text_write_line_endings.py: OK.

GPUs tested: AMD Radeon 660M (RDNA2 iGPU, gfx1035), Adrenalin 32.0.21045.1000 (Vulkan driver 2.0.353), Windows 11 26200

AI-assisted: yes (Claude and OpenCode ran the rebase and the tests; I reviewed them)

Checklist

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption, including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

🤖 Generated with Claude Code

https://claude.ai/code/session_015pRhqKwVhndiVZH8fawThh

…(AMD Windows driver crash)

v_sub_co_u32 / v_subrev_co_u32 and their _ci_ forms with the same operand
twice were translated to OpISubBorrow %x %x. AMD's Windows driver dies with
an access violation (0xC0000005 in amdvlk64.dll, 32.0.21037.1004 and
32.0.21045.29003, gfx1036) creating a native wave64 compute pipeline in which
that borrow predicates the value operand of an OpGroupNonUniformShuffle.

x - x is 0 with no borrow, so these forms now emit D = 0 - carry in and
borrow out = carry in, with no OpISubBorrow. Values are unchanged; other
operand pairs are translated as before.

Found with crosslane_fuzz.py --seed 880317 --wave 64 --w64-native
--no-maskdata --dpp --ext --programs 400 on a Ryzen 9 9950X3D iGPU:
programs 1 and 181 were harness errors (exit 3221225477) and now match
(399 of 400 match; the other differs only in a hypothesis op, as before).

- docs/design.md: contract row "Carry-out subtract of a register from itself"
- tests/semantic/test_sub_co_same_operand.py: values and borrow mask in
  wave32 and native wave64, the emitted form with --wave64-emulate

Not counted over the corpus, and two different registers holding equal
values still reach OpISubBorrow.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@tiguan26

Copy link
Copy Markdown
Contributor

Checked a17d0e7 merged into current main (3aa9754): it merges cleanly. Linux, Python 3.13, no GPU, so I could not check the driver crash itself.

  • The new branch is right for the carry-in forms too: x - x - cin is 0 - cin with the borrow out equal to cin, which is what it emits (OpISub 0 cin, carry = cin).
  • tests/semantic/test_sub_co_same_operand.py 6/6; tests/test_docs_design_rows.py, test_docs_table_rows.py and test_docs_links.py pass.
  • Same register through a modifier, where the two reads are not the same value: v_sub_co_ci_u32_dpp v2, vcc, v1, v1, vcc quad_perm:[0,0,0,0] is refused (mask destination) on main and here, and v_sub_co_ci_u32_sdwa v2, vcc, v1, v1, vcc ... src0_sel:WORD_1 src1_sel:WORD_0 gives the same words on this branch as on main, so the shortcut does not change those.

That SDWA check turned up a separate bug on main, not caused by this PR: for v_add_co_ci_u32, v_sub_co_ci_u32 and v_subrev_co_ci_u32 the SDWA source selects land one operand early (insn() starts them at args[1], which is the carry-out vcc for these ops), so src0_sel is dropped and src1_sel narrows src0. I'll post it in #14 separately. Once that is fixed, srcs[0] == srcs[1] stays safe, since two reads with different selects carry different sdwa_sel and compare unequal.

AI-assisted (Claude).

@KernelSmoker KernelSmoker 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.

Reviewed exact head a17d0e7. The focused semantic suite passed 6/6; generated same-operand wave32 SPIR-V passed spirv-as and spirv-val for Vulkan 1.2. I also built this PR's vk_compute_test target and ran the synthetic wave32 shader on an NVIDIA GeForce RTX 3090 (subgroup 32). All 32 dispatched lanes / 96 output words matched the fixture: active-lane D values, carry-in borrow bits, and wave mask popcount 2. This validates the translated shader behavior on NVIDIA; it does not reproduce or validate the reported AMD Windows driver crash. PR is GitHub-mergeable at review time.

@Deedlyy

Deedlyy commented Nov 24, 2026

Copy link
Copy Markdown

Recommendation: [MERGE]

Reasoning: Fixes the AMD Windows driver crash by emitting x - x (and the carry-in forms) as a constant zero/borrow instead of OpISubBorrow %x %x, carrying #324 with authorship kept. Small translator change with a 194-line semantic test; independently checked by tiguan26 (merge into main, semantic logic) and KernelSmoker (spirv-val plus RTX 3090 readback). The AMD crash itself has not been reproduced by a second person. #324 can be closed once this lands. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with main. Merge once the queued checks are green.

Impact level: 5/10

@adrianmjim

Copy link
Copy Markdown

Tested a17d0e7 applied onto main 66d4f5a on an AMD Radeon RX 7900 XT. This is a discrete RDNA3 card on the current proprietary driver, a different one from the gfx1035/gfx1036 iGPUs where the crash was measured. Setup: AMD Radeon RX 7900 XT (RDNA3, gfx1100), AMD proprietary driver 32.0.32029.2010 (26.11.2), Windows 11 build 26300, VS 2022 RelWithDebInfo, Vulkan SDK 1.4.363.0, llvm-mc 23.1.5. No game files.

The PR's repro on the GPU. tools/crosslane_fuzz.py --seed 880317 --wave 64 --w64-native --no-maskdata --dpp --ext --programs 400, with vk_compute_test from a main build and --translator pointing at each tree:

wave64 native wave64 emulate
main 66d4f5aa3 400 match, 0 mismatch, 0 harness errors 400 match, 0 mismatch, 0 harness errors
this PR 400 match, 0 mismatch, 0 harness errors 400 match, 0 mismatch, 0 harness errors

The amdvlk64.dll crash does not reproduce here: main already runs programs 1 and 181 of this seed without a harness error. So on this card and driver the change makes no visible difference, and it causes no regression.

CPU check. tests/semantic/test_sub_co_same_operand.py passes 6/6 on the PR. Copied onto main, it fails only its 24 assertNotIn('OpISubBorrow', ...) subtests, and every value check passes. So the new lowering gives the same results as the old OpISubBorrow chain, as expected for x - x.

@aslan2142

Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants