Skip to content

Tests: 16-bit integer VALU ops and the byte / half SADs on the GPU - #638

Open
acaracargo wants to merge 1 commit into
xcl-dev:mainfrom
acaracargo:fork/int16-gpu-tests
Open

acaracargo wants to merge 1 commit into
xcl-dev:mainfrom
acaracargo:fork/int16-gpu-tests

Conversation

@acaracargo

Copy link
Copy Markdown

Adds a GPU test for 20 VOP3 instructions that emit.rs translates but no test runs:

  • The 16-bit add / sub / mul_lo / shifts / min / max / mad, in u16 and i16.
  • v_mad_u32_u16 and v_mad_i32_i16.
  • v_sad_hi_u8, v_sad_u16 and v_sad_u32.
  • v_cvt_pk_i16_i32.

Eleven lanes carry edge values: sign and carry boundaries, shift counts past 15, and i16 saturation in both directions. The high half of every 16-bit source holds another value, so a translation that reads the whole register shows up. Each lane is compared with the ISA's pseudo-code. Only D[15:0] of a 16-bit result is compared.

#590 tests the 24-bit and high-half multiplies, so this one leaves them out. #445 has the 16-bit min3 / max3 / med3.

What is in it

  • crates/xcl/src/gpu/recomp/tests.rs: gpu_valu_16_bit_integer_and_sad.

Tested

  • NVIDIA GeForce RTX 4060 (32-lane waves only), driver 610.88; Intel Core i5-13400F; Windows 11 Pro 26300; Rust 1.100.0 x86_64-pc-windows-msvc; DXC 1.9.2602.17; debug.
  • cargo test --workspace -- --test-threads=4 on 253f749: 685 passed, 0 failed, 41 ignored (main 9ce2070: 684 / 0 / 41).
  • SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64).
  • Breaking v_ashrrev_i16 into a logical shift, or making v_sad_u16 skip the high half, fails the test (checked locally, reverted).

Regression run

  • Test-only change, no runtime regression run.

Not tested

  • AMD GPUs and native wave64; console hardware.
  • D[31:16] of 16-bit results.

AI use

  • Claude Code (Claude Opus 5.5) wrote the test and the original description and ran the tests and mutation checks. ChatGPT assisted with editing the PR description.

20 VOP3 instructions that no GPU test ran: the 16-bit add / sub /
mul_lo / shifts / min / max / mad (u16 and i16), v_mad_u32_u16,
v_mad_i32_i16, v_sad_hi_u8, v_sad_u16, v_sad_u32 and v_cvt_pk_i16_i32.
Eleven lanes carry edge values (sign and carry boundaries, shift counts
past 15, i16 saturation), with another value in the high half of each
16-bit source, compared per lane with the ISA's pseudo-code. Only
D[15:0] of a 16-bit result is compared. Making v_ashrrev_i16 a logical
shift, or v_sad_u16 skip the high half, in emit.rs fails the test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WsgnReN2iZK9RUNckZAhrv
@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of 253f74917b147deb949fa9633db1ea88eabd54ac on AMD RDNA4; the PR was tested on NVIDIA only. I merged it onto current main 18c105a locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 690 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 650 passed, 0 failed, 21 ignored
  • 0 SKIPPED; gpu_valu_16_bit_integer_and_sad passes.

Review: The CPU references match the RDNA2 pseudo-code where I checked: v_sad_u16 sums both half differences plus S2, v_sad_hi_u8 shifts the byte SAD by 16 before adding S2, v_mad_u32_u16 / v_mad_i32_i16 widen before the multiply, v_cvt_pk_i16_i32 saturates each word, and the *rev shifts take the count from S0[3:0]. Comparing only D[15:0] for the 16-bit results is right, since the high half is not defined by these opcodes without op_sel. I found nothing to change.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

@marquezinii

Copy link
Copy Markdown
Contributor

Test run of 253f74917b147deb949fa9633db1ea88eabd54ac on NVIDIA Blackwell with a newer driver than the one in the description. I merged it onto current main f4ce27c locally (clean merge, 75 lines in tests.rs) and tested that tree.

Tested

  • NVIDIA GeForce RTX 5070 12 GB (32-lane waves only), driver 621.24; Windows 11 Pro 26300; rustc 1.99.1 stable-x86_64-pc-windows-msvc, debug; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0)
  • cargo test --workspace -- --test-threads=4: 702 passed, 0 failed, 41 ignored; --test-threads=1: the same
  • SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64)
  • gpu_valu_16_bit_integer_and_sad passes
  • Two emitter breaks other than the ones in the description, each made by hand and reverted, fail the test: v_sad_hi_u8 shifting the sum by 8 instead of 16 (a=0x12340001 b=0xabcdffff c=0x55550002: got 0x55582f02, want 0x58840002), and v_ashrrev_i16 masking the shift count with 31 instead of 15 (a=0xa5a50011 b=0x0f0f8001: got 0xffff, want 0xc000)

