Files
metal2vulkan/scripts/rerecord-venue
T
Anees Iqbal c05c380139 Match the M3 Max under macOS 27.0.1: measurements, profile, Metal rows and MoltenVK venue
The macOS 27 work packet: the M3 Max moved to macOS 27.0.1, where MoltenVK gives it the M4's
deviceID. Its measurements, its MoltenVK profile, its Metal rows (now the C3 reference) and its
MoltenVK venue rows are taken again, and the tests follow.

Read Metal's NotMipmapped anisotropic footprint through MoltenVK at level 0:
On macOS 27 Metal's anisotropic filter reads a sampler without a mip filter
differently once its level clamp reaches 1/64: the runtime's NotMipmapped form
(nearest mip, lod [0, 0.25]) handed MoltenVK an anisotropic footprint that
was not Metal's NotMipmapped one, and the anisotropic lane failed on the M3
Max under macOS 27.0.1. Through Metal's own sampler (VkProperty::MetalSampler)
with anisotropy and equal min and mag filters the sampler now clamps to
[0, 0]: with equal filters the level has no filter left to choose, and Metal
answers that sampler as NotMipmapped bit for bit. With filters that differ no
clamp reads Metal's answer at maxAnisotropy 2 to 16; that stays a known gap in
docs/FAST-PATHS.md.

RUNTIME_VERSION moves (renumbered once for the composed batch): a run of an unchanged
artifact samples differently.

