Skip to content

Scripts: run the compile-time benchmark and compare two runs (#1269) - #2106

Draft
BetterJdue wants to merge 6 commits into
xcl-dev:mainfrom
BetterJdue:compile-bench-scripts
Draft

BetterJdue wants to merge 6 commits into
xcl-dev:mainfrom
BetterJdue:compile-bench-scripts

Conversation

@BetterJdue

Copy link
Copy Markdown

Stacked on #2100 (itself stacked on #1763); only the top three commits belong here: dae9b63, 7d3f7f6, 61dd6dc.

A script to run the compile-time benchmark of #2100 and one to compare two runs, plus a set of only the large programs and a summary ranked by DXC time, so the slow tail shows next to the median. Scripts and tests only: nothing in crates/xcl/src. 6 files changed, 431 insertions(+), 12 deletions(-), a little over the 400-line target; the large set (7d3f7f6) can go to a PR of its own if that is preferred.

Part of #1269

What is in it

  • scripts/compile_bench.ps1 (dae9b63): builds release and runs the benchmark one compile at a time (-Set full|large|small, -Reps, -DxcArgs); writes the JSON, CSV and log to target\compile_bench\<commit> and warns when the tree has uncommitted changes.
  • scripts/compile_bench_compare.py and its test (dae9b63, 61dd6dc): compares two runs program by program (sizes, median DXC time, head / base ratio, geometric mean), says when the two environments make the times incomparable, and marks any size change and any time change beyond the run-to-run noise (5 % unless --noise says otherwise).
  • crates/xcl/tests/compile_bench/measure.rs, main.rs (7d3f7f6): XCL_COMPILE_BENCH=large, 18 programs (base, divergent and resource programs at 8 000, 20 000 and 40 000 operations, native wave64 with 1 memory window and split wave64 with 4); every run prints the programs slowest first and a summary (median, nearest-rank p90, maximum, total, the slowest tenth's share), which also goes into the JSON.
  • README.md: a paragraph under the tests.

Tested

  • 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; Python 3.15.2.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 61dd6dc (debug): 764 passed, 3 failed, 41 ignored. The failures are not from this PR: placed_title_textures_share_vram_and_preserve_pixels, transitions_apply_when_their_list_is_submitted, d32s8_targets_take_their_own_size_of_video_memory, the same RDNA2 texture failure and its two lock-poisoning followers as in Tests: time DXC on generated RDNA2 programs and write JSON / CSV (#1269) #2100. SKIPPED: none.
  • The compile_bench tests in that run: 16 passed, 0 failed. python -I -m unittest discover -s scripts -p "test_compile_bench_compare.py": 8 tests, OK.
  • Negative control: four changes to the summary and the ranking (the p90 index, the size of the slowest tenth, the order, the summary left out of the JSON; made on 1297b3d's copy of these files, which is the same code) and three to the comparison (the noise ignored, the size check dropped, --noise not passed on) each make a test fail.
  • compile_bench.ps1 -Set large, release, 3 compiles per program, on 1297b3d: the same benchmark code as dae9b63 and 7d3f7f6, but on a newer main (4178e88) whose recompiler emits different HLSL than this PR's base, so these numbers show the shape of the tail, not this head's values: 18 programs, DXC median 24.8 s, p90 155.6 s, maximum 497.5 s (divergent-40000-split-4win: 26.6 MB of HLSL, 33.3 MB of DXIL); the 2 slowest take 47 % of the 1385 s.
  • The noise behind the 5 %: compile_bench.ps1 -Set small (6 programs of 0.1 to 0.25 s) 5 times on 7d3f7f6, the programs' median DXC times moved by at most 1.9 %; within one full-set run (ae43075, 3df53eb) the 3 compiles of a program spread by 2.8 and 1.4 % (median), single compiles by up to 17 %. 5 % is a margin chosen above that, not a measured bound.

Not tested

  • Game data and scripts/smoke.ps1: none used; scripts and tests only.
  • The large set on this head, and a second full-set run on one commit: not run, because I limit unattended runs to programs of up to about 8 MB of HLSL after a run was stopped for low memory.
  • Other machines and DXC versions.
  • NVIDIA and Intel; macOS and Linux (not built).

AI use

  • Claude Code (Claude Opus 5.5) wrote the scripts, the tests and this description, and ran the tests and the measurements. Prepared under human supervision: I direct this work and approve every change and comment before it is published.

BetterJdue and others added 6 commits November 24, 2026 16:05
…#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>
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.
…-dev#1269)

The compile-time benchmark of xcl-dev#1269 measures what DXC does with the
recompiler's HLSL without game data. Each generated program is
translated and compiled with DXC one at a time; its instructions,
blocks, code, HLSL and DXIL bytes, translation time and DXC times go
into compile_bench.json (with the commit, whether the tree was dirty,
the DXC toolchain, the build profile and the CPU) and compile_bench.csv.

Every test run compiles a small set of six programs, so CI goes through
the same code; XCL_COMPILE_BENCH=full runs five shapes at four sizes up
to 20 000 operations, each in the native form and in the split wave64 /
4-window form, plus controls whose effect is known (the guarded block
chain, 1 against 4 memory windows). XCL_COMPILE_BENCH_OUT,
_REPS and _DXC_ARGS set the output folder, the compiles per program and
extra DXC arguments; without the latter dxc.rs picks the optimisation
level from the source size, as it does for a title. Without DXC the
test calls skip_test("no DXC"). A program that does not translate
completely, that DXC refuses, or whose HLSL or DXIL differs between
repeats fails the test; the times are recorded, not judged.

The generator gets buffer (V#) and image (T#, S#) access knobs and a
compute mode (64 threads, 4 user SGPRs). At zero they draw nothing, so
the programs of the first version stay byte for byte the same, which a
test checks against hashes computed with the generator of 5ae62c5.

Negative control: six mutations (buffer or image share ignored, compute
ignored, the draws changed, the CSV time separator, the knobs not
flattened into the row) each make at least one test fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…#1269)

scripts/compile_bench.ps1 runs the full set (or the small one) of
crates/xcl/tests/compile_bench in release, one compile at a time, and
writes compile_bench.json / .csv and the log, in UTF-8, to
target\compile_bench\<commit>[-dirty]. It warns when the tree has
uncommitted changes, and fails when the test was skipped (no DXC) and
wrote nothing.

scripts/compile_bench_compare.py compares two runs program by program:
instructions, HLSL and DXIL bytes and the median DXC time, with the
head / base ratio and the geometric mean of the ratios. It notes what
makes the numbers not comparable (a dirty tree, another DXC, build,
CPU, set or number of compiles). It reports and does not judge: exit 0
whatever the numbers, 2 for unreadable input. Standard library only;
its tests: python -I -m unittest discover -s scripts -p
"test_compile_bench_compare.py".

README: a short paragraph under Tests on the benchmark and the two
scripts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…benchmark (xcl-dev#1269)

A median over a set hides the few multi-megabyte programs where most of
the compile time goes. On the full set (ae43075, release,
Ryzen 5 3600) the five slowest of 44 programs took 486 s of the 693 s
total DXC time.

XCL_COMPILE_BENCH=large (compile_bench.ps1 -Set large) measures only that
tail: base, divergent and resource programs at 8 000, 20 000 and 40 000
operations, native and split wave64 with 4 windows, 18 programs. The
larger ones cross the source sizes at which dxc.rs lowers the
optimisation level.

Every run now prints the programs from the slowest compile to the
fastest and a summary (median, nearest-rank p90, maximum, total and the
share of the slowest tenth of the programs), which also goes into
compile_bench.json. The CSV is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…xcl-dev#1269)

Comparing two runs showed every ratio, so a 2 % wobble looked like a
result. Measured on one machine (Ryzen 5 3600, release): the small set's
medians moved by at most 1.9 % over 5 runs, and the 3 compiles of one
full-set run spread by 1.4 to 2.8 % (median), single compiles by up to
17 %, which the median of 3 absorbs.

compile_bench_compare.py now marks each program "size" when its HLSL or
DXIL size differs at all, else "time" when its DXC time moved by more
than the noise (5 % by default, --noise to change it), and counts both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants