Skip to content

FUZZ-2: generate packed half FMA inline and literal operands - #6048

Open
kacper-serewis wants to merge 1 commit into
ItsNotRexed:mainfrom
kacper-serewis:fuzz/packed-fma-immediates
Open

kacper-serewis wants to merge 1 commit into
ItsNotRexed:mainfrom
kacper-serewis:fuzz/packed-fma-immediates

Conversation

@kacper-serewis

Copy link
Copy Markdown
Contributor

FUZZ-2 follow-up, coordination claim. Based directly on main. No PR dependencies. #5665 covers destination aliasing separately.

The f16 generator now mixes VGPR-only packed FMAs with one or two floating inline constants, or one appended literal and one inline constant. The CPU reference selects each operand half independently. The regression executes a synthetic instruction through the translator and interpreter and checks the exact packed result against hand arithmetic. A fixed-seed coverage test requires all four observed constant/selector forms.

Private recount across 26,503 cached listings found 480 packed half FMAs. 66 combined constants with a nondefault high selector: 50 used two inline floats, 12 used one, and 4 used an appended literal plus an inline float. Two of the four literals had two finite halves. Only synthetic inputs are in the patch.

AI-assisted. Windows CPU only, no GPU or driver used. Seed 7, 128 indices at wave32 and wave64: 256 modelled, 256 translated and 256 passed spirv-val using the production harness and AMDGPU llvm-mc 21.1.8. tests/test_valu_fuzz.py: 79 passed, 5 optional AMD-toolchain tests skipped. tests/semantic/test_valu_pk_fma_f16.py: 6 passed.

@rojasruiz

Copy link
Copy Markdown

Tested 730923c merged onto main 5cf3daf (clean merge) on an actual GPU: NVIDIA GeForce RTX 3080 (32-wide subgroups), driver 615.78.08, Linux 7.2.15; llvm-mc 23.1.3, SPIRV-Tools v2026.4: pass. This adds the GPU run to your CPU-only check.

valu_fuzz.py --family f16 --programs 200 --seed 7 with vk_compute_test from main:

wave32 (native) wave64 (--emulate)
main 200/200 match 200/200 match
this branch 200/200 match 200/200 match

All runs had 0 mismatched, 0 skipped, 0 not translated and 0 harness errors. The generator change does reach the GPU. In the wave32 seed-7 listings, v_pk_fma_f16 lines with an inline-constant or literal operand go from 0 of 75 on main to 56 of 78 on this branch (a rough grep, not a per-form count). All of them translated and matched the CPU model.

  • tests/test_valu_fuzz.py: 79 passed, 5 skipped (the AMD clang / AMD llvm-mc tests; no LEONIDA_AMD_CLANG here).
  • tests/semantic (443 files / 5,889 tests) and run_gpu_tests.py (190/239): both identical to main. check_no_game_data.py on both files: clean.

AI-assisted (Claude Code).

@AsgerCode

Copy link
Copy Markdown

Tested 730923c on Windows 11 (NTFS), Python 3.12.10 (CPU only, no GPU, no game files): pass

This adds CPU-side checks to the GPU run above: operand validity over a large sample, fixed-seed reproducibility, and a model-vs-translator differential through the repository's SPIR-V interpreter, with mutations to show that it can fail.

What I ran:

  • tests/test_valu_fuzz.py: 77 passed, 7 skipped. The 2 extra skips need an AMDGPU llvm-mc, which this machine does not have. tests/semantic/test_valu_pk_fma_f16.py: 6 passed. The 7 other test files that import valu_fuzz: 198 passed, 2 skipped.
  • Negative control (merge base's tools/valu_fuzz.py): both new tests fail, one on the coverage assert and one with KeyError: '0x42004000' in op_text.
  • Model mutations: replicating an inline constant into both halves, cutting the literal to its low 16 bits, or swapping the literal's halves each makes test_packed_fma_literal_and_inline_exact_words fail.
  • Merge with current main (867d922): clean. The two test files on the merged tree: 83 passed, 7 skipped.
  • Operand validity, seeds 1-20 x 200 programs x wave32/64 (8,000 programs, 2,953 v_pk_fma_f16). Forms: VGPR-only 752, one inline 758, two inline 734, literal + inline 709. Every op has at most one literal. Every inline operand is in the f16 inline set and has op_sel_hi = 0. Every literal has a normal low half and a non-zero high half, so an assembler cannot fold it into an inline constant. 517 of the 709 literals have their high half read through op_sel/op_sel_hi, and 257 of those have the NaN high half.
  • Fixed seeds, merge base vs this branch:
    • --family mem: identical (seed 7 x 128 x both waves, seed 1 x 2000, seed 2 x 200 x both).
    • --family f16: every program without v_pk_fma_f16 is identical. Every program with one is identical up to that op and different after it, also when it draws the VGPR-only form, because rng.randrange(4) is always drawn. That is 586 of 2,000 programs for seed 1 wave32, and 67 of 256 for seed 7.
    • --show 2:163:64 (the valu_fuzz f16 seed 2 program 163 (wave64) mismatches on Radeon 680M: v_lshlrev_b16 op_sel result #1506 reproduction in tests/test_u16_high_half.py) is unchanged.
  • CPU differential. Each generated program runs on one lane in a pixel-shader wrapper: the program body, then exp mrt0..3 of v20..v35. The translator output runs in spirv_mini_interp, and the result is compared with F16Family.model() for that lane, with uncertain halves masked.
    • Seed 7, indices 0-127, both waves: the 52 programs with a constant form (65 such ops). 832 words and 1,585 halves compared, 0 mismatches.
    • Seed 1, indices 0-399, both waves: 195 programs, 3,120 words, 0 mismatches.
    • Mutation (model replicates inline constants into both halves): 32 words mismatch.
    • Mutation (translator input gets the literal cut to its low 16 bits, which is what llvm-mc's printed text does to v_fma_mix* literals, docs/design.md "Printed encodings"): 12 words mismatch on seed 7. The GPU run reads llvm-mc's printed text, so its 200/200 at seed 7 also shows that llvm-mc 23 printed the full 32-bit literal.

Not checked here: the bytes llvm-mc encodes. The translator path reads llvm-mc's text, so neither the GPU run nor mine sees a literal that the encoder changes. --oracle hw on an AMD GPU would. The rule that op_sel picks the literal's high half is not measured for packed f16 in the repository: every packed-f16 row with a literal in tests/semantic/test_alu_vop3_mods_hw.py has op_sel[0] = op_sel_hi[0] = 0. docs/shader_validation.md (SHADER-302) records the full dword for packed 16-bit integer ops on gfx1036, which supports the model.

Nits, none blocking:

  1. About 29% of the f16 seed corpus changes (above). The counts in docs/design.md for f16 runs at seeds 1, 2, 4 and 330 were measured on the old programs. If keeping old seeds reproducible matters, draw the form from a separate random.Random keyed on seed/index/wave/op index. Otherwise, one line in the PR body is enough.

Overlap: 7 other open PRs touch tools/valu_fuzz.py (#3086, #3302, #3700, #4388, #4426, #5057, #6131). None makes this change, and git merge-tree with each merges both valu_fuzz files without a conflict.

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.

3 participants