Not tested

  • AMD / Intel, native wave64

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and the emitter-break checks and wrote this report.

@4usphs

4usphs commented Nov 24, 2026

Copy link
Copy Markdown

Measured on RDNA2 hardware, for the two points under Not tested: console-generation hardware, and D[31:16] of 16-bit results.

Method. The Radeon iGPU of a Ryzen 7 9800X3D (gfx1036, RDNA2), Windows 11 Pro 26200, display driver 32.0.21045.29003, AMD OpenCL 3652.0 (PAL,LC). Each instruction runs as inline RDNA2 assembly in an OpenCL C kernel (the #518 / #772 method), in its VOP3 form (_e64), on this test's 11 input triples, one per work-item. VDST is preset to 0xCAFEBABE. The test runs 6 times, 3 in wave32 and 3 in wave64, with identical output. The reference is a Python port of this test's 20 closures.

Result.

  • All 20 instructions × 11 inputs match the test's reference on the compared bits.
  • D[31:16] of a 16-bit result is kept. All 14 16-bit instructions in the test leave the high half at the preset 0xCAFE, for every input. These are v_add/sub_nc_u16/i16, v_mul_lo_u16, the three *_b16/_i16 shifts, v_min/max_u16/i16 and v_mad_u16/i16. That is what valu16 does ((cur & 0xFFFF0000u) | t, emit.rs:3051 on main 077ce40). So the test could preset the destinations and compare all 32 bits. v_cvt_u16_f16 / v_cvt_i16_f16 keep it too (measured for Tests: float-to-int conversions clamp and take NaN as 0 on the GPU #639). The assembler refuses a VOP2 (_e32) form of these 16-bit instructions on gfx1036, so I could not compare an encoding without op_sel.

For comparison, an RX 9070 XT (gfx1201, RDNA4, OpenCL 3686.0) gives the same results and also keeps D[31:16].

Not tested: the console itself (gfx1036 is a desktop RDNA2 APU of the same generation), RDNA1, the op_sel forms (writing D[31:16] instead), this PR's D3D12 test on this GPU.

AI use: Claude Code (Claude Opus 5.5) wrote the OpenCL probes and the port of the reference, ran them on my PC and wrote this comment. I have not reviewed the code.

@JJAutoCompare

Copy link
Copy Markdown

Empirical test report (253f749)

Hardware / environment

  • PR Tests: 16-bit integer VALU ops and the byte / half SADs on the GPU #638 at 253f74917b147deb949fa9633db1ea88eabd54ac, checked out detached.
  • Intel Arc A770 selected with XCL_ADAPTER=A770. Windows x64, build 10.0.26200.0. CPU identifier AMD64 Family 23 Model 113 Stepping 0, AuthenticAMD.
  • Rust 1.100.0 (0ef1bc386, x86_64-pc-windows-msvc). DXC 1.9.2609.5 (01b62ad4), DXIL 1.9.2609.5. Unoptimized test profile with debug info and incremental compilation disabled.

Commands and results

  • cargo test -p xcl --lib --no-run ran outside the Arc lock and exited 0. It built the library test executable.
  • xcl-00e28da3621caf64.exe --exact --nocapture --test-threads=1 gpu::recomp::tests::gpu_valu_16_bit_integer_and_sad ran under Invoke-ArcTest.ps1 with XCL_ADAPTER=A770 and RUST_TEST_NOCAPTURE=1. The executable and wrapper both exited 0. Libtest reported 1 passed, 0 failed, 0 ignored, 0 measured, and 665 filtered out in 0.37 s. The captured stdout and stderr contained 0 lines beginning with SKIPPED .

Observed behavior

  • The new GPU test completed with no mismatches against its reference calculations across 20 VOP3 instructions and 11 input triples. Its assertions cover 16-bit arithmetic, shifts, min/max, multiply-add, byte and halfword SAD, 32-bit SAD, and packed signed saturation. It compares the low 16 bits for 16-bit destinations and the full output for 32-bit destinations.

Not tested

  • The full GPU workspace suite and game smoke runs were omitted.

AI use

Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr638-focused.log and published.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

off-goal Does not bear on the current goal (world loading); waits until it is reached

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants