Repository navigation
rdna2spirv: emit OpBitFieldUExtract for the VOP3 16-bit result mask (NVIDIA And-&-0xFFFF miscompile) - #1585
rdna2spirv: emit OpBitFieldUExtract for the VOP3 16-bit result mask (NVIDIA And-&-0xFFFF miscompile)#1585whoalin1 wants to merge 4 commits into
Conversation
|
Independent RTX 4090 check of the conversion changes in One scope detail for the PR description: the shared result mask also changes the SPIR-V for I dispatched synthetic wave32 compute shaders with runtime inputs and checked the full 32-bit destination against a CPU reference:
0 mismatches across 327,680 outputs on each revision. All five GPU buffers were byte-identical between revisions, and all ten translated modules passed |
|
Heads-up from a test run on an RTX 4070 SUPER: the code part looks fine, but merged onto current main this PR fails AI-assisted (Claude Code, Claude Opus 5.5). |
|
Thanks — fixed in |
…NVIDIA And-&-0xFFFF miscompile) NVIDIA's shader compiler (RTX 4070 SUPER, wave32) corrupts the preserved high half of a 16-bit VOP3 result when OpBitwiseAnd & 0xFFFF consumes a value that passed through %int ops and the result merges with (old & 0xFFFF0000): v_add_nc_i16 v14, v3, v12 op_sel:[1,1,0] clamp wrote 0x1113AAA8 for 0x0002AAA8. BitFieldUExtract reads the same low 16 bits and dodges the peephole; SClamp on %int and select-based clamps do not. AMD (gfx1036, Vulkan and hw_oracle) and the CPU interpreter are unaffected. Co-Authored-By: Devin <noreply@cognition.ai>
…nd d16 saturate The review of 97535ad found three more OpBitwiseAnd & 0xFFFF sites whose operand is an %int-derived bitcast feeding a preserve-high-half merge, the same shape NVIDIA's shader compiler miscompiles: - v_cvt_i16_f16: OpConvertFToS %int -> Bitcast -> And, then write_lo16 or the op_sel merge (the u16 sibling is %uint and safe) - v_cvt_norm_i16_f16: the snorm path has the same structure (unorm safe) - saturate_int16 signed path: SClamp %int -> Bitcast -> And reaches the preserve merges through the d16 image/buffer stores All emit OpBitFieldUExtract %uint x, 0, 16 instead, spec-identical. Audited every remaining And & 0xFFFF site: the rest are %uint-derived, operand-side, packed-Or consumers, or constant masks. RTX 4070 SUPER spot-checks of v_cvt_i16_f16/v_cvt_norm_i16_f16 (VOP2 form; llvm-mc rejects op_sel on these) produce the right words on both the old and new modules, so the bug does not reproduce on this shape; the extract removes the risky pattern regardless. Full semantic suite: 487 files, 6279 tests, 0 failures. Co-Authored-By: Devin <noreply@cognition.ai>
The literal pipe in the NVIDIA workaround row made tests/test_docs_design_rows.py read the row as having more cells than the contract table header. Co-Authored-By: SWE-2.1 Max <noreply@google.com>
|
@QemmHD thanks for the catch. Rebased onto current main ( |
42ad738 to
69b363d
Compare
|
Useful scope data point from Sangonapou (coordination issue): the high-half corruption does not reproduce on Ampere (RTX 3080 Ti Laptop, 621.24) — 384/384 single-op cases match RDNA2. That is consistent with this PR's evidence, where the miscompile showed on Ada (RTX 4070 SUPER) with the surrounding fuzz-program instructions, and points at an Ada-generation compiler issue rather than something universal. Either way the transform here is bit-identical semantics on every device — |
|
Follow-up verification on the current head 69b363d under the local coordination lock: |
|
Hi @whoalin1, thanks for this pull request. CONTRIBUTING.md asks contributors to claim their work in the coordination issue ("Coordinating who works on what", currently #1608) before opening a pull request: post The claim matters because "it is claimed in the coordination issue by the pull request's author" is the first item on the maintainers' checklist for a mergeable pull request, and because it lets others see that the work is taken before they write it a second time. Could you post the claim in #1608 and put its ID (or a link to it) on the pull request's "Claimed in the coordination issue as:" line? If you already claimed it in another form, a link to your comment is enough. AI-assisted (Claude Code, Claude Opus 5.5). |
|
Thanks for this! Writing the VOP3 16-bit result mask as During maintainer testing (local, 2026-11-28) (head 69b363d, merged on main b1619e0 / 6dfca64, Windows 11, Python tests via pytest/unittest) we found:
To get this merged:
AI-assisted (Claude Code), posted for DadaCap (maintainer). |
|
The commit now on this PR incorporates the patch for the maintainer’s test-regex review. Its Git tree matches the originally tested patch exactly. I also merged it locally onto main It changes the two semantic tests. Both now require the low-half extract to start at bit 0 and take exactly 16 bits. The add test targets the value stored in I checked two cases that distinguish the old and revised tests:
Both example modules passed SPIR-V validation for Vulkan 1.2. All 23 tests in the two affected files passed on the patched head. This supplies the requested test change. It adds no hardware evidence about the reported driver miscompilation. Coordination claim. AI-assisted with OpenAI Codex (GPT-6). Integration check after #2593. I merged this exact head ( |
|
I did not reproduce the preserved-high-half corruption on physical gfx906 (RADV Mesa 26.0.8, native wave64). Main The structural change is present: in the sampled modules, 16 integer result sites and six conversion result sites changed from AND-with-65535 to an extract at offset 0, width 16. These were result paths feeding stores, not source-operand extracts. Removing just the clamped add’s result mask in a test-only module produced 25 wrong lane words, so the readback really checks the preserved half. The test-width concern is independent of the driver result: AI-assisted. |
|
For the maintainer’s hardware question, I could not reproduce the signed add/subtract corruption on a desktop RTX 4090, Windows, NVIDIA 616.64, Vulkan subgroup 32. This covers the add/subtract case that the earlier conversion sweep left open. I compared main
This was an independently constructed shader around the reported instruction. The full failing shader and driver version from the RTX 4070 SUPER would help distinguish a driver difference from a surrounding-code difference. AI-assisted verification with OpenAI Codex (GPT-6). |
Check offset zero and width 16 on the product and the value stored by the signed sum. Ignore unrelated extracts in the fragment. AI-assisted with OpenAI Codex (GPT-6).
|
#1585 | head 599de2f (merged cleanly onto origin/main 791899f) | Windows 11 (10.0.26200.9974), Python 3.12.10 | AI-assisted: yes Independent Verification (Windows 11)
|
|
Ready for testing: merges cleanly with AI-assisted (Claude Code). |
Finding from the overnight fuzz campaign (coordination issue #14 — the issue's comment thread is currently at its cap, so context lives here): on NVIDIA'''s shader compiler,
OpBitwiseAnd %uint X, 0xFFFFmiscompiles whenXis a value that passed through%int-typed ops and the result feeds a preserve-high-half merge(old & 0xFFFF0000) | lo— the kept high half comes out corrupted while the low half is fine. Measured on an RTX 4070 SUPER (Windows, wave32):v_add_nc_i16 v14, v3, v12 op_sel:[1,1,0] clampwrote0x1113AAA8for the correct0x0002AAA8.OpBitFieldUExtract %uint X, 0, 16is spec-identical (zero-extended low 16) and does not trigger the miscompile. This PR emits it at every site where an int-derived value is masked for a preserved-16-bit-half merge:v_add/sub_{nc_,}{i16,u16}, the_rev/shift forms,v_mul_lo_u16,v_{min,max}_{u16,i16},v_mad_{u16,i16},v_{min,max,med}3_{u16,i16})v_cvt_i16_f16/v_cvt_norm_i16_f16conversions (aBitcastof an%intOpConvertFToS)saturate_int16feeding d16 image/buffer stores (aBitcastof an%intSClamp)The unsigned/unorm siblings, the
v_pk_*packed paths, and the f16put_f16_bitsidiom were audited and deliberately left: they either produce%uint-only values or build a packed dword rather than a preserve merge.Scope note (thanks @ecox982745): because the signed and unsigned conversions share the result-mask helper, the emitted SPIR-V for
v_cvt_u16_f16andv_cvt_norm_u16_f16also gains oneOpBitFieldUExtracteach (like their signed siblings), andv_cvt_pk_i16_i32gains two through the signed saturation helper, one per packed operand. These are the same spec-identical zero-extended-low-16 rewrite at zero cost; ecox982745's independent RTX 4090 sweep of all 65,536 binary16 encodings for each ofv_cvt_{i16,u16}_f16/v_cvt_norm_{i16,u16}_f16plus 65,536v_cvt_pk_i16_i32input pairs found 0 mismatches in 327,680 outputs per revision, with all GPU buffers byte-identical between revisions.Verification
0x0002AAA8;v_sub_nc_i16 … clamp0x0002AAAC; 160 randomizedv_add/sub_nc_i16programs across allop_sel/clampcombos — 0 mismatches vs a Python reference.v_cvt_i16_f16/v_cvt_norm_i16_f16spot checks produce correct results on both old and new SPIR-V (the miscompile did not reproduce on that shape, but the extract removes the risky pattern at zero cost).--pc-tail-ubo,LEONIDA_PC_TAIL_UBO=1): repro, sub-clamp, mad_i16, min3 cases all match NVIDIA/reference — no AMD regression (the op is spec-identical).python -I scripts/run_semantic_tests.py tests/semantic— 487 files / 6,279 tests, 0 failures. Two tests that pinned theOpBitwiseAnd … 0xFFFFshape were updated to the extract form with their negative controls intact.compileallclean; the changed ops all passspirv-val.docs/design.mdcontract-table row forv_add_nc_i16/v_sub_nc_i16documents the workaround, the trigger shape, and the confirmation method.Independent review: initial pass found three missed sites of the same idiom (now covered); re-review confirmed the six-site coverage is exhaustive against a full census of
And … 0xFFFFemit sites.AI-assisted (Devin).