#1506

valu_fuzz f16 seed 2 program 163 (wave64) mismatches on Radeon 680M: v_lshlrev_b16 op_sel result

Openezwinxdlmaoopened 2h ago

tools/valu_fuzz.py --family f16 --seed 2 --programs 200 --wave both at c2967a5e mismatches on one program, cs_f16fuzz_s2_163_w64, on an AMD Radeon 680M (gfx1035, Vulkan driver 22.40.84.06, Windows 11). It fails both native and with --emulate, on all 64 threads. The other 399 of 400 match, and the RTX 3050 Laptop (621.01) matches this program under --emulate (its native wave64 is skipped). Reproduce with --family f16 --show 2:163:64.

thread 0..63 v30: got 0x41b10000, want 0x41b18362 (compared bits 0xffffffff; last written by op 13: v_lshlrev_b16_e64 v30, v30, v20 op_sel:[1,1,0])

Hand trace (a hypothesis, not measured):

  • The shift amount is v30.hi & 15. v30.hi = max_f16(0x3e00, 0x41b1) = 0x41b1, which matches the high half the 680M returns, so the amount is 1.
  • v20.hi should be 0x41b1. It's written by v_min_i16_e64 v20, v24, v31 op_sel:[1,0,1] (min of 0x41b1 and 0x4200), then kept by the partial write v_fma_f16_e64 v20 … op_sel:[0,0,1,0].
  • 0x41b1 << 1 = 0x8362. The 680M's 0 means it saw v20.hi as 0 or 0x8000.
  • The translation already masks the 16-bit shift amount (rdna2spirv.py ~4283), so the shift itself is defined.

The same emulated SPIR-V matches on the RTX 3050, so the cause may be the AMD 22.40 driver rather than the translation. Confirming that needs a newer AMD driver or a native gfx103x run of the program. No game files are involved; the program is the fuzzer's synthetic output.

Program
; cs_f16fuzz_s2_163_w64: tools/valu_fuzz.py (FUZZ-2)
; group: 64,1,1
; rsrc2: 0x8088
; mattr: +wavefrontsize64,-wavefrontsize32
s_mov_b64 exec, -1
v_mov_b32_e32 v20, 0x42b0ace0
v_mov_b32_e32 v21, 0xd4ee40ac
v_mov_b32_e32 v22, 0xd6f54000
v_mov_b32_e32 v23, 0xba1dc59a
v_mov_b32_e32 v24, 0x41b1af48
v_mov_b32_e32 v25, 0x5394f60b
v_mov_b32_e32 v26, 0x3e00ccd9
v_mov_b32_e32 v27, 0xc11f2ee5
v_mov_b32_e32 v28, 0xb0d23c00
v_mov_b32_e32 v29, 0x48c74637
v_mov_b32_e32 v30, 0xf82eeb86
v_mov_b32_e32 v31, 0x40004200
v_mov_b32_e32 v32, 0x4000b1e8
v_mov_b32_e32 v33, 0x90c956e7
v_mov_b32_e32 v34, 0xc09946b2
v_mov_b32_e32 v35, 0xb3eac2b2
v_and_b32_e32 v7, 7, v0
v_lshlrev_b32_e32 v7, 7, v7
v_or_b32_e32 v20, 0x3c00, v7
v_cvt_pkrtz_f16_f32_e32 v23, v30, v27
v_cvt_f16_f32_e32 v23, v23
v_max_i16_e64 v29, v30, v34 op_sel:[1,0,1]
v_pk_max_f16 v30, v26, v24 op_sel:[0,0] op_sel_hi:[1,1]
v_min_i16_e64 v24, v22, v33 op_sel:[1,1,0]
v_mul_f16_e32 v33, v21, v33
v_med3_f16_e64 v31, v30, v29, v28 op_sel:[1,1,0,1]
v_min_u16_e64 v32, v24, v30 op_sel:[1,0,1]
v_pack_b32_f16 v32, v27, v22 op_sel:[1,0]
v_pk_lshrrev_b16 v25, v27, v27 op_sel:[0,1] op_sel_hi:[0,0]
v_add_f16_e64 v33, v30, v33
v_min_i16_e64 v20, v24, v31 op_sel:[1,0,1]
v_fma_f16_e64 v20, v34, v26, v26 op_sel:[0,0,1,0]
v_lshlrev_b16_e64 v30, v30, v20 op_sel:[1,1,0]
s_mov_b64 exec, -1
v_mul_u32_u24_e32 v6, 64, v0
buffer_store_dword v20, v6, s[0:3], 0 offen offset:0
buffer_store_dword v21, v6, s[0:3], 0 offen offset:4
buffer_store_dword v22, v6, s[0:3], 0 offen offset:8
buffer_store_dword v23, v6, s[0:3], 0 offen offset:12
buffer_store_dword v24, v6, s[0:3], 0 offen offset:16
buffer_store_dword v25, v6, s[0:3], 0 offen offset:20
buffer_store_dword v26, v6, s[0:3], 0 offen offset:24
buffer_store_dword v27, v6, s[0:3], 0 offen offset:28
buffer_store_dword v28, v6, s[0:3], 0 offen offset:32
buffer_store_dword v29, v6, s[0:3], 0 offen offset:36
buffer_store_dword v30, v6, s[0:3], 0 offen offset:40
buffer_store_dword v31, v6, s[0:3], 0 offen offset:44
buffer_store_dword v32, v6, s[0:3], 0 offen offset:48
buffer_store_dword v33, v6, s[0:3], 0 offen offset:52
buffer_store_dword v34, v6, s[0:3], 0 offen offset:56
buffer_store_dword v35, v6, s[0:3], 0 offen offset:60
s_endpgm
; model, thread 0: v20=0x41b1d803 v21=0xd4ee40ac v22=0xd6f54000 v23=0xc8f97e00 v24=0x41b190c9 v25=0x1770608 v26=0x3e00ccd9 v27=0xc11f2ee5 v28=0xb0d23c00 v29=0x46b24637 v30=0x41b18362 v31=0x41b14200 v32=0x4000c11f v33=0x90c95c08 v34=0xc09946b2 v35=0xb3eac2b2