Verified: metal::sampler unit tests (24, including the new
metals_own_anisotropic_sampler_reads_not_mipmapped_at_level_zero) at a release
build; runtime_lane::anisotropic_filter::anisotropic_samples_answer_within_
their_bounds_of_metals passes on the M3 Max, macOS 27.0.1, MoltenVK 1.4.1
(it failed at the round's first composed tree and at 61a2efc7d3).

Take the M3 Max's macOS 27 measurements on MoltenVK's shared Apple identity:
MoltenVK's deviceID on an Apple GPU is the macOS release and the GPU's
highest families (MVKPhysicalDevice::getHighestGPUCapability), so under
macOS 27.0.1 the M3 Max reports 0x1B000209, the M4's identity, and takes the
M4's driver facts. The owner's rule: an answer fact holds on the shared
identity only where measured on both GPUs; a cost fact follows the M3 Max.

- MetalNormStorageWrites and DepthTestKeepsDenormals, measured on the M4:
  re-measured on the M3 Max under macOS 27.0.1 with the fact taken, every
  channel and texel Metal's; kept, the evidence in their docs.
- GraphicsCubeGradientRoute stays measured on the macOS 26.7 identity alone;
  the shared identity's graphics route stays unmeasured.
- The interlocked pass: on the M3 Max under macOS 27.0.1 split ran about a
  quarter faster than whole (wall 721-769 us against 974-1045, GPU 671-719
  against 914-964, two runs of three rounds of 30 frames at 1920x1080
  RGBA16Float), so the shared identity's row moves from
  InterlockedPassWholeFaster to InterlockedPassSplitNoSlower. The M4's own
  measurement (whole faster) is in the row's doc and in docs/FAST-PATHS.md's
  known gaps. RUNTIME_VERSION 1190 on this branch covers it.
- APPLE_M3_MAX and APPLE_M4 say what the deviceID is.

Verified: the facts and timings on the M3 Max (macOS 27.0.1, MoltenVK 1.4.1)
through runtime-lane tests at the round's first composed tree with these facts; the
device::tests::driver_facts unit tests run at the rebased tip before landing.

Hold the degrade-notice lane to the resolves the device actually makes:
passes_degrade_once_per_kind expected the exact resolve and the device's
rounded one to be announced wherever the driver's RGBA8Unorm average at 4
samples is measured as Metal's, assuming a texture of 8 samples exists. The
M3 Max (macOS 27.0.1, MoltenVK 1.4.1) makes none at 8 samples, so neither
is announced there, and the lane failed. The filter now expects those two
where the average is not measured as Metal's or where the device makes an
8-sample texture.

Verified: runtime_lane::degrade_notices::passes_degrade_once_per_kind passes
on the M3 Max (it failed at 61a2efc7d3 and the round's first composed tree).

Write the tessellation test's vertex output as Metal's compiler does:
authored_tessellation_executes_native_patch_inputs hand-writes its AIR, and
its post-tessellation output carried metadata Metal's compiler does not
write (Xcode 27, every macOS target 13 to 27 checked): air.location_index on
a vertex output. Our AIR reader refused it (Abi(UnknownKey) for
air.location_index on a vertex output), as it should for a key the compiler
never writes there. The output now carries air.vertex_output with its
user(locn0) name, its type name and its argument name, as the compiler emits
it.

Verified: metal::tests::graphics::authored_tessellation_executes_native_
patch_inputs passes on the M3 Max, macOS 27.0.1 (it failed at 61a2efc7d3 and
the round's first composed tree).

Wrap the driver-facts claims test's doc at the line width:
The interlocked-pass sentence the shared-identity commit rewrote ran past
the 100-column doc width. No other change.

Hold the unmeasured-identity test to the macOS 27 identity's split form:
an_unmeasured_identity_takes_its_drivers_defects_alone still expected the
moltenvk-m4 capture to take InterlockedPassWholeFaster, which the shared
macOS 27 identity no longer does (it takes InterlockedPassSplitNoSlower, the
M3 Max's measurement). Found by the device::tests::driver_facts run at the
rebased tip.

Name the format where the formats capture and the product's query differ:
the_formats_capture_is_the_product_queried_formats_of_the_venue_device
compared every format's masks without naming the format, so a failure on
the M3 Max showed two masks and no format. Each assert now names it.
Test-only.

Capture the M3 Max's MoltenVK profile under macOS 27.0.1:
The reference Mac runs macOS 27.0.1 (26A434) now. Its moltenvk-m3 capture
(vulkaninfo --json and corpus-vulkan --capture-formats, Homebrew MoltenVK
1.4.1, vulkan-tools 1.4.350.1) is regenerated through
scripts/regen-device-profiles. Only the identity moved: MoltenVK's deviceID
on an Apple GPU is the macOS release and the GPU family, so the M3 Max now
reports 0x1B000209 (452985353), the M4's identity, and every capability,
limit and format mask is as before. c3-venues.json declares the new
identity.

The two captures now differ only in allocation sizes, which no translation
reads, so they derive one translation key:
- candidate::platform::profiles: a run on the M4 held to the M3 Max venue
  stops on the device name alone (the venue's identity guard, not product
  behaviour), and proceeds where the venue allows the M4.
- c3::tests: the M4's capture passes check_profiles as a second device of
  the venue; the list still refuses it for naming the M3 Max's Metal
  environment.
- device::tests::driver_facts: moltenvk-m3 takes the shared identity's facts;
  the macOS 26.7 identity (APPLE_M3_MAX), measured but with no committed
  capture now, moves to MEASURED_WITHOUT_PROFILE and keeps its coverage
  through a description at that deviceID, graphics cube route included.
- tests::engine_sampler_unk: the graphics cube route's test builds the
  M3 Max under macOS 26.7 the same way.
Docs: API.md and profiles/README.md say what MoltenVK's deviceID is.

Golden hashes and expectation rows that hold moltenvk-m3's translation key
are left for the round's bless. Verified: the capture on the M3 Max
(regen_device_profiles.py --only moltenvk-m3, check_device_profiles.py);
the unit tests above run at a build of this branch before landing.

Record the Metal rows of the M3 Max under macOS 27.0.1:
The reference Mac's Metal answers, apple-m3-max-macos27.0.1 (Apple M3 Max,
40 GPU cores, macOS 27.0.1 26A434, Xcode 27A266a, Metal toolchain 32023.921,
ORACLE_ABI metal-literal-resources-v48): corpus-metal --batch over every
case the 26.7 environment holds, in three maclock holds of about 6.5
minutes, then --batch-install. 2227 cases ran: 2223 qualified, 4 reference
gaps (the simdgroup_matrix 16x16 cases, GPUFamily10, as on 26.7), no
failure. The 26.7 rows stay.

Against the 26.7 rows: no status changed and 8 outputs moved, every one a
cube-gradient case with identical AIR and inputs (a54af728, 315ca8b0,
391fac4d, 6ce71712, ae7aa91b, b3e5b4ef, dd39e2e5, 649c204a). Those 8 ran a
second time identically. Every other case answers as on 26.7.

Expect the M3 Max's and the M4's MoltenVK captures to share a fingerprint:
fingerprints_distinguish_committed_profiles listed only the two Intel
captures as sharing a fingerprint, kept apart for the Apple GPUs by the
graphics cube route measured on the M3 Max's macOS 26.7 deviceID. Under
macOS 27 MoltenVK gives the M3 Max and the M4 one deviceID, and the captures
differ only in allocation sizes, so moltenvk-m3 and moltenvk-m4 now derive
one fingerprint; the test lists the pair.

Found by device::tests at a build of this branch; device:: (104) and
tests::engine_sampler_unk (8) pass with it on the release build.

Make the M3 Max under macOS 27.0.1 the C3 reference Metal environment:
The reference Mac runs macOS 27.0.1 (26A434), and its Metal rows are
committed (apple-m3-max-macos27.0.1). The switch:
- c3-references.json: the primary is apple-m3-max-macos27.0.1 (Apple M3 Max,
  40 cores, 27.0.1, 26A434, Xcode 27A266a, Metal toolchain 32023.921).
- c3-venues.json: the MoltenVK venue's device compares with it.
- runtime_lane::METAL_ENVIRONMENT, the reference and venue tests, and
  scripts/rerecord-venue's default name it.
- The parity lines: record_metal and the sequences' record_metal on the M3
  Max under macOS 27.0.1. The four scenarios recorded 68, 240, 95 and 36
  records; the 64 sequence seeds 8534 records, 0 differences from the model
  and no Metal-side gap (seeds 32, 51 and 62 crashed Metal's driver under
  26.7; they run under 27.0.1). The 26.7 lines and rows stay.

Verified on the M3 Max (release, --cfg m2v_gpu, the validation layer on):
runtime_lane::driver_deviations::cube_gradients_through_an_anisotropic_
sampler_answer_as_metal passes against the 27 rows (MoltenVK answers Metal
27's cube gradients; it failed against the 26.7 rows); parity::tests::
committed_records_are_current and the 14 parity and sequence lanes pass (their
2 recorders are ignored); the
c3::, candidate::platform::profiles::, candidate::engine::guards:: and
parity::tests:: modules pass (98 tests).

Record the M3 Max's MoltenVK venue under macOS 27.0.1 at product 15b6df4e2bd0:
Rows and refusals recorded by one build (executor vulkan-engine-v181, product
15b6df4e2bd0cb440724ffe07ba95f1ccf6d0a5dd7fb5055598e70c877596734, semantics 1698, oracle
metal-literal-resources-v48) at this commit's product, on the Apple M3 Max under macOS 27.0.1 (MoltenVK
1.4.1, deviceID 0x1B000209). They are judged against the apple-m3-max-macos27.0.1 Metal rows and
were installed by scripts/rerecord-commit --no-commit. No later commit changes the product, so every row installed here stays current.

- apple-m3-max-moltenvk (moltenvk): 4389 rows, 56 refusals, over 2223 cases in two legs
- stated: 2168 match, 23 mismatch, 31 refused, 1 failed
- robustness-off: 2175 match, 23 mismatch, 25 refused

Against the macOS 26.7 rows, per case and leg:
- Of the earlier matches, 2965 still match, none mismatches, and 1 failed (below).
- 13 earlier mismatches and 13 earlier refusals now match; 38 mismatches and 42 refusals remain.
- 1374 runs had no 26.7 row: 1352 match, 14 refused, 8 mismatch. The 8 are the robustness-off
  leg of four linked-single radix13 and radix15 zero-write cases whose stated leg was already a
  mismatch, and both legs of the two new cases quad-broadcast-first-in-an-arm-metal-speculates
  and quad-broadcast-first-in-a-fragment-arm-metal-speculates.

The failed run is authored-four-iteration-loop (3cf0a3f024a5), stated leg. Metal's compiler
connection was interrupted while it compiled the compute pipeline (XPC_ERROR_CONNECTION_INTERRUPTED
after MoltenVK's retries), on both the first try and the --retry-failed run. Its robustness-off leg
matches, and under 26.7 it matched in both legs. Its stated slot keeps the 26.7 row, which C3 reads
as stale. Two msl-4-1 cases the venue's selection did not include also keep 26.7 rows that read
stale.

Verified:
- corpus-moltenvk --batch-report reads this_build=yes for the out directory at the recording tree and at the round's
  final tree (the table bless after this commit), which adds only tests, test tables and docs.
- corpus-status --c3 prints the same report at both trees. The MoltenVK slots (stated, then
  robustness-off) read: match 2168 and 2175, reviewed 10 and 10, mismatch 13 and 13, refused 25
  and 19, ray tracing out of scope 6 and 6, stale 3 and 1.

Versions: RUNTIME_VERSION 1205 -> 1211. RUNTIME_VERSION moves: MoltenVK's NotMipmapped anisotropic
footprint is read at level 0, and the macOS 27 Apple identity takes InterlockedPassSplitNoSlower.
crates/metal2vulkan-validation/runtime-sources.sha256 holds
e74792b15fd66114fb4efcc8e281318bfe1e16a3b8532e90d737834ea5a2add3, the hash of this tree's runtime
inputs (runtime-pin.py, which reproduces build.rs's). Version numbers quoted above are the values
the work's branch built with. Each part's Verified lines name the tree it ran at.
2026-10-14 20:17:42 +03:00

321 lines
17 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, in both legs, into an out
# directory kept on this host, resumable and measured. Metal is never run.
#
# scripts/rerecord-venue --venue ID [--kind native-gpu|moltenvk|cpu-icd]
# [--icd lavapipe|swiftshader] [--ref SHA] [--out-root DIR]
# [--leg stated|robustness-off]... [--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 (a SwiftShader venue, say) needs --kind. Every venue runs both legs unless
# --leg says otherwise: C3 judges the legs c3-venues.json lists, but coverage needs both on every
# venue (a robustness-off requirement is met only by a robustness-off run). --icd picks the CPU
# ICD of a cpu-icd venue (default lavapipe). --profiles-layer P records a restricted leg: 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`.
# moltenvk: this Mac's GPU, `corpus-moltenvk --batch --device-type gpu`, with Homebrew's
# validation layer through a scratch VK_ADD_LAYER_PATH (docs/VALIDATION.md). 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, leg) 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, per-leg, 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 leg'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
leg_flags=
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 ;;
--leg) [ "$#" -ge 2 ] || usage; leg_flags="$leg_flags --leg $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$leg_flags$case_flags$slot$icd$profile" in
*[!A-Za-z0-9_.@+\ -]*) fail "IDs, legs, 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|swiftshader) ;; *) fail "--icd is lavapipe or swiftshader" ;; 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
[ -n "$leg_flags" ] || leg_flags=" --leg stated --leg robustness-off"
case "$kind" in
native-gpu) exe=corpus-vulkan; device=gpu; : "${limit:=50}" ;;
moltenvk) exe=corpus-moltenvk; 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, moltenvk, or cpu-icd" ;;
esac
if [ "$kind" = moltenvk ] && [ "$(uname -s)" != Darwin ]; then fail "MoltenVK runs on macOS"; fi
[ "$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 "legs:$leg_flags 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$leg_flags$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$leg_flags$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
vvl=
if [ "$kind" = moltenvk ]; then
manifest=/opt/homebrew/share/vulkan/explicit_layer.d/VkLayer_khronos_validation.json
[ -f "$manifest" ] || fail "no validation layer at $manifest"
vvl=$d/vvl
mkdir -p "$vvl"
sed 's#"library_path": *"[^"]*"#"library_path": "/opt/homebrew/lib/libVkLayer_khronos_validation.dylib"#' \
"$manifest" > "$vvl/VkLayer_khronos_validation.json"
export VK_ADD_LAYER_PATH=$vvl
trap 'rm -rf "$vvl"' EXIT
fi
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"$leg_flags$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 leg'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, leg)'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"