Files
metal2vulkan/scripts/rerecord-venue
Anees Iqbal d54a1a5568 Validation: the MoltenVK backend, its C3 venue and the old engine's baseline are deleted
The validation executor's Vulkan side runs on Linux through native ICDs
and the runtime. No lane records MoltenVK rows any more, and no MoltenVK
venue is wanted. This commit deletes the MoltenVK backend from the
store up.

Before the deletion, git grep at e35d9098c0 showed these readers of
Backend::Moltenvk rows outside tests:
- C3's input (c3.rs: C3Input::moltenvk, the baseline, the old-mismatch
  ledger), its venue kind (venues.rs), the evidence census
  (index.rs: the index's candidate table and evidence_status);
- the store's own layout check, shard rewrite and rekey;
- the batch's worker store, which linked the other backend's rows;
- the corpus-moltenvk binary, the host and driver checks
  (candidate.rs, platform/compute.rs) and candidate_batch's CPU refusal.
Every one goes or loses its MoltenVK arm here. No reader is left.

What goes:
- The corpus-moltenvk binary (Cargo.toml entry included), and
  Backend::Moltenvk and BatchBackend::Moltenvk. Backend keeps one
  variant, Vulkan. Collapsing it is a follow-up commit.
- corpus/observations/moltenvk: 64 shards, 4,809 rows. 4,802 of them
  are old-engine rows in about 60 slots: apple-m3-max-moltenvk 1,137,
  the byte-exact-* and local-* runs, and probe slots. The other 7 are
  engine rows of apple-m3-max-moltenvk@engine.
  corpus/observations/refusals/moltenvk: 16 shards, 6 refusals.
- The store's MoltenVK shards: its layout check, the aligned rewrite,
  the refusal follow and the rekey now read the Vulkan backend alone.
  The batch's worker store links only the Metal rows. The index stores
  the Vulkan candidates alone, and evidence_status's rows have no
  moltenvk column (corpus-status's evidence line loses it too).
- C3's MoltenVK venue (VenueKind::Moltenvk, c3-venues.json's
  apple-m3-max-moltenvk entry) and with it the old engine's baseline:
  - Population::OldEngineMatched, the baseline closure and the "new
    mismatch" count (SlotReport::new_mismatches);
  - the old-mismatch ledger (LedgerRow, C3Report::ledger, stale_causes,
    unexplained);
  - the reviewed list's old_mismatches part (OldMismatch,
    ListPart, EntryRow::part), and Venues::baseline and by_environment.
  The venue list's MoltenVK-driver check goes too. VenueDevice's
  metal_environment_id, which only an Apple GPU's venue device set,
  goes with Venue::identities_compared_with: a venue run is held to
  all of its devices' identities.
- c3-reviewed.json: the 12 old_mismatches entries (all signed off),
  and the 10 fast_math_regrouping readings whose only observation was
  the apple-m3-max-moltenvk@engine slot. These are the linked-single
  radix 5/7/11/13/15 zero-write cases, two each, all signed off. A
  reading must list an observation, and theirs named a slot that no
  longer exists. A regrouping mismatch of those cases on another venue
  now reads unreviewed until a reading lists that venue's row. The 12
  apple_reading entries are untouched; none named a MoltenVK slot.
- corpus/authored-compile.tsv: the moltenvk-m3 column keeps its cells
  but drops their artifact digests (2,255 cells). Only a C3 venue's
  profile keeps a digest, and moltenvk-m3 is no venue's now. This is
  what a bless writes; the profile itself stays, since the translator's
  tests read it.
- scripts/rerecord-venue's moltenvk kind (and its Homebrew validation
  layer path), and scripts/rerecord-commit's MoltenVK build, install
  and shard paths. docs/VALIDATION.md loses corpus-moltenvk, and its
  venue list names what each venue covers.
- In the docs, the robustness leg's "profile-leg" (validation README,
  corpus README) is now "profile", which 79d95a2887 missed.