AI-assisted (Claude Code).

Activity

3
dcastell12h ago

I ran the program through the translator and the reference interpreter on the CPU, and the translated module produces the expected word on all 64 lanes, so this looks like the 680M driver rather than the translation.

  • Regenerated with tools/valu_fuzz.py --family f16 --seed 2 --show 2:163:64 at aae4d99; translated with tools/rdna2spirv.py (native wave64, no --wave64-emulate) and executed with tests/semantic/spirv_mini_interp.run_workgroup(spv, 64, 64, ...) with the same pc[0..3] = 0, 0, 0xFFFFFFFF, 0x31016FAC the fuzzer's harness uses.
  • Output memory (v6 = 64 * lane, stores at offsets 4..60): every lane has v30 = 0x41b18362, the model's value quoted in the issue, not 0x41b10000.
  • The rest of the dump also matches the model for lane 0: v24 = 0x41b190c9, v25 = 0x01770608, v29 = 0x46b24637, v31 = 0x41b14200, v33 = 0x90c95c08, v32 = 0x4000c11f.

0x41b10000 is exactly 0x41b1 << 0, while the shift amount is v30.hi & 15 = 1, so on that driver the v_lshlrev_b16 either took a zero amount or lost the low half of v20 — the two alternatives in the issue's hand trace. The SPIR-V does not contain a hardware v_lshlrev_b16: Gen emits a ShiftRightLogical on the lane index plus a Select of the word (low or high half) and a ShiftLeftLogical of the 16-bit value by the masked amount, so it is the driver's 32-bit shift/select path that would have to be wrong.

The mini interpreter cannot run the emulated form (OpControlBarrier is not modelled), but the native run above is already the case the 3050 could not check and it agrees with the model. Before spending time on the translator I would retry this one on a current AMD driver (22.40.84.06 is from 2022) and, if it still fails, keep the program as the known finding with --skip-op v_lshlrev_b16.

Sanonymous011h ago

Reproduced on a newer AMD driver and a second RDNA2 GPU. A second program fails the same way, and the hardware runs both correctly, so this points at the AMD Vulkan shader compiler.

GPU:     AMD RDNA2 integrated GPU (gfx1036), AMD Windows driver 32.0.21044.64 (Vulkan driverInfo 2026.10.12, LLPC)
OS:      Windows 11
Commit:  bb2e1842 (main), llvm-mc from AMD LLVM 23.0.0git, vk_compute_test built with MSVC

s2_163_w64 (--family f16 --seed 2) still mismatches with this driver, both native and --emulate, on all 64 threads:

thread 0..63 v30: got 0x41b1b006, want 0x41b18362 (last written by op 13: v_lshlrev_b16_e64 v30, v30, v20 op_sel:[1,1,0])

The low half is wrong in a different way than on the 680M with 22.40 (0x0000), so the shift input is still misread, just differently.

A second program of the same shape: s3_22_w64 (--family f16 --seed 3, --show 3:22:64). It mismatches native and --emulate, all 64 threads:

thread 0..63 v21: got 0xb2bdb2b9, want 0xb2b9000d (last written by op 11: v_pack_b32_f16 v21, v31, v31 op_sel:[1,0])

