Skip to content

Tools: hardware oracle for lds_fuzz — 60,000 LDS programs on real AMD hardware, 0 mismatches; answers SHADER-105 - #1345

Merged
ItsNotRexed merged 5 commits into
ItsNotRexed:mainfrom
AlxcBTW:hw-oracle-lds
Nov 22, 2026
Merged

ItsNotRexed merged 5 commits into
ItsNotRexed:mainfrom
AlxcBTW:hw-oracle-lds

Conversation

@AlxcBTW

@AlxcBTW AlxcBTW commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

This continues the hardware oracle from #1160, #1202 and #1248. It answers SHADER-105 (@edupode).

What and why

tools/lds_fuzz.py (FUZZ-6) gains --oracle hw and --oracle translator,hw. The same seeded LDS programs run natively on an AMD GPU, and every stored word is compared with the model. A run uses wave32 and wave64, real group sizes, EXEC masks and s_barrier, with the LDS size in the kernel descriptor. Until now the LDS model had only been checked against the translator.

  • tools/hw_oracle/asm.py:
    • A per-kernel lds size and vgprs count.
    • GFX11 respelling of ds_*: ds_load_*, ds_store_*, ds_load_2addr*, ds_storexchg_rtn_b32.
    • ds_cmpstore_rtn_b32 takes its operands in swapped order (below). .max_flat_workgroup_size is now 1024 for every kernel; it was 256.
  • tools/hw_oracle/hw_oracle.c: the word limit goes from 4096 to 16384.
  • lds_fuzz.py options: --only, --minimize, --keep, --perturb NAME, --negative-control and --hw-arch. Opt-in op-mix switches are --permute (ds_permute_b32), --swizzle-exec (ds_swizzle_b32 under EXEC masks), --threads 32|64|128|256|mix, and --extended for all three.
  • Default seeds produce identical programs. I checked by fingerprinting asm(), model() and the op list against main, so default translator-mode runs and CI are unchanged.
  • Linux backend (Tools: a Linux backend for the hardware oracle (libdrm_amdgpu), and its first runs on RDNA2 #1265): the oracle returns 77 ("unavailable") on it, because that launcher doesn't support LDS or more than 4096 words yet. On Windows (HIP) it runs.

Results: Radeon 880M (gfx1150, RDNA3.5), driver 26.11.2

run programs (wave32 + wave64) mismatches
default mix, 9 seeds × 2000 36,000 0
--extended, 6 seeds × 2000 24,000 0
the 12 wave32 programs SHADER-105 names (seed 1) 12 0
negative control, 1000 programs 15 deliberately wrong models each one caught, in 126–547 programs
translator vs hardware, default mix, native and --emulate 200 0

SHADER-105: the model matches gfx1150 for every family Intel flagged, under EXEC masks, in both wave sizes and in multi-wave groups. Those families are:

  • the DS atomics, including max_i32/max_u32, with and without return;
  • ds_cmpst;
  • all small reads: u8, i8, u16, i16, and the d16/d16_hi forms;
  • wrxchg, read2/write2 (plain and st64), and the wide reads and writes;
  • ds_swizzle, ds_bpermute and ds_permute.

The Intel mismatches went away with #820's constant-EXEC fix. gfx1150 is not RDNA2.

Findings (gfx1150 only; RDNA2 not measured):

  • GFX11 ds_cmpstore_rtn_b32 takes the store value before the compare value, the reverse of GFX10's ds_cmpst_rtn_b32. llvm-mc encodes both spellings of the same text identically, so only hardware shows it. Without the swap, every program with a cmpst failed, and each minimised to that one op.
  • A masked ds_swizzle_b32 whose source lane is off returns 0, like ds_bpermute. The model is corrected accordingly.
  • The translator differs from gfx1150 there: it returns the source register. This shows in 22 of 177 --extended programs on AMD Vulkan, native and emulated. RDNA2 is unverified and the translator is not changed here.
  • ds_permute_b32 and ds_bpermute behave as modelled in both wave sizes. Only active lanes send, an unwritten lane gets 0, and the two 32-lane halves stay separate.

Overlap: #789 makes ds_permute_b32 part of the default op mix, while this PR keeps it opt-in with --permute. Whichever lands second reconciles them.

Tested

  • py -I tests/test_lds_fuzz_hw.py: 38 tests. tests/test_hw_oracle.py: 24 tests. test_lds_fuzz, test_lds_fuzz_cli and test_crosslane_fuzz pass too.
  • The tests need no GPU. The exit-77 path and the gfx12 skip of ds_cmpst are tested.
  • The hardware runs above. After the review fixes, --oracle hw --extended over 300 programs gave 600/600 matches.

An independent review checked several points:

  • default-seed identity;
  • the LDS descriptor size;
  • EXEC save/restore for partial waves;
  • the exit-77 path;
  • the hard rules.

Its findings are fixed: the Linux-backend crash, a merge with #1265, the SHADER-105 and swizzle wording, gfx12 scoping, and --perturb handling.

AI-assisted (Claude Code).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), 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. (No translator change.)