What C3 still decides: per venue of c3-venues.json, lavapipe on arm64
and x86 (the public cases) and the 780M, the Iris Xe RPL-P and the RTX
5080 Laptop (every Metal-qualified case), each case's verdict in the
venue's engine slot by the same rules as before (match, reviewed,
device_gap, out_of_scope, reference_gap, mismatch, refused, stale,
missing). It holds when every slot holds, every reviewed observation
holds, every listed reference gap is recorded, every entry and recorded
reference gap is signed off, and no sign-off is refused. It no longer
holds anything to an old-engine population, counts new mismatches
against one, or keeps a ledger of old-engine mismatch causes.

Tests:
- c3/tests.rs: the synthetic MoltenVK venue becomes a native GPU venue
  (GPU, Metal-qualified, still described by the moltenvk-m3 capture).
  Deleted: the baseline test (moltenvk_must_cover_every_case...), the
  ledger test, and the Apple-GPU Metal-environment test.
  Rewritten: the population tests (two populations now) and the
  reference-gap test (on lavapipe's public population). The schema test
  checks its review fields on a reading. The venue checks lose the
  baseline and driver cases.
- index.rs and store.rs tests run their toy rows as Vulkan's. The
  cross-backend checks have no second backend and go.
- vulkan_batch/tests.rs: the MoltenVK batch test goes. The install test
  refuses a Metal batch's record in place of a MoltenVK one.
- tests/integration: the store-layout and worker tests drop
  corpus-moltenvk. fast_trig_within_apples_bound reads the Vulkan store
  and wants one row per venue (5). It wanted 10, which the robustness-off
  and MoltenVK rows made up.

Device-level MoltenVK accommodations stay for the follow-up commit with
the MSL helper, once a grep shows no Vulkan run on macOS: the loader
word, MoltenVK's withheld diagnostics, coverage's robust-buffer host
class and the pipeline flag.

Verified: cargo fmt; no committed observation path, C3 list entry, venue
or script names the MoltenVK backend (git grep). The compile gate of the
Q3 commits follows as a potluck job.
2026-11-20 22:15:53 -08:00

301 lines
16 KiB
Bash
Executable File

#!/usr/bin/env bash
# Re-record one execution venue at one product build: the engine batch of the
# venue's backend over the cases with a current Metal row, into an out
# directory kept on this host, resumable and measured. Metal is never run.
#
# scripts/rerecord-venue --venue ID [--kind native-gpu|cpu-icd]
# [--icd lavapipe] [--ref SHA] [--out-root DIR]
# [--case-id HASH]...
# [--limit CASES] [--budget SECONDS] [--cpus N] [--slot NAME]
# [--private-corpus DIR] [--metal-environment-id ID] [--retry-failed]
# [--profiles-layer P]
#
# - The venue. --venue is the operator environment ID its rows record (the batch stores them in
# its engine slots). A venue of crates/metal2vulkan-validation/cutover/c3-venues.json takes its kind from
# there; any other needs --kind. --icd names the CPU
# ICD of a cpu-icd venue (lavapipe, the default and only one). --profiles-layer P records a restricted run: every
# run with the device restricted to the committed profile P, its rows in the ID@engine@P
# slots (a capability profile on a CPU ICD, or on a GPU where no CPU ICD takes it, or a GPU
# restricted to another profile of its own driver class). Where the device lacks what P states,
# each run records a typed refusal (not_supported{profile_exceeds_device}, naming the members);
# where the profiles layer cannot present P as the product reads it (a requirements document
# its regeneration did not complete for the layer), the batch refuses before its first run and
# the round stops. The restricted context runs at P's own API version (1.2 at least).
# - The build. HEAD must be --ref (default: HEAD) with no tracked file changed, so every row is
# of the ref's product. Coverage and C3 count a row only at the build that recorded it: record
# every venue at one ref, then commit the rows with scripts/rerecord-commit at that ref (or a
# descendant that changes no product source). Any product change between recording and that
# commit leaves every row stale.
# - Metal is never run. The batch selects the cases with a current Metal row in
# --metal-environment-id (default apple-m3-max-macos27.0.1), or each --case-id (each must have
# one), and compares against the committed row.
# - Where it runs. native-gpu: this host's GPU, `corpus-vulkan --batch --device-type gpu`. cpu-icd:
# `corpus-vulkan --batch --device-type cpu` inside scripts/linux-gate (--cpus N, default 6;
# --slot NAME, default rerecord; --icd; --private-corpus DIR, read-only, for the private cases,
# which the native venues read through crates/metal2vulkan-validation/corpus/local), lavapipe at its native width.
# - Resumable. The out directory is OUT_ROOT/VENUE/scratch/batch-<12 hex of the ref> (OUT_ROOT
# defaults to ~/.cache/m2v-rerecord) and is kept between invocations: the batch skips every
# case its done-list holds and refuses an out directory of another build or venue
# (build.json). An invocation runs the batch in rounds of --limit cases (default 50 on a GPU, 200
# on a CPU ICD) until nothing is pending or --budget seconds (default 1800) are spent; exit 3
# means runs are pending, or some ended `failed` (a tooling failure, such as Metal's compiler
# service dropping its connection under load): run it again at the same ref, with
# --retry-failed for those. --retry-failed first drops the done-list's `failed` runs, which
# recorded no evidence, so they run again; a timeout, a device crash, or a device-wait timeout
# is never retried (the GPU hang protocol owns those).
# - GPU safety. One run at a time; no round starts while the hang tripwire (~/.cache/m2v-gpu/hang,
# /tmp/m2v-gpu.hang) exists, and the batch checks it before every run; each run is killed whole
# at 300 s, with device waits bounded at 60 s; the batch stops after a run that hung or crashed
# the device. Each GPU round is under a 2-hour alarm; if it fires, this script writes the
# tripwire itself (only a human clears it, after the suspected-hang protocol).
# - Measured. OUT_ROOT/VENUE/summary.txt (printed at the end) has the build time, each round's
# exit, runs, pending count and elapsed time, --batch-report's build, report, and slowest lines,
# and, for a venue of c3-venues.json, how many rows and refusals record each device identity and
# how many a device the venue does not allow (C3 reads those as stale). done.tsv holds every run's seconds.
# - Output. The out directory (build.json, done.tsv, rows.jsonl, refusals.jsonl, logs/) is what
# scripts/rerecord-commit installs; copy it as it is to the checkout that commits the rows.
# Nothing tracked is written. A GPU venue's executor runs from a copy in OUT_ROOT/VENUE/bin. A
# restricted run's directory is OUT_ROOT/VENUE@P.
# Exit: 0 nothing pending; 3 runs pending; 86 a hang tripwire stopped it; 2 a usage or
# precondition error; 1 any other failure.
set -o pipefail
usage() {
sed -n '2,/^# Exit:/p' "$0" | sed 's/^# \{0,1\}//' >&2
exit 2
}
venue=
kind=
icd=lavapipe
ref=
out_root=${XDG_CACHE_HOME:-$HOME/.cache}/m2v-rerecord
case_flags=
limit=
budget=1800
cpus=6
slot=rerecord
private=
metal=apple-m3-max-macos27.0.1
retry=
profile=
while [ "$#" -gt 0 ]; do
case "$1" in
--venue) [ "$#" -ge 2 ] || usage; venue=$2; shift 2 ;;
--kind) [ "$#" -ge 2 ] || usage; kind=$2; shift 2 ;;
--icd) [ "$#" -ge 2 ] || usage; icd=$2; shift 2 ;;
--ref) [ "$#" -ge 2 ] || usage; ref=$2; shift 2 ;;
--out-root) [ "$#" -ge 2 ] || usage; out_root=$2; shift 2 ;;
--case-id) [ "$#" -ge 2 ] || usage; case_flags="$case_flags --case-id $2"; shift 2 ;;
--limit) [ "$#" -ge 2 ] || usage; limit=$2; shift 2 ;;
--budget) [ "$#" -ge 2 ] || usage; budget=$2; shift 2 ;;
--cpus) [ "$#" -ge 2 ] || usage; cpus=$2; shift 2 ;;
--slot) [ "$#" -ge 2 ] || usage; slot=$2; shift 2 ;;
--private-corpus) [ "$#" -ge 2 ] || usage; private=$2; shift 2 ;;
--metal-environment-id) [ "$#" -ge 2 ] || usage; metal=$2; shift 2 ;;
--retry-failed) retry=1; shift ;;
--profiles-layer) [ "$#" -ge 2 ] || usage; profile=$2; shift 2 ;;
-h|--help) usage ;;
*) echo "rerecord-venue: unknown argument $1" >&2; usage ;;
esac
done
fail() { echo "rerecord-venue: $*" >&2; exit 2; }
[ -n "$venue" ] || fail "--venue is required"
case "$venue$case_flags$slot$icd$profile" in
*[!A-Za-z0-9_.@+\ -]*) fail "IDs, cases, slot, and ICD are plain words" ;;
esac
case "$budget" in ''|*[!0-9]*) fail "--budget takes whole seconds" ;; esac
case "$limit" in *[!0-9]*) fail "--limit takes a whole number" ;; esac
case "$icd" in lavapipe) ;; *) fail "--icd is lavapipe" ;; esac
root=$(git rev-parse --show-toplevel) || fail "not in a git checkout"
cd "$root" || exit 2
head=$(git rev-parse HEAD) || exit 2
ref=$(git rev-parse --verify "${ref:-HEAD}^{commit}") || fail "no commit ${ref:-HEAD}"
[ "$head" = "$ref" ] || fail "HEAD $head is not --ref $ref: check the ref out"
git diff --quiet HEAD -- || fail "tracked files differ from $ref: the build would not be its"
declared=$(python3 - "$root/crates/metal2vulkan-validation/cutover/c3-venues.json" "$venue" <<'PY'
import json, sys
for v in json.load(open(sys.argv[1]))["venues"]:
if v["environment_id"] == sys.argv[2]:
kind = {"native_gpu": "native-gpu", "cpu_icd": "cpu-icd"}.get(v["kind"], v["kind"])
print(kind)
PY
) || fail "read crates/metal2vulkan-validation/cutover/c3-venues.json"
if [ -n "$declared" ]; then
declared_kind=$declared
[ -z "$kind" ] || [ "$kind" = "$declared_kind" ] ||
fail "$venue is a $declared_kind venue in c3-venues.json, not $kind"
kind=$declared_kind
fi
case "$kind" in
native-gpu) exe=corpus-vulkan; device=gpu; : "${limit:=50}" ;;
cpu-icd) exe=corpus-vulkan; device=cpu; : "${limit:=200}" ;;
'') fail "$venue is not in c3-venues.json: pass --kind" ;;
*) fail "--kind is native-gpu or cpu-icd" ;;
esac
[ "$limit" -gt 0 ] 2>/dev/null || fail "--limit must be positive"
hex=$(printf '%s' "$ref" | cut -c1-12)
d=$out_root/$venue${profile:+@$profile}
scratch=$d/scratch
out=$scratch/batch-$hex
mkdir -p "$d/rounds" "$scratch" || exit 1
n=0
while [ -e "$d/summary.$n.txt" ]; do n=$((n + 1)); done
[ -e "$d/summary.txt" ] && mv "$d/summary.txt" "$d/summary.$n.txt"
log=$d/summary.txt
start=$(date +%s)
elapsed() { echo $(( $(date +%s) - start )); }
{
echo "rerecord-venue $venue ($kind, $exe on a $device device) at $ref on $(hostname) $(uname -sm), $(date)"
echo "out $out"
echo "cases:${case_flags:- every case with a current Metal row in $metal}"
[ -z "$profile" ] || echo "restricted to the profile $profile (--profiles-layer)"
} > "$log"
trip=$HOME/.cache/m2v-gpu/hang
tripped() { [ -e "$trip" ] || [ -e /tmp/m2v-gpu.hang ]; }
if [ -n "$retry" ] && [ -f "$out/done.tsv" ]; then
# Keep every complete line but the failed runs' (the third field); a cut last line, which the
# batch would drop anyway, goes too.
python3 - "$out/done.tsv" <<'PY' || exit 1
import os, sys
path = sys.argv[1]
text = open(path).read()
kept = [line for line in text[: text.rfind("\n") + 1].splitlines(True)
if line.split("\t")[2:3] != ["failed"]]
open(path + ".next", "w").write("".join(kept))
os.replace(path + ".next", path)
PY
echo "retry: dropped the failed runs from done.tsv" >> "$log"
fi
restrict=${profile:+ --profiles-layer $profile}
batch_flags="--device-type $device --metal-environment-id $metal --environment-id $venue$case_flags$restrict"
stopped=
pending=unknown
if [ "$kind" = cpu-icd ]; then
# The rounds run in the container; /scratch is $scratch.
inner='set -u
start=$(date +%s)
cargo build --release -p metal2vulkan-validation --bin corpus-vulkan -j "$CARGO_BUILD_JOBS" >&2 || exit 1
echo "BUILD $(( $(date +%s) - start ))s"
bin=$CARGO_TARGET_DIR/release/corpus-vulkan
unset LP_NATIVE_VECTOR_WIDTH
echo "DEVICE $(vulkaninfo --summary 2>/dev/null | grep -m1 deviceName | sed "s/.*= //")"
i=0
rc=0
while [ $(( $(date +%s) - start )) -lt '"$budget"' ]; do
i=$((i + 1))
"$bin" --batch '"$batch_flags"' --corpus crates/metal2vulkan-validation/corpus --out /scratch/batch-'"$hex"' \
--run-timeout 300 --gpu-wait-timeout 120 --limit '"$limit"' < /dev/null > /scratch/round.out
rc=$?
echo "ROUND $i exit=$rc runs=$(grep -c "^batch-run " /scratch/round.out) pending=$(sed -n "s/^batch-pending runs=//p" /scratch/round.out) $(( $(date +%s) - start ))s"
grep -E "^batch-(summary|slowest)" /scratch/round.out | sed "s/^/ /"
[ "$rc" -eq 0 ] || break
grep -q "^batch-pending runs=0$" /scratch/round.out && break
done
"$bin" --batch-report --corpus crates/metal2vulkan-validation/corpus --out /scratch/batch-'"$hex"' \
--metal-environment-id '"$metal"' --environment-id '"$venue$restrict"' > /scratch/report.txt 2>&1
exit $rc'
gate_flags="--cpus $cpus --slot $slot --icd $icd --scratch $scratch"
[ -z "$private" ] || gate_flags="$gate_flags --private-corpus $private"
# shellcheck disable=SC2086
scripts/linux-gate $gate_flags -- bash -c "$inner" > "$d/gate.log" 2>&1
rc=$?
grep -E '^(BUILD|DEVICE|ROUND| batch-)' "$d/gate.log" >> "$log"
echo "linux-gate exit=$rc $(elapsed)s" >> "$log"
[ "$rc" = 0 ] || stopped="linux-gate exit $rc: $(grep -v '^[[:space:]]*$' "$d/gate.log" | tail -n 1 | cut -c1-400)"
pending=$(grep '^ROUND ' "$d/gate.log" | tail -n 1 | sed -n 's/.* pending=\([0-9]*\) .*/\1/p')
cp "$scratch/report.txt" "$d/report.txt" 2>/dev/null
else
if tripped; then echo "rerecord-venue: hang tripwire present; no device work" >&2; exit 86; fi
cargo build --release -p metal2vulkan-validation --bin "$exe" > "$d/build.txt" 2>&1 ||
{ echo "BUILD FAILED" >> "$log"; tail -n 30 "$d/build.txt" >> "$log"; cat "$log"; exit 1; }
echo "build $(elapsed)s" >> "$log"
target=$(cargo metadata --format-version 1 --no-deps |
python3 -c 'import json, sys; print(json.load(sys.stdin)["target_directory"])') || exit 1
# The batch runs its own executable once per run: a copy no later build in a shared target
# directory can replace mid-batch.
mkdir -p "$d/bin" && cp "$target/release/$exe" "$d/bin/$exe" || exit 1
bin=$d/bin/$exe
i=0
while [ "$(elapsed)" -lt "$budget" ]; do
if tripped; then stopped="hang tripwire present"; break; fi
i=$((i + 1))
round=$d/rounds/$(date +%s)-$i
# shellcheck disable=SC2086
perl -e 'alarm 7200; exec @ARGV' "$bin" --batch $batch_flags --corpus "$root/crates/metal2vulkan-validation/corpus" \
--out "$out" --run-timeout 300 --gpu-wait-timeout 60 --limit "$limit" \
< /dev/null > "$round.out" 2> "$round.err"
rc=$?
pending=$(sed -n 's/^batch-pending runs=//p' "$round.out" | tail -n 1)
echo "ROUND $i exit=$rc runs=$(grep -c '^batch-run ' "$round.out") pending=${pending:-?} $(elapsed)s" >> "$log"
grep -E '^batch-(summary|slowest)' "$round.out" | sed 's/^/ /' >> "$log"
if [ "$rc" = 142 ]; then
mkdir -p "$(dirname "$trip")"
echo "rerecord-venue: the 2-hour alarm ended a batch round of $venue at $ref, $(date)" > "$trip"
stopped="the alarm ended round $i; tripwire $trip written"
break
fi
if [ "$rc" != 0 ]; then
stopped="round $i exit $rc: $(tail -n 1 "$round.err" | cut -c1-600)"
break
fi
[ "$pending" = 0 ] && break
done
# shellcheck disable=SC2086
"$bin" --batch-report --corpus "$root/crates/metal2vulkan-validation/corpus" --out "$out" \
--metal-environment-id "$metal" --environment-id "$venue"$restrict > "$d/report.txt" 2>&1
fi
grep -E '^batch-(build|report|slowest)' "$d/report.txt" 2>/dev/null | cut -c1-400 >> "$log"
# A restricted run's rows record what the profiles layer reports; C3 judges unrestricted slots only.
if [ -n "$declared" ] && [ -z "$profile" ]; then
python3 - "$root/crates/metal2vulkan-validation/cutover/c3-venues.json" "$out" "$venue" >> "$log" 2>&1 <<'PY'
import collections, json, os, sys
venues, out, venue = sys.argv[1:4]
# The devices the venue allows (an allowed-device list).
allowed = next([d["identity"] for d in v["devices"]] for v in json.load(open(venues))["venues"]
if v["environment_id"] == venue)
fields = sorted(allowed[0])
allowed = {tuple(identity[f] for f in fields) for identity in allowed}
def records(name):
path = os.path.join(out, name)
if not os.path.exists(path):
return []
text = open(path).read()
return [json.loads(line) for line in text[: text.rfind("\n") + 1].splitlines() if line.strip()]
for name in ("rows.jsonl", "refusals.jsonl"):
found = collections.Counter(
tuple(r["environment"].get(f) for f in fields) for r in records(name))
other = {k: n for k, n in found.items() if k not in allowed}
print(f"identity {name}: {sum(found.values())} recorded, {sum(other.values())} of a device "
f"identity c3-venues.json does not allow")
for k, n in found.items():
print(f" {n} x {dict(zip(fields, k))}{'' if k in allowed else ' (not allowed)'}")
PY
fi
# The failed runs among each case's last: no evidence, so the venue is not complete.
failed=$(awk -F '\t' 'NF >= 3 { last[$1 FS $2] = $3 } END { n = 0; for (k in last) if (last[k] == "failed") n++; print n }' \
"$out/done.tsv" 2>/dev/null)
status=0
if [ -n "$stopped" ]; then
echo "STOPPED: $stopped" >> "$log"
echo "RESULT stopped" >> "$log"
status=1
tripped && [ "$device" = gpu ] && status=86
elif [ "$pending" = 0 ] && [ "${failed:-0}" != 0 ]; then
echo "RESULT failed=$failed: run this again at $ref with --retry-failed" >> "$log"
status=3
elif [ "$pending" = 0 ]; then
echo "RESULT complete" >> "$log"
else
echo "RESULT pending=$pending: run this again at $ref" >> "$log"
status=3
fi
echo "wall $(elapsed)s" >> "$log"
cat "$log"
exit "$status"