Skip to content

Tests: generate RDNA2 programs for compile-time measurements (#1269) - #1763

Open
BetterJdue wants to merge 2 commits into
xcl-dev:mainfrom
BetterJdue:compile-bench-gen
Open

BetterJdue wants to merge 2 commits into
xcl-dev:mainfrom
BetterJdue:compile-bench-gen

Conversation

@BetterJdue

Copy link
Copy Markdown

A generator of deterministic RDNA2 programs for the synthetic compile-time benchmark of #1269: no game data, so it runs anywhere, CI included. Test-only: one commit in crates/xcl/tests/compile_bench/, nothing in crates/xcl/src. Nothing is timed yet; the DXC measurement is the next PR, stacked on this one.

Part of #1269

What is in it

  • crates/xcl/tests/compile_bench/gen.rs: program(&Knobs) assembles a program with rdna2::encode from a seed and knobs: the number of operations, divergent ifs (v_cmp → s_and_saveexec → s_cbranch_execz) and how deep they nest, uniform loops (SGPR counter, backward s_cbranch_scc1) and how deep they nest, wave32 or wave64, the VGPR and SGPR pools, and the share of LDS and memory accesses. Knobs that would give more operations than asked for are refused.
  • crates/xcl/tests/compile_bench/main.rs: 7 tests, CPU only. They check in the disassembly, not in the generator: the operation count, how deep the ifs and loops nest, where every branch lands, the EXEC instructions of each wave size, the LDS and memory shares and the VGPR pool; 24 knob combinations translate completely with structured control flow on and off.

Tested

  • AMD Radeon RX 6700 (RDNA2), driver 32.0.21045.29003, Ryzen 5 3600, Windows 11 Pro 26300, Rust 1.100.0 MSVC, debug.
  • cargo test -p xcl --test compile_bench: 7 passed, 0 failed, 0 ignored.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 5ae62c5: 755 passed, 3 failed, 41 ignored (20 binaries); no SKIPPED tests. The failures are placed_title_textures_share_vram_and_preserve_pixels ("3D 64x64x64 4 mips: subresource 2 mismatch") and two tests that then fail on the lock it poisons; the first fails alone on main 930e8b4 too (4 of 4 runs). The same failure (same message, RDNA2, same driver) is reported fixed by D3D12.X: map and unmap 3D texture mips separately #1028 on an RX 6600, RX 6750 XT and RX 6900 XT; D3D12.X: map and unmap 3D texture mips separately #1028 was not run here.
  • Negative control: 10 mutations of the generator (seed ignored, loops not nested, loop and execz branch offsets off by one, wrong EXEC width, if depth ignored, VGPR pool too large, LDS share ignored, operations miscounted, the operation-count check removed); each makes at least one test fail.

Regression run

  • Not needed: test-only change, nothing in crates/xcl/src.

Not tested

  • scripts/smoke.ps1 or any retail title (no game data here; the change does not touch the runtime).
  • NVIDIA, wave32-only GPUs; release build.

AI use

  • Claude Code with Claude Opus 5.5: wrote the generator, the tests and this description, and ran the tests on the machine above; reviewed by an independent Claude Code agent before posting.

🤖 Generated with Claude Code

…#1269)

The synthetic compile-time benchmark of xcl-dev#1269 needs console programs that
anyone can build, CI included, without game data. This adds the generator
it will measure: deterministic RDNA2 programs, assembled with
rdna2::encode, from a seed and knobs for the number of operations,
divergent ifs (v_cmp, s_and_saveexec, s_cbranch_execz) and how deep they
nest, uniform loops (SGPR counter, backward s_cbranch_scc1) and how deep
they nest, wave32 or wave64, the VGPR and SGPR pools, and the share of LDS
and memory accesses. Knobs that would give more operations than asked for
(fewer than two per loop level) are refused. Nothing is timed yet; that
comes next, with DXC.

The tests count what each knob does in the disassembly of the program,
not in the generator: the operations, how deep the ifs and loops nest,
that every s_cbranch_execz lands on its EXEC restore and every loop
branch on the instruction after its counter is set, the EXEC instructions
of each wave size, the LDS and memory shares, the highest VGPR. Every
knob combination the tests use translates completely, structured and as
the guarded block chain, with as many instructions as the disassembly.

Negative control: ten mutations of the generator (seed ignored, loops
not nested, loop and execz branch offsets off by one, wave32 using the
64-bit EXEC instructions, if depth ignored, VGPR pool one too large, LDS
share ignored, operations miscounted, the operation-count check removed)
each make at least one test fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ivall ivall added the goal:world-load Bears on the retail title getting past world loading label Nov 24, 2026
@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~23 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

Large synthetic loop bodies can exceed the signed SOPP displacement. The narrowing cast silently wraps the back edge and produces a different program. Check the displacement before encoding it; cover rejection and a large representable loop.
@anes66

anes66 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Large loop bodies silently wrap their SOPP back edge on exact head 5ae62c52c218f2ee7ba36e18a83769b5d5ae13a9. nested_loop narrows the negative dword displacement with back as i16, so benchmark knobs can produce a different control-flow graph instead of rejecting an unencodable loop.

Patch: 0f257d1, directly on that head. It uses i16::try_from before encoding, following the generator's existing panic-on-invalid-knobs contract. Two test files only; no runtime changes or competing PR.

Tested

  • Windows 10 Pro 19045, Ryzen 7 9800X3D, Rust 1.100.0 MSVC, debug. CPU-only, no DXC or GPU execution.
  • The new rejection test uses ops=100000, one loop, no divergent regions/LDS/memory operations. Before the check: 0 passed / 1 failed, because the generator did not reject the out-of-range branch. After: it rejects with loop body exceeds SOPP branch range.
  • A second test disassembles a representable 10000-operation program, verifies the backward branch lands immediately after its counter initialization, and checks operation count and loop shape.
  • cargo test --locked -p xcl --test compile_bench -- --nocapture --test-threads=1: 9 passed / 0 failed / 0 ignored, no skips. This also runs the existing 24 knob combinations through both structured and unstructured CPU translation.

Not tested
The full workspace/GPU suite, release, retail inputs, or integration onto newer main. Oversized loops are rejected rather than expanded into far jumps; the encoded loop range remains the ISA's signed 16-bit dword range.

AI use
Codex (GPT-6; exact variant unavailable) found the narrowing issue, wrote the check and regression tests, ran CPU validation and prepared this report.

CPU integration follow-up

The generator at 0f257d19e5b3950ebf00b61090ab78d25fc45ea4, including the accepted branch-range fix, was also checked in an integration tree based on main 06c9f55 with #1906, #1860, the proposed #2076 rebase, #1972, #2322 and #2124. Test-only addition 0f733a4 is on that integration tree, not directly on this PR's head.

Windows 10 Pro 19045, Ryzen 7 9800X3D, Rust 1.100.0 MSVC, debug, SDK DXC/DXIL 1.9.2602.17:

  • 64 generated programs / 288 validated direct-DXIL variants: eight seeds, four 300-operation profiles (straight ALU, divergent branches, nested loops, mixed LDS/global memory), wave32/native wave64/split wave64, and plain/flat-compact/nested-compact emission. Three isolated children each validate 96 variants.
  • SDK disassembly verifies the requested forms. A representative wave32 case has no xcl_blocks table and 0 switches in plain form, the table and 1 switch flat, and the table and 8 switches nested. The parent requires a larger switch count for nested dispatch, so merely ignoring the mode is insufficient.
  • cargo test --locked -p xcl --test compile_bench -j 2 -- --nocapture --test-threads=1: 10 passed / 0 failed / 0 ignored / 0 runtime skips, including the original nine generator tests. The two should_panic rejection tests pass as intended.
  • Negative control: asking the nested child for flat dispatch still validates its 96 containers but fails the parent with switch counts [0, 1, 1]. Restored before the final passing run and commit.

No GPU capability query, pipeline build or shader execution; these generated memory accesses were never run. Not tested: output parity, timings, release, full workspace suite, a title or this added matrix on the standalone old PR head. This checks compiler/validator coverage, not compilation-speed improvement.

@raylitebull

Copy link
Copy Markdown
Member

\CI\ workflow approved for \5ae62c5\ (\crates/xcl/tests/compile_bench/{gen.rs,main.rs}). Note @anes66's finding above on
ested_loop\ (\�ack as i16\ silently wrapping if \ops\ is large enough to exceed SOPP's signed 16-bit dword range); using \i16::try_from\ + obtaining an independent NVIDIA check on \5ae62c5\ (plus \Build and test\ green) will make this ready.

@BetterJdue

Copy link
Copy Markdown
Author

Thanks @anes66: your commit is pulled into this PR unchanged, so the head is now 0f257d1 (a fast-forward on 5ae62c5, author kept).

Tested on 0f257d1: AMD Radeon RX 6700 (RDNA2), driver 32.0.21045.29003; Ryzen 5 3600; 32 GB RAM; Windows 11 Pro 26300; Rust 1.100.0 MSVC; DXC 1.9.2602.17; debug.

  • cargo test --workspace --no-fail-fast -- --test-threads=4: 757 passed, 3 failed, 41 ignored, no SKIPPED. The 3 failures are the RDNA2 texture test (placed_title_textures_share_vram_and_preserve_pixels, "subresource 2 mismatch", also failing alone on main b9b6ea6) and the two tests that fail on the lock it poisons; none is in this PR's files.
  • cargo test -p xcl --test compile_bench: 9 passed, 0 failed.
  • With back as i16 put back, oversized_loop_branches_are_refused fails; with the fix it passes.

An independent run on NVIDIA on the new head would still help: DavidM1911's RTX 3060 Ti report above was on 5ae62c5 merged with main.

AI use: Claude Code (Claude Opus 5.5) ran these tests and wrote this comment.

AI-assisted verification using synthetic inputs.

@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

The independent NVIDIA run asked for above, on the new head 0f257d1: RTX 3070 (Ampere, driver 616.56), Windows 11, debug.

  • cargo test -p xcl --test compile_bench: 9 passed, 0 failed (oversized_loop_branches_are_refused included).
  • cargo test -p xcl --lib -- --test-threads=4: 706 passed, 1 failed, 21 ignored. The failure is hle::xaudio2::tests::xma2_source_voice_decodes_and_manages_lifetime (0 samples played where 28679 were expected, xaudio2.rs:1611). That test waits a fixed time for audio playback, and the machine was under heavy parallel load during this run. This PR doesn't touch XAudio2. Tests: the XAudio2 voice tests wait 30 s for playback and skip a slow audio device (#1487) #1600 gives those voice tests a longer wait.

Not run: the whole workspace.

AI-assisted (Claude Code). Synthetic tests only.

@vakaobr

vakaobr commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

@BetterJdue one knob I needed for running the programs rather than only compiling them: race_free. Suggesting it here so the harness keeps using this generator instead of a fork of it.

Why. The programs let lanes race: a global_store_dword to lane * 4 + o1 and a later global_load_dword of lane * 4 + o2 by another lane, s_load_dword of addresses a vector store just wrote, and ds_read_b32 of a lane's LDS dword before anything wrote it. On the console a wave runs those in program order; translated to one GPU thread per lane, D3D12 gives no such order. With data in memory, 59 of 1000 seeds gave different results on two runs of the HLSL path on D3DMetal, and 48 more differed between the HLSL path and #1426's direct path for the same reason. With the knob on: 1000 tested, 0 differences, 0 unstable (details on #1269).

What it does (off by default):

  • global and scalar loads read only bytes 0..1024 (lane * 4 + offset ≤ 63 × 4 + 192 × 4 = 1020),
  • every global store writes the lane's own dword at byte 1024 + lane * 4,
  • the program starts with ds_write_b32 v1, v0, so each lane's LDS dword is set before it is read.

With the knob off the programs are byte for byte the same as 5ae62c5: the store still draws its data register before its offset, as the array literal did.

@@ pub struct Knobs {
     pub lds_pct: u32,
     pub mem_pct: u32,
+    /// programs whose result does not depend on the order lanes see each other's memory
+    /// accesses, for running and comparing them: global loads and scalar loads read only bytes
+    /// 0..1024, every global store writes the lane's own dword at byte 1024 + lane * 4, and the
+    /// lane's LDS dword is written before anything reads it
+    pub race_free: bool,
 }
@@ impl Default for Knobs {
-        Knobs { seed: 1, ops: 200, if_depth: 2, divergent_pct: 10, loops: 0, loop_depth: 1, loop_trips: 4, wave64: true, vgprs: 16, sgprs: 8, lds_pct: 5, mem_pct: 10 }
+        Knobs { seed: 1, ops: 200, if_depth: 2, divergent_pct: 10, loops: 0, loop_depth: 1, loop_trips: 4, wave64: true, vgprs: 16, sgprs: 8, lds_pct: 5, mem_pct: 10, race_free: false }
@@ fn op(&mut self) -> Vec<u8> {
-                0 => inst("GLOBAL_LOAD_DWORD", "ENC_FLAT_GLBL", &[("VDST", self.vgpr()), ("ADDR", 1), ("SADDR", 2), ("OFFSET", 4 * self.rng.below(256))], None),
-                1 => inst("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 1), ("DATA", self.vgpr()), ("SADDR", 2), ("OFFSET", 4 * self.rng.below(256))], None),
+                // race-free: lane * 4 + offset stays below byte 1024 (63 * 4 + 192 * 4 = 1020)
+                0 => inst("GLOBAL_LOAD_DWORD", "ENC_FLAT_GLBL", &[("VDST", self.vgpr()), ("ADDR", 1), ("SADDR", 2), ("OFFSET", 4 * self.rng.below(if self.k.race_free { 193 } else { 256 }))], None),
+                1 => {
+                    // the data register is drawn before the offset, as before, so programs without
+                    // race_free stay the same
+                    let data = self.vgpr();
+                    let offset = if self.k.race_free { 1024 } else { 4 * self.rng.below(256) };
+                    inst("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 1), ("DATA", data), ("SADDR", 2), ("OFFSET", offset)], None)
+                }
@@ pub fn program(k: &Knobs) -> Vec<u8> {
     let mut v = inst("V_LSHLREV_B32", "ENC_VOP2", &[("VDST", 1), ("SRC0", 130), ("VSRC1", 0)], None); // v1 = lane * 4
+    if k.race_free {
+        v.extend(inst("DS_WRITE_B32", "ENC_DS", &[("ADDR", 1), ("DATA0", 0)], None)); // the lane's LDS dword = lane id
+    }

It's commit 5fa8e36 on vakaobr/xcl tests/diff-harness, on top of your 5ae62c5 (kept as is; that branch is on main c4d37be). Take it into #1763 if you agree, or I'll stack it as its own PR after #1763; either is fine with me.

Tested: cargo test -p xcl --test compile_bench with the knob in: 7 passed, 0 failed, on the Mac (M5 Pro, CrossOver 26.3 / D3DMetal, Rust 1.100.0 x86_64-pc-windows-gnu, debug). Not tested: Windows.

AI use: Claude Code (Claude Opus 5.5) wrote the knob and this comment.

@DavidM1911

Copy link
Copy Markdown
Contributor

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

@futurepro62

Copy link
Copy Markdown

NVIDIA and AMD full-suite run, to go with the reports above by anes66, upipibi, vakaobr, since none of them covers AMD. Tested exact head 0f257d19 (on its base 930e8b4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 760 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: same_knobs_and_seed_give_the_same_program, operations_and_control_flow_follow_the_knobs, knobs_with_fewer_operations_than_loop_levels_are_refused, wave_size_picks_the_exec_instructions, oversized_loop_branches_are_refused, large_representable_loop_still_targets_its_body, lds_and_memory_shares_follow_the_knobs, vgprs_stay_in_the_pool, every_program_translates_completely.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 760 passed, 0 failed, 41 ignored, no skips.
  • --skip leaves out tests that fail on main b49be183 too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651), the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests, const_and_null_mask_operands_agree_with_hlsl_on_the_gpu and mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, and gpu::dxil::fuzz_tests seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card (drivers 616.64 and 621.40). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). The AMD run does not set XCL_REQUIRE_GPU.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@saintwolf

Copy link
Copy Markdown
Contributor

merge-check claim
head: 0f257d1

@github-actions github-actions Bot added area:tests Unit, integration, e2e tests, or testtitle gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Nov 30, 2026
@saintwolf

Copy link
Copy Markdown
Contributor

merge-check
base: 9dfbe3e
head: 0f257d1
merge: clean (trial merge 0b9b76fbc61228231d8c20c08687488ef1dd6cec; git diff --check clean; +374/-0, two new files in crates/xcl/tests/compile_bench/)
build: cargo build --workspace -> ok (39 pre-existing warnings, none from the PR's files)
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2894 passed, 1 failed, 51 ignored; SKIPPED: 27 (22 "no wave64" — wave32-only GPU, 2 "no heap windows", 1 "cannot disable the driver cache (Developer Mode)", 2 "no xgameruntime.dll"); failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, pre-existing on this machine (fails identically on base 9dfbe3e, same "2D D16 resinfo clobbered v2/v3" assertion). All nine compile_bench tests pass: determinism per seed, knob-driven shape verified in the disassembly (op counts exact, if/loop nesting, every branch target checked, EXEC width per wave size, LDS/mem shares, VGPR pool), the two rejection should_panic tests, and 48 generated programs translating completely with structured on and off.
review: read the whole diff. Test-only generator for the #1269 compile-time benchmark series: program(&Knobs) builds an RDNA2 instruction stream with the existing rdna2::encode (seeded splitmix64, same sequence on every platform), so no game data and CI-runnable. The tests do not trust the generator: they count and locate instructions in the disassembly and check each s_cbranch_execz lands on its EXEC restore and each s_cbranch_scc1 back on the instruction after its counter init. The head includes anes66's i16::try_from fix for loop bodies exceeding the SOPP signed 16-bit dword range (previously a silent wrap), with a fail->pass regression pair in the thread. No unsafe, no new dependencies, nothing in crates/xcl/src. #2100/#2106 are the stacked follow-ups of the same series; no duplicates.
performance: none; test-only, CPU-only (the programs are meant to be translated and compiled, not run).
verdict: safe to merge
hardware / tool and model: RTX 4070 SUPER (driver 32.0.16.2140), Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 / OpenCode, Qwen 3.8 27B

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) labels Nov 30, 2026
@tiagonleal

tiagonleal commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: 9dfbe3e
head: 0f257d1
merge: clean, alone and together with #2814 (15e88d7, which touches other files, gpu/dxil/lower.rs, lower_valu.rs, round_tests.rs): both heads merged onto the base in one tree (052f736e) without conflicts
build: cargo build --workspace -> ok on the combined tree
tests: cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4 on the combined tree of this head and #2814's head on the base (one suite run for the two PRs, not one per PR) -> 2895 passed, 1 failed, 51 ignored; SKIPPED: 24 lines, the same as on the base; failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, which fails the same way on the base alone (2885 passed, 1 failed, 51 ignored; #3513 fixes it). The nine tests of the new compile_bench test binary all ran and passed, none skipped and none #[ignore]d: they are always on. They need no GPU: the programs go through the CPU translator (recomp::translate, compile_bench/main.rs:176) and are never run. Time: the binary finished in 0.43 s in the suite and in 0.43, 0.43 and 0.44 s in three more runs of cargo test -p xcl --test compile_bench -- --test-threads=4 on their own, all 9 passing each time; the suite's added cost is that plus building one more test binary.
review: whole diff read (+374/-0, two new files under crates/xcl/tests/compile_bench/, nothing in crates/xcl/src, no Cargo change: the directory is picked up as a test target by its main.rs). Deterministic by construction: every program comes from Knobs.seed through a splitmix64 generator (gen.rs:58, gen.rs:174), with seed 1 by default (gen.rs:38) and seeds 0 to 47 in every_program_translates_completely (main.rs:172); nothing reads the clock or an OS random source. Nothing is timed and no assertion depends on wall-clock time, so it cannot be flaky that way (the PR body says the DXC timing comes in a later PR; a timing assertion there would need care). The assertions are structural: same seed gives the same bytes and another seed other bytes, instruction counts and branch targets read back from the disassembly, the VGPR pool, LDS and memory shares within a tolerance (main.rs:152), two should_panic refusals, and full translation of 48 programs with structured control flow on and off.
performance: no smoke run: the PR adds only test files, and nothing in the emulator binary.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB (617.42, wave32), Ryzen 7 9800X3D, 32 GB, Windows 11 26300, rustc 1.100.0 / Claude Code (Claude Opus 5.5 ran the build, suite and tests, reviewed the diff against the merged source and wrote this)

Edit (30 Nov, after thehollowedone's report below): the lds_pct + mem_pct sum in tests/compile_bench/gen.rs (lines 98 and 173) can overflow, but only with knobs far out of range, for example u32::MAX and 1. The literal values in this PR are 0, 5 and 10. A debug test build panics on the addition; a release test build wraps and the assert passes. The file is the test-only benchmark generator and no runtime code uses it, so my verdict stays. A checked_add there would be a good small follow-up.

  • Tiago

@Pipodi

Pipodi commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

merge-check claim
head: 0f257d1

@Pipodi

Pipodi commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Withdrawing my merge-check claim above: saintwolf and tiagonleal already hold the two slots on this head, and the queue table I worked from was older than their posts. Sorry for the noise.

AI use: Claude Code (Claude Opus 5.5) posted the claim and this note.

@github-actions github-actions Bot added ready-to-merge Has 2 independent safe merge-checks on current head (#3041) and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Nov 30, 2026
@thehollowedone

Copy link
Copy Markdown
Contributor

I found an input-validation overflow in the generator. program() checks lds_pct + mem_pct <= 100 using u32 addition. In release mode, u32::MAX + 1 wraps to zero, so invalid knobs pass validation; the per-operation threshold wraps too. The candidate uses checked addition and adds tests for the boundary and program() itself.

Tested locally: current main 9dfbe3ea plus the two test files from this PR head and this candidate. cargo test --offline --locked -p xcl --test compile_bench: 11 passed, 0 failed, 0 ignored. In release mode, the overflow regression passes with the fix; reverting only the checked guard makes it fail with “test did not panic as expected.” Windows 11 build 26300, Ryzen 7 9800X3D, rustc 1.99.1 MSVC; CPU-only. Full workspace and a clean PR merge were not run.

Candidate fix and regression diff
diff --git a/crates/xcl/tests/compile_bench/gen.rs b/crates/xcl/tests/compile_bench/gen.rs
@@
 const V: u64 = 256;
 
+pub(super) fn valid_access_shares(lds_pct: u32, mem_pct: u32) -> bool {
+    lds_pct.checked_add(mem_pct).is_some_and(|sum| sum <= 100)
+}
+
 fn inst(name: &str, enc: &str, fields: &[(&str, u64)], lit: Option<u32>) -> Vec<u8> {
@@
-    assert!(k.lds_pct + k.mem_pct <= 100 && k.divergent_pct <= 100, "{k:?}");
+    assert!(valid_access_shares(k.lds_pct, k.mem_pct) && k.divergent_pct <= 100, "{k:?}");

diff --git a/crates/xcl/tests/compile_bench/main.rs b/crates/xcl/tests/compile_bench/main.rs
@@
+#[test]
+fn memory_access_shares_reject_overflow_and_out_of_range_sums() {
+    assert!(gen::valid_access_shares(60, 40));
+    assert!(!gen::valid_access_shares(60, 41));
+    assert!(!gen::valid_access_shares(u32::MAX, 1));
+}
+
+#[test]
+#[should_panic]
+fn program_rejects_overflowing_memory_access_shares() {
+    program(&Knobs { lds_pct: u32::MAX, mem_pct: 1, ..Knobs::default() });
+}

AI use: OpenAI Codex (GPT-6.2 Sol) prepared and tested the candidate.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 0f257d1

#2100 and #2106 contain this PR's two commits because they are stacked on it, by the same author. They are not duplicates: this is the base of the stack.
No problems found in the diff. The branch offsets of s_cbranch_execz and of the backward s_cbranch_scc1 and the loop counters check out.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

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

Labels

area:tests Unit, integration, e2e tests, or testtitle goal:world-load Bears on the retail title getting past world loading gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) ready-to-merge Has 2 independent safe merge-checks on current head (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.