🤖 Generated with Claude Code

AlxcBTW and others added 5 commits November 22, 2026 11:00
…* respelling, wider op mix, perturbations

hw_oracle: kernels carry their LDS size and VGPR count; ds_* mnemonics and the
ds_cmpstore operand order are respelled for GFX11/GFX12; launcher accepts up to 16384 words.
lds_fuzz: --oracle hw|translator,hw, --permute/--swizzle-exec/--threads/--extended,
--only, --minimize, --keep, --perturb, --negative-control. Default programs unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…only cmpstore swap, perturb scoping, docs wording

Merges ItsNotRexed#1265 (libdrm backend, gfx10_spelling) keeping both raw_kernel_text changes. The kernel
metadata's .max_flat_workgroup_size is now 1024 (was 256) so 256-thread groups launch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bobcatchris

Copy link
Copy Markdown
Contributor

Independent CPU/static verification only (no GPU or hardware-number claim), at head 8a52cbcd against main f85582e2:

  • tests/test_lds_fuzz_hw.py + tests/test_hw_oracle.py: 57 passed, 6 skipped; compileall -q tools tests clean.
  • Negative control: the PR's new test file on untouched main gives 35 failed, 22 passed, 6 skipped. The failures are exactly the new contracts: asm.ds_line, asm.ds_mnemonic, and Kernel(..., lds=, vgprs=) / raw-kernel LDS metadata are absent before this PR.
  • A tool-discovery path hit the sandbox-blocked reg.exe; the suite still passed through its Unavailable branch. No retry or bypass.
  • Not verified here: the 60,000-program AMD LDS run or the reported zero-mismatch result.

Coordination note: this PR and #1365 both edit Kernel, raw_kernel_text, metadata and module_text in tools/hw_oracle/asm.py. git merge-tree --write-tree 8a52cbcd eef40049 reports a content conflict in that one file; both heads merge cleanly with #1373. Whichever lands second should rebase over the first.

@ItsNotRexed
ItsNotRexed merged commit 472166e into ItsNotRexed:main Nov 22, 2026
11 checks passed
@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tried 8a52cbc on an AMD Radeon RX 9070 (RDNA4, gfx1201), AMD 26.11.2, rocm-sdk-core 10.0.0 clang. There are two GFX12 points. The second is a measured hardware difference that the oracle has to know about.

1. GFX12 has no s_barrier. Every chunk fails with RuntimeError: the assembler rejected every program in a chunk: ... instruction not supported on this GPU (gfx1201): s_barrier. GFX12 splits it into s_barrier_signal -1 + s_barrier_wait -1, and both assemble. With that respelled locally in raw_kernel_text for fam == "gfx12" (uncommitted), the programs run:

--oracle hw --wave both --programs 1000 wave32 wave64
seed 1 531 match, 0 mismatch, 469 skipped 271 match, 217 mismatch, 512 skipped
seed 2 488 match, 0 mismatch, 512 skipped 270 match, 223 mismatch, 507 skipped

Replacing s_waitcnt lgkmcnt(0) with s_wait_dscnt 0 + s_wait_kmcnt 0 changes nothing (identical counts). On gfx12 the old spelling still assembles, to the legacy S_WAITCNT word 0xBF89FC07. So the waits are not the cause.

2. On RDNA4, wave64 ds_bpermute_b32 addresses all 64 lanes, not two wave32 halves. The wave64 mismatches are almost all bpermute. --minimize reduces them to a single ds_bpermute_b32. A direct kernel shows the rule. It runs wave64 with 64 threads, data = 100 + lane, and lane L asks for lane (L + K) mod 64:

K source lane = (L+K) mod 64 (all 64 lanes) two-halves rule (the model's, RDNA2/RDNA3.5)
0 64/64 64/64
8 64/64 48/64
32 64/64 0/64
40 64/64 16/64

For example, with K = 32, lanes 0..3 read lanes 32..35 and lanes 30..33 read 62, 63, 0, 1.

  • The translator is unaffected. It follows RDNA2, the console's rule, and emits SPIR-V shuffles, not native ds_bpermute.
  • The hardware oracle can't judge wave64 bpermute on gfx12. It needs either a per-arch model rule (gfx12: 64-lane) or a skip for that op there. Wave32 matches everywhere.
  • The swizzle, read_d16, read2 and atomic words in the "differing words" line follow the bpermute results in the same programs. No program without a bpermute differed in the minimized set I looked at.

AI-assisted (Claude Code).

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.

4 participants