Skip to content

sdwa_diff: generate the two SDWA forms main now translates (fixed by #2187, #2209) in every run - #3331

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
Vonsek:vonsek4/sdwa-diff-known
Nov 23, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
Vonsek:vonsek4/sdwa-diff-known

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

EGEN-SDWA-DIFF-KNOWN (Vonsek4). Finding: #3047 (posted with the claim)

tools/sdwa_diff.py leaves the forms in KNOWN_DIVERGENCES out of every default run, so that a run shows only new problems. Two of the three are no longer divergences on main:

Leaving them out meant the fuzzer could no longer catch a regression of either fix. This PR removes them from KNOWN_DIVERGENCES and from the generator's filter, so default runs generate them again. Only #2005's constant shift amount with src0_sel/sext stays known; that PR is still open.

Tests

  • New: tests/test_sdwa_diff.py::Generator::test_forms_main_translates_again_are_generated_by_default. KNOWN_DIVERGENCES must be {"shift-const-sel"}, and a default batch must contain both forms. The existing test_known_divergences_are_left_out_by_default now expects them in default runs.
    • Without the change (tools/sdwa_diff.py from main, python -I tests/test_sdwa_diff.py Generator): 2 of 3 fail.
    • With the change: python -I tests/test_sdwa_diff.py gives 21 OK.
  • Fuzz runs on main f847748c with this branch's generator:
    • python -I tools/sdwa_diff.py --programs 3000 --seed 81504 --family all: 2833 pass, 0 mismatch, 167 skipped. The skips are the existing reasons: the f16 NaN rules, and the output modifier on v_cvt_f16_{u16,i16}.
    • python -I tools/sdwa_diff.py --programs 2000 --seed 81505 --family all --oracle translator,hw: 1970 pass, 0 mismatch, 30 skipped. Hardware: natively on AMD Radeon Graphics (RDNA2 gfx1036, the iGPU of a Ryzen 9 9950X3D), AMD Windows driver 32.0.21045.16010. The translator side runs on the CPU interpreter, so no Vulkan GPU is needed.
    • For comparison, --known on main gives 7 mismatches in 1,500 programs, all constant-shift v_lshlrev/v_ashrrev (rdna2spirv: keep the SDWA src0_sel on a constant shift amount #2005).

Notes

AI-assisted.

KNOWN_DIVERGENCES kept two forms out of every default run: 16-bit results
with dst_sel:DWORD and f16 float inline constants with a src_sel. ItsNotRexed#2187 and
ItsNotRexed#2209 fixed both on main, so leaving them out only hides a regression of
those fixes. Only ItsNotRexed#2005's constant-shift form stays known.
@tylerstraub

Copy link
Copy Markdown
Contributor

Replying to @Vonsek.

CPU generator review at af752465. All three Generator tests passed on the submitted head. I then repeated them with two independent changes to default generation in emit:

Change to f16 inline constants Generator tests
Force only source 0's selector to DWORD 3/3 pass
Force only source 1's selector to DWORD 3/3 pass

Either change loses coverage for one operand. The new assertion looks for a constant anywhere on the line and checks only source 0's selector. The existing parsed assertion accepts a match on either operand. Could the regression collect the source indices for which the same operand is a float constant and its selector is non-DWORD, then require both indices in the default batch? Each single-source change above should then fail the test.

This is a test coverage finding. The earlier BYTE_1 readback on #3220 illustrates why these selector cases matter on a GPU. These two checks exercised only the CPU generator. AI-assisted review.

AI-assisted.

@bobcatchris

Copy link
Copy Markdown
Contributor

Verified on origin/main 16282101, Windows 11, Python 3.12.0, CPU only — the two tests pin the change and nothing else moves.

  • python -IB tests/test_sdwa_diff.py on this branch → OK.
  • Control (tool reverted to main, test kept) → 2 failures, exactly the two that name the behaviour: test_forms_main_translates_again_are_generated_by_default and test_known_divergences_are_left_out_by_default. So the pair really does separate the generated forms from KNOWN_DIVERGENCES, which is the thing the board finding was about.

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

Both SDWA forms are translated on main since #2187 and #2209 (tools/rdna2spirv.py:486-496, 4583), so putting them back into default runs is right. The new test, which fails on the merge base, guards against them being filtered out again (21 OK here). AI-assisted review (Claude Code).

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@tylerstraub thanks, good catch (Vonsek4). test_forms_main_translates_again_are_generated_by_default now parses each line and collects, per source position, the cases where that operand is a float constant and its own src<i>_sel isn't DWORD. It requires both positions, {0, 1}, in the default batch.

I re-ran your two sabotages on emit:

Sabotage Generator tests
Force only source 0's selector to DWORD for a float constant 1 failure
Force only source 1's selector to DWORD for a float constant 1 failure
Unchanged python -I tests/test_sdwa_diff.py: 21 OK

Pushed as 16076f3f.

AI-assisted.

@tylerstraub

Copy link
Copy Markdown
Contributor

Replying to @Vonsek.

Verified the fix on Linux at 16076f3f. In the default seed-1 batch of 2,500 instructions, I counted 77 f16 inline constants with their own non-DWORD selector at source 0, and 47 at source 1. All 21 tests passed.

Forcing only source 0’s float constants to DWORD changed those counts to 0 / 47. Forcing only source 1’s changed them to 77 / 0. In each run the new assertion was the only failing Generator test, and it named the missing position. That resolves my earlier coverage finding.

AI-assisted.

@ItsNotRexed
ItsNotRexed merged commit a718fe8 into ItsNotRexed:main Nov 23, 2026
1 of 4 checks passed
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.

5 participants