diff --git a/CHANGELOG.md b/CHANGELOG.md index e686c9c..6717f5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,12 @@ remains unsupported. ### Added - Added the VOP3A (`_e64`) encodings of eleven gfx1030 VOP2 integer forms (`v_mul_{i32_i24,hi_i32_i24,u32_u24,hi_u32_u24}`, `v_{min,max}_{i32,u32}`, `v_xnor_b32`, `v_sub_nc_u32`, `v_subrev_nc_u32`) and of the sixteen Wave32 integer compares (explicit SGPR mask destination, `s_cbranch_vccz` through `vcc_lo`, a translation error for reads of runtime-only SGPR results) as semantic-registry encoding variants, with VGPR sources only. New fixtures `vop3-integer` and `vop3-compare` with IR and MSL goldens, and an independent guide-derived oracle (`tests/validation/tests/vop3_{integer,compare}.rs`) that agrees on both reference interpreters and on native Metal. Part of #215. +- Added `scripts/cpu-tests.sh`, which lists the default-feature workspace test targets and runs + deterministic shards of them (`--shard K/N`), with `--check N` showing every target lands in + exactly one shard. It does not replace `cargo test --locked --workspace` or + `scripts/test-gpu.sh`. `docs/testing/cpu-coverage.md` records local CPU gate timings on one + Apple M4 host (about 40 s wall time; one loader target takes about 19 s) and shows that the 2- and + 3-shard unions match the full gate's 681 passed and 34 ignored tests (#159). - Added guest texture binding through D3D12-style descriptor tables (#303): shader-visible CBV_SRV_UAV and sampler heaps, `CreateShaderResourceView` for one-level RGBA8 and BC1 2D textures, a point/clamp `CreateSampler`, a root signature with one pixel-stage SRV table and one sampler table, and `SetDescriptorHeaps`/`SetGraphicsRootDescriptorTable` in `crates/loader/src/graphics.rs`, plus `NativeCompute::render_rgba8_sampled_bc1`. Verified locally on an Apple M5 Pro under Metal validation: a guest draw with the translated `image_sample_lz` pixel stage matches the software reference and hand-derived images on 16 of 16 pixels for two RGBA8 textures and 64 of 64 for an 8×8 BC1 texture. A wrong descriptor slot changes the image, off-centre and out-of-range coordinates point-sample with clamping, and a rejected binding, draw shape or resource state never reaches the backend. The software reference samples BC1 with the spec-exact decoder, while Apple's hardware rounds BC1's interpolated palette entries differently (171/84 against 170/85), so the BC1 fixtures use only endpoint colours. Not yet reachable from guest imports. Not yet independently accepted. - Added four Wave32 gfx1030 VOP2 select and carry forms through the semantic registry. Conditional select, add with carry and both subtract orders with borrow use a per-lane VCC bit and have a guide-derived oracle that passes on both CPU interpreters and on native Metal (local Apple M5, API and shader validation); independent acceptance is pending. Part of #215. - Added decoding and Metal shader translation for twelve Wave32 VOPC 16-bit integer compares (#215). The signed and unsigned forms compare the low 16 bits of each source and write the Wave32 VCC mask. CPU verification covers 1,572 compiler acceptance cases and 408 rejections from the guide-derived oracle, which also passes on native Metal (1,572 cases in 1,420 programs on a local Apple M5 under API and shader validation); acceptance is pending. diff --git a/docs/README.md b/docs/README.md index 5008656..e542771 100644 --- a/docs/README.md +++ b/docs/README.md @@ -41,6 +41,7 @@ either path. The [changelog](../CHANGELOG.md) records notable changes. ## Testing, validation, and benchmarks - [Engineering progress](progress.md) — Verification commands, metric definitions, and open release gates. +- [CPU test runtime and shard selection](testing/cpu-coverage.md) — Measured CPU gate cost and deterministic test-target shards. - [Test inventory comparison](testing/test-inventory.md) — Detect missing or newly ignored Cargo tests across commits. - [Persistent resource and translated rendering acceptance](testing/x9-acceptance.md) — Pinned upstream tests, native ARM64 results and unsupported cases. - [Baseline acceptance](testing/phase-02-baseline.md), [Phase 01 assurance](testing/phase01-assurance.md), and [independent reviews](testing/review-log.md) — Candidate-specific results and release findings. diff --git a/docs/testing/cpu-coverage.md b/docs/testing/cpu-coverage.md new file mode 100644 index 0000000..96b8558 --- /dev/null +++ b/docs/testing/cpu-coverage.md @@ -0,0 +1,98 @@ +# CPU test runtime and shard selection + +This page records what the CPU test gate costs and describes +`scripts/cpu-tests.sh`, which splits that gate into deterministic shards. The +shards are a convenience for local iteration and parallel runners. They do not +replace any gate: `cargo test --locked --workspace` stays the full CPU gate, and +`scripts/test-gpu.sh` stays the GPU gate. + +## What counts as a CPU test + +A CPU test is any test target that `cargo test --locked --workspace` builds with +default features. Targets that need a Metal device are either behind the +`gpu-tests` feature (`xenora-metal`, `xenora-loader`, `xenora-ffi`) or marked +`#[ignore = "requires a native Metal device ..."]` (for example +`tests/validation/known_answers.rs`), so the default run does not execute them. +`scripts/test-gpu.sh` runs them. The selection uses Cargo's own target list, so +it never decides by file name which tests are CPU tests. + +One exception: two `xenora-ffi` library tests +(`test_resource_management_lifecycle_and_validation` and +`test_deferred_resource_retirement_waits_for_in_flight`) call +`xenora_session_create_texture`. When a Metal device is available, that +function creates one and uploads a texture; when none is available, it +continues without one. So on a Mac these default tests do touch Metal, and they +are not GPU verification. The selection keeps them because the full gate runs +them. + +## Usage + +```sh +scripts/cpu-tests.sh --list # every default-feature test target, sorted +scripts/cpu-tests.sh --shard 2/3 # run shard 2 of 3 +scripts/cpu-tests.sh --check 3 # show that 3 shards cover every target once +``` + +Targets are sorted by package, kind and name. Shard K of N takes each target +whose zero-based index i satisfies i mod N = K - 1. Shard 1 also runs the +workspace doctests. A new target joins a shard without any edit to the script. +The script exits 1 when any selected target fails or when Cargo cannot build the +workspace. Partial target lists never run. It exits 2 on bad arguments. +It uses at most four Cargo build jobs unless `CARGO_BUILD_JOBS` says otherwise. + +## Measurements + +Host: Apple M4 (10 cores), macOS on ARM64, `cargo 1.100.0`, target +`aarch64-apple-darwin`, debug test profile, main at `d7f7d58`. All runs used a +warm build unless noted. These are single-host samples, not benchmarks. + +Full gate, `cargo test --locked --workspace`, three runs: 40.47 s, 39.99 s and +40.12 s wall time. It ran 82 test targets plus doctests (92 `test result` lines): +681 passed, 0 failed, 34 ignored. + +Running each target alone through `cargo test -p ` adds up +to 79.5 s, because every invocation pays Cargo start-up. The five most expensive +targets, one sample each: + +| Target | Wall time | Passed / ignored | +| --- | --- | --- | +| `xenora-loader --test runtime_services` | 19.13 s | 23 / 0 | +| `xenora-loader --test cpu_known_answers` | 8.18 s | 42 / 5 | +| `xenora-loader --test probe_delay_imports` | 3.53 s | 8 / 0 | +| `xenora-loader --test probe_truncation` | 3.32 s | 1 / 0 | +| `xenora-ffi --lib` | 2.16 s | 18 / 0 | + +`runtime_services` alone is about a quarter of the summed cost. Any shard that +contains it takes at least about 19 s. The next step for a faster gate is +profiling that target, not finer sharding. + +Shard runs, one sample each, sequential on the same host: + +| Selection | Wall time per shard | Passed | Failed | Ignored | Result lines | +| --- | --- | --- | --- | --- | --- | +| 2 shards | 37.98 s, 4.55 s | 360 + 321 = 681 | 0 | 21 + 13 = 34 | 51 + 41 = 92 | +| 3 shards | 6.54 s, 29.55 s, 6.27 s | 160 + 282 + 239 = 681 | 0 | 9 + 12 + 13 = 34 | 38 + 27 + 27 = 92 | + +For both shard counts, the union of the shards matches the full gate exactly +in passed, failed, ignored and result-line counts. Round-robin by name does +not balance cost: with one dominant target, parallel shards finish no sooner +than the shard that holds it. Running the shards one after another costs more +than the full gate, because each target pays Cargo start-up. + +## Verification of the script + +- `--check N` for N = 1 to 4 reports that all 82 targets are covered once. +- `--check 3` fails when the selection expression is changed to skip a + residue or to repeat a target. +- `--list` exits 1 with an error when a crate fails to compile, instead of + printing a shortened list. +- Bad arguments (`--shard 0/2`, `--shard 3/2`, `--check x`) exit 2. + +## Limitations + +- Timings come from one machine and few samples. Re-measure before using them + for decisions. +- Shard membership changes when targets are added or renamed. Shards from two + different commits are not comparable. +- The experiment workspace `experiments/x1` is outside the selection. CI runs + it separately. diff --git a/scripts/cpu-tests.sh b/scripts/cpu-tests.sh new file mode 100755 index 0000000..1ee384f --- /dev/null +++ b/scripts/cpu-tests.sh @@ -0,0 +1,113 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-3.0-or-later +# +# Deterministic CPU-only selection of the workspace test targets (#159). +# +# scripts/cpu-tests.sh --list print every default-feature test target +# scripts/cpu-tests.sh --shard K/N run shard K of N (1 <= K <= N) +# scripts/cpu-tests.sh --check N prove N shards cover every target once +# +# Targets are the ones `cargo test --locked --workspace` builds with default +# features, sorted by package, kind and name. Shard K takes every target whose +# index i in that order has i mod N == K - 1; shard 1 also runs the doctests. +# New targets join a shard automatically. The selection never replaces the full +# gate, `cargo test --locked --workspace`; `gpu-tests` targets stay in +# scripts/test-gpu.sh. +set -eu +cd "$(dirname "$0")/.." +export CARGO_BUILD_JOBS=${CARGO_BUILD_JOBS:-4} + +usage() { + echo "usage: $0 --list | --shard K/N | --check N" >&2 + exit 2 +} + +# Prints "package selector..." for each test target, one per line, sorted. +# Fails when Cargo cannot build every target, so a partial list never runs. +targets() { + json=$(cargo test --locked --workspace --no-run --message-format=json) || { + echo "cpu-tests: cargo could not build the workspace test targets" >&2 + exit 1 + } + printf '%s\n' "$json" | python3 -c ' +import json, sys +rows = set() +for line in sys.stdin: + m = json.loads(line) + if m.get("reason") != "compiler-artifact" or not m.get("executable"): + continue + if not m["profile"]["test"]: + continue + pkg = m["package_id"].split("#")[-1].split("@")[0] + kind, name = m["target"]["kind"][0], m["target"]["name"] + sel = {"test": "--test " + name, "bin": "--bin " + name}.get(kind, "--lib") + rows.add(f"{pkg} {sel}") +if not rows: + sys.exit("cpu-tests: no test targets found; does the workspace build?") +print("\n".join(sorted(rows))) +' +} + +# Keeps the lines of stdin that belong to shard $1 of $2. +select_shard() { + awk -v k="$1" -v n="$2" '(NR - 1) % n == k - 1' +} + +parse_count() { + case $1 in '' | *[!0-9]*) usage ;; esac + [ "$1" -ge 1 ] || usage +} + +[ $# -ge 1 ] || usage +case $1 in +--list) + [ $# -eq 1 ] || usage + targets + ;; +--check) + [ $# -eq 2 ] || usage + parse_count "$2" + all=$(targets) + total=$(printf '%s\n' "$all" | wc -l | tr -d ' ') + union=$(k=1; while [ "$k" -le "$2" ]; do + printf '%s\n' "$all" | select_shard "$k" "$2" + k=$((k + 1)) + done) + if [ "$(printf '%s\n' "$union" | sort)" != "$(printf '%s\n' "$all" | sort)" ]; then + echo "cpu-tests: $2 shards do not cover the $total targets exactly once" >&2 + exit 1 + fi + echo "cpu-tests: $2 shards cover all $total targets exactly once" + ;; +--shard) + [ $# -eq 2 ] || usage + k=${2%/*} + n=${2#*/} + [ "$k/$n" = "$2" ] || usage + parse_count "$k" + parse_count "$n" + [ "$k" -le "$n" ] || usage + all=$(targets) + selected=$(printf '%s\n' "$all" | select_shard "$k" "$n") + failed=0 + # Word splitting of $line is intended: it holds "package --test name". + while IFS= read -r line; do + [ -n "$line" ] || continue + echo "cpu-tests[$k/$n]: cargo test --locked -p $line" + # shellcheck disable=SC2086 + cargo test --locked -p $line || failed=$((failed + 1)) + done <&2 + exit 1 + fi + echo "cpu-tests[$k/$n]: all selected targets passed" + ;; +*) usage ;; +esac