omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / tools / run_gpu_l2d_prefetch_chip.sh
| 1 | #!/bin/bash |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # run_gpu_l2d_prefetch_chip.sh EVIDENCE_DIR [PHYSICS_DIR] (OWN-30B W-L2d, 2026-10-14; run under flock /tmp/aien-gb10.lock) |
| 18 | # One variable: the o_proj weight prefetch launch beside the attention (decode graph --prefetch), on GPU-cached weights. |
| 19 | # Synthetic 2-layer token (no model load). Interleaved A/B: cached base, cached prefetch, cached base, cached prefetch; |
| 20 | # control: uncached + prefetch (no L2 keep possible: expect no o_proj gain); red: --prefetch-red MUST FAIL; |
| 21 | # cmdlist chip test (regression of the cmdlist change). Every graph run checks B == C bit for bit + mutants and prints the |
| 22 | # per-kind TIMELINE and the logits hash. Verdict line last: "GPU_L2D_PREFETCH_CHIP: PASS|FAIL". |
| 23 | set -u |
| 24 | HERE="$(cd "$(dirname "$0")/.." && pwd)" |
| 25 | # Host-only gate. All test generation, child supervision and result decisions |
| 26 | # live in gate.om. This retained shell entry only verifies and builds the |
| 27 | # existing native tools. Missing/unqualified compiler dependencies fail closed. |
| 28 | if [ "${1:-}" = --host-qualification ]; then |
| 29 | cd "$HERE" || exit 3 |
| 30 | sha256sum -c native/prefetch/compiler.sha256 || { echo "PREFETCH_NATIVE_GATE: compiler prerequisite unavailable"; exit 3; } |
| 31 | [ -x seed/out/omc ] || exit 3 |
| 32 | mkdir -p build || exit 3 |
| 33 | stage="$(mktemp -d "$HERE/build/prefetch-check.XXXXXX")" || exit 3 |
| 34 | mkdir -p "$stage/native" "$stage/build" || exit 3 |
| 35 | cp -R native/prefetch "$stage/native/prefetch" || exit 3 |
| 36 | timeout --kill-after=2 30 seed/out/omc < "$stage/native/prefetch/gate.om" > "$stage/gate.elf" || exit 3 |
| 37 | chmod 700 "$stage/gate.elf" || exit 3 |
| 38 | cd "$stage" || exit 3 |
| 39 | exec "$stage/gate.elf" "$HERE/seed/out/omc" |
| 40 | fi |
| 41 | EVID="${1:?evidence dir}"; PHYS="${2:-$HOME/workspace/physics-own30b-k}" |
| 42 | "$(dirname "$0")/require_physics_pin.sh" "$PHYS" || exit 2 # omega#456: refuse a Physics checkout other than physics.lock |
| 43 | # Classification is implemented by native/prefetch/classify.om. Require the |
| 44 | # explicitly built native classifier before any device work; never fall back |
| 45 | # to accepting a nonzero child exit. An exclusive directory prevents stale |
| 46 | # receipts from an earlier run from being paired with a failed new invocation. |
| 47 | CLASSIFIER="${PREFETCH_CLASSIFIER:?path to compiled native/prefetch/classify.om}" |
| 48 | CLASSIFIER="$(realpath "$CLASSIFIER")" || exit 2 |
| 49 | [ -x "$CLASSIFIER" ] || { echo "GPU_L2D_PREFETCH_CHIP: INVALID classifier unavailable"; exit 2; } |
| 50 | EXPECTED="$(cat "$HERE/native/prefetch/classify.sha256")" || exit 2 |
| 51 | [[ "$EXPECTED" =~ ^[0-9a-f]{64}$ ]] || exit 2 |
| 52 | mkdir "$EVID" || { echo "GPU_L2D_PREFETCH_CHIP: INVALID evidence directory must be new"; exit 2; } |
| 53 | EVID="$(cd "$EVID" && pwd)" || exit 2 |
| 54 | cd "$HERE" || exit 2 |
| 55 | cp "$CLASSIFIER" "$EVID/classifier.elf" || exit 2 |
| 56 | CLASSIFIER="$EVID/classifier.elf" |
| 57 | ACTUAL="$(sha256sum "$CLASSIFIER")" || exit 2 |
| 58 | [ "${ACTUAL%% *}" = "$EXPECTED" ] || { echo "GPU_L2D_PREFETCH_CHIP: INVALID classifier digest"; exit 2; } |
| 59 | sha256sum -c native/prefetch/source.sha256 > "$EVID/classifier-source.log" 2>&1 || { echo "GPU_L2D_PREFETCH_CHIP: INVALID classifier source"; exit 2; } |
| 60 | { echo "start $(date -u +%FT%TZ) omega=$(git rev-parse HEAD) branch=$(git rev-parse --abbrev-ref HEAD) dirty=$(git status --porcelain | wc -l) physics_commit=$(git -C "$PHYS" rev-parse HEAD)" |
| 61 | uname -a; nvidia-smi --query-gpu=name,driver_version --format=csv,noheader 2>/dev/null; free -g | head -2; uptime; } > "$EVID/device.txt" |
| 62 | make PHYSICS_DIR="$PHYS" -j10 build/gpu_decode_graph_test build/gpu_cmdlist_test > "$EVID/build.log" 2>&1 || { echo "GPU_L2D_PREFETCH_CHIP: INVALID build"; exit 2; } |
| 63 | D=./build/gpu_decode_graph_test |
| 64 | sha256sum "$D" build/gpu_cmdlist_test build/libomega_gpu.a > "$EVID/binaries.sha256" || exit 2 |
| 65 | sha256sum "$CLASSIFIER" native/prefetch/classify.om >> "$EVID/binaries.sha256" || exit 2 |
| 66 | fail=0 |
| 67 | run() { local name="$1"; shift |
| 68 | timeout --kill-after=10 600 "$D" "$@" --reps "${REPS:-10}" --out "$EVID/receipt-$name.json" > "$EVID/$name.log" 2>&1 || fail=1 |
| 69 | echo "$name ($*): $(grep -E 'TIMELINE|PER TOKEN|^chip:' "$EVID/$name.log" | tr '\n' ' ')" |
| 70 | grep -o '"C0_logits_fnv":"[0-9a-f]\{16\}"' "$EVID/receipt-$name.json" || fail=1; } |
| 71 | run 1-cached-base --cached-weights |
| 72 | run 2-cached-prefetch --cached-weights --prefetch |
| 73 | run 3-cached-base --cached-weights |
| 74 | run 4-cached-prefetch --cached-weights --prefetch |
| 75 | run 5-uncached-prefetch --prefetch |
| 76 | timeout --kill-after=10 600 "$D" --cached-weights --prefetch-red --reps 3 --out "$EVID/receipt-red.json" > "$EVID/red.log" 2>&1; rc=$? |
| 77 | printf '%s\n' "$rc" > "$EVID/red.exit" |
| 78 | echo "red (prefetch-red): exit $rc ($(tail -1 "$EVID/red.log"))" |
| 79 | timeout --kill-after=2 10 "$CLASSIFIER" "$rc" "$EVID/red.log" "$EVID/receipt-red.json" > "$EVID/red-classification.log" 2>&1; classification=$? |
| 80 | cat "$EVID/red-classification.log" |
| 81 | if [ "$classification" != 0 ]; then |
| 82 | fail=1 |
| 83 | if [ "$classification" != 1 ]; then |
| 84 | echo "GPU_L2D_PREFETCH_CHIP: INVALID prefetch control" |
| 85 | exit 2 |
| 86 | fi |
| 87 | fi |
| 88 | timeout --kill-after=10 600 ./build/gpu_cmdlist_test > "$EVID/cmdlist.log" 2>&1 || fail=1; echo "cmdlist: $(tail -1 "$EVID/cmdlist.log")" |
| 89 | echo "end $(date -u +%FT%TZ)" >> "$EVID/device.txt" || exit 2 |
| 90 | # The directory is exclusive and SHA256SUMS does not exist yet. Glob expansion |
| 91 | # precedes creation of that output, so it cannot hash itself. Preserve hash and |
| 92 | # write failures instead of masking them behind grep's successful exit. |
| 93 | (cd "$EVID" && sha256sum ./* > SHA256SUMS) || { echo "GPU_L2D_PREFETCH_CHIP: INVALID evidence manifest"; exit 2; } |
| 94 | if [ $fail = 0 ]; then echo "GPU_L2D_PREFETCH_CHIP: PASS"; else echo "GPU_L2D_PREFETCH_CHIP: FAIL"; exit 1; fi |