Both halves of v31 come from earlier partial writes:

  • v_ashrrev_i16_e64 … op_sel:[1,0,1] and v_min_i16_e64 … op_sel:[0,1,1] write the high half;
  • v_med3_f16_e64 v31, v25, v27, v34 writes the low half and keeps the high one.

v_pack_b32_f16 … op_sel:[1,0] then swaps them. This looks like the same pattern as SHADER-140 (#1051): a source built from partial writes.

Why it isn't the translation or the model:

  • Hardware: valu_fuzz --oracle translator,hw runs both programs natively on this gfx1036 through tools/hw_oracle, and the result matches the model, wave64 included. That is the native gfx10 behaviour @ezwinxdlmao asked for.
  • Other driver: the same --emulate SPIR-V matches on an NVIDIA GPU for both programs.
  • CPU: the translated module of s3_22_w64 (native wave64, from --work), run in tests/semantic/spirv_mini_interp.run_workgroup(spv, 64, 64, …) with the harness's pc[0..3], gives v21 = 0xb2b9000d on all 64 lanes. That's the model's value. @dcastell1 showed the same for s2_163 above.

Sweep for scale: f16, seeds 1–6, 200 programs × wave32/wave64 through the AMD Vulkan driver. These two are the only mismatches in 2,200 programs, both wave64; wave32 is clean.

No game files involved. AI-assisted (Claude Code).

S1m0ne19971h ago

SHADER-251: same conclusion as @Sanonymous01 above (posted while I was measuring; thanks, and to @dcastell1 for the CPU run). Points 1 and 2 independently confirm theirs; what's new is the three-instruction case in 3 and the SPIR-V reading in 4.

This is the AMD Vulkan driver, not the translator or the model. Measured on a Ryzen 9 9950X3D iGPU (AMD Radeon Graphics, gfx1036, RDNA2), AMD driver 32.0.21045.16010, next to an RTX 4090 (NVIDIA 621.24), Windows 11 26300, main bb2e1842.

1. It reproduces on a newer AMD driver, with a telling value. --family f16 --seed 2, program 163, wave64, native and --emulate: v30 = 0x41b1b006 on all 64 threads (the 680M on 22.40 gave 0x41b10000). The RTX 4090 matches under --emulate (its native wave64 is skipped).

2. Native RDNA2 hardware agrees with the model. tools/valu_fuzz.py --family f16 --seed 2 --programs 200 --wave both --oracle hw on the same gfx1036 (HIP runtime from the driver, amdhip64_6.dll; AMD clang from rocm-sdk-core): wave32 200/200 and wave64 200/200 match, program 163 included. So the model's 0x41b18362 is what the hardware computes.

3. Minimal case (greedy one-op removal while the 9950X3D iGPU and the 4090 still disagree; --emulate):

v_mov_b32_e32 v24, 0x41b1af48
v_mov_b32_e32 v31, 0x40004200
v_min_i16_e64 v20, v24, v31 op_sel:[1,0,1]      ; v20.hi = 0x41b1
v_fma_f16_e64 v20, v34, v26, v26 op_sel:[0,0,1,0] ; writes v20.lo, keeps v20.hi
v_lshlrev_b16_e64 v30, v30, v20 op_sel:[1,1,0]  ; v30.lo = v20.hi << 0

RTX 4090: v20 = 0x41b10000, v30 = 0x41b1 (right). AMD: v20 = 0x41b10000 (also right, as stored), but v30 = 0x0. Each instruction alone gives the right result on AMD. So do the v_lshlrev_b16 variants with v20 set by v_mov, with op_sel:[0,1,0], with a different destination, and the v_lshrrev_b16 and v_add_nc_u16 forms. It takes the v_fma_f16 partial write right before.

4. The SPIR-V is well defined. The registers are a Function-storage uint array. The partial write is old & 0xFFFF0000 | f16bits behind the EXEC OpSelect, then the shift reads (v20 >> 16) & 0xFFFF and OpShiftLeftLogical by (v30 >> 16) & 15. There's no undefined shift, no type punning beyond OpBitcast, and spirv-val passes. The FMA's f32 two-sum carries NoContraction. So AMD's compiler loses the high half of v20 through the (a & 0xFFFF0000) | b merge followed by >> 16, where b is the f16-rounded FMA result. It could be folding (… | b) >> 16 as if only b were there.

So no translator change for SHADER-251. The finding is an AMD driver bug, still present in 32.0.21045. It needs a report to AMD with the minimal case. A translator workaround would be a guess until the miscompile is pinned to one pattern; I can try that next if wanted.

No game files involved. AI-assisted (Claude Code).