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 / bench / prime_race / tests / run_gb10_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 | # bench/prime_race/tests/run_gb10_chip.sh -- AIEN Prime Drag Race: native GB10 sieve chip test. |
| 18 | # |
| 19 | # GB10_CHIP_RUN=1 bench/prime_race/tests/run_gb10_chip.sh --physics-dir DIR [--evidence-dir DIR] |
| 20 | # |
| 21 | # Pattern of tests/run_tensor_chip.sh (never creates or touches the quiet flag; the |
| 22 | # operator runs it inside an own quiet window). |
| 23 | # 1. Refuses unless GB10_CHIP_RUN=1, the omega tree is clean, and the physics checkout is |
| 24 | # clean and at the physics.lock commit. |
| 25 | # 2. Builds libomega_gpu, gb10_native, gb10_native_mutant and the host test (nice, -j1); |
| 26 | # the Makefile refuses a binary with CUDA symbols (nm, tools/chip_run.sh pattern); this |
| 27 | # script checks again. |
| 28 | # 3. Runs the host test first (golden words, nvdisasm listing, IR simulator sweep): a |
| 29 | # kernel that is wrong on the host never gets chip time. |
| 30 | # 4. Takes /tmp/aien-gb10.lock (waits; no timeout) and holds it for the whole sweep. Every |
| 31 | # limit of the DESIGN sweep (gb10_sieve_host_test --limits) runs in audit mode (K = 2; |
| 32 | # K = 5 at 1e6), every pass's bitmap compared byte for byte with the host oracle |
| 33 | # (independent Eratosthenes); then 1e7 (K = 1), one timed run (1e6, 2 s, stdout line |
| 34 | # and final bitmap checked) and the mutant binary at 1e6, which must be caught. |
| 35 | # The first failing run stops the sweep (no further launches); nothing is ever killed. |
| 36 | # 5. Writes a content-addressed receipt <evidence-dir>/<sha256>.json (mode 0444, never |
| 37 | # overwritten) for PASS and FAIL alike, plus the run log as blobs/<sha256>.log. |
| 38 | # Shell + coreutils + git + jq + make + nm + cmp + flock. No Python. Exit 0 PASS, 1 FAIL, 2 refused. |
| 39 | set -u |
| 40 | SELF_DIR=$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd) |
| 41 | OMEGA=$(cd "$SELF_DIR/../../.." && pwd) |
| 42 | PHYS="" |
| 43 | EVID=$HOME/workspace/evidence/prime-race/gb10-chip |
| 44 | while [ $# -gt 0 ]; do |
| 45 | case $1 in |
| 46 | --physics-dir) PHYS=$2; shift 2 ;; |
| 47 | --evidence-dir) EVID=$2; shift 2 ;; |
| 48 | *) echo "unknown argument $1" >&2; exit 2 ;; |
| 49 | esac |
| 50 | done |
| 51 | die() { echo "run_gb10_chip: $*" >&2; exit 2; } |
| 52 | [ "${GB10_CHIP_RUN:-}" = 1 ] || die "chip run refused: GB10_CHIP_RUN=1 is not set" |
| 53 | [ -n "$PHYS" ] && [ -d "$PHYS" ] || die "--physics-dir is required" |
| 54 | PHYS=$(cd "$PHYS" && pwd) |
| 55 | [ -z "$(git -C "$OMEGA" status --porcelain)" ] || die "omega tree is dirty; refusing" |
| 56 | COMMIT=$(git -C "$OMEGA" rev-parse HEAD) |
| 57 | LOCKED=$(tr -d ' \n' < "$OMEGA/physics.lock") |
| 58 | PHEAD=$(git -C "$PHYS" rev-parse HEAD) |
| 59 | [ "$PHEAD" = "$LOCKED" ] || die "physics checkout is at $PHEAD, physics.lock pins $LOCKED" |
| 60 | [ -z "$(git -C "$PHYS" status --porcelain)" ] || die "physics checkout is dirty" |
| 61 | command -v jq >/dev/null || die "jq missing" |
| 62 | mkdir -p "$EVID/blobs" |
| 63 | EVID=$(cd "$EVID" && pwd) |
| 64 | case "$EVID/" in "$OMEGA/"*|"$PHYS/"*) die "evidence dir must be outside the omega tree and physics checkout" ;; esac |
| 65 | |
| 66 | STARTED=$(date -u +%Y-%m-%dT%H:%M:%SZ) |
| 67 | B=$OMEGA/bench/prime_race/build |
| 68 | BIN=$B/gb10_native MUT=$B/gb10_native_mutant HT=$B/gb10_sieve_host_test |
| 69 | T=$(mktemp -d) || die "no temp dir" |
| 70 | LOG=$T/run.log |
| 71 | FAIL_REASON="" |
| 72 | log() { echo "$*" | tee -a "$LOG"; } |
| 73 | |
| 74 | (cd "$OMEGA" && nice -n 19 make -j1 PHYSICS_DIR="$PHYS" prime-race-gb10 bench/prime_race/build/gb10_sieve_host_test) > "$T/build.log" 2>&1 \ |
| 75 | || FAIL_REASON="build failed" |
| 76 | if [ -z "$FAIL_REASON" ]; then |
| 77 | for x in "$BIN" "$MUT"; do |
| 78 | nm -u "$x" | grep -Eiq 'cuda|cuInit|cuLaunch|nvrtc|cublas' && FAIL_REASON="CUDA symbols in $(basename "$x")" |
| 79 | done |
| 80 | fi |
| 81 | BIN_SHA=$( [ -f "$BIN" ] && sha256sum "$BIN" | cut -d' ' -f1 ) |
| 82 | MUT_SHA=$( [ -f "$MUT" ] && sha256sum "$MUT" | cut -d' ' -f1 ) |
| 83 | HOST_OK=false |
| 84 | if [ -z "$FAIL_REASON" ]; then |
| 85 | "$HT" >> "$LOG" 2>&1 && HOST_OK=true || FAIL_REASON="host test (simulator) failed" |
| 86 | fi |
| 87 | |
| 88 | NRUNS=0 NPASSES=0 MUTANT_CAUGHT=false TIMED_OK=false KERNEL_SHA="" |
| 89 | # run_audit LIMIT K BINARY -> 0 match, 1 mismatch, 2 run failed |
| 90 | run_audit() { |
| 91 | local L=$1 K=$2 X=$3 |
| 92 | rm -f "$T/got.bin" "$T/want.bin" "$T/rep.json" |
| 93 | "$X" --limit "$L" --min-seconds 0 --audit-passes "$K" --bitmap-out "$T/got.bin" --report-out "$T/rep.json" \ |
| 94 | > "$T/stdout" 2> "$T/stderr" |
| 95 | local rc=$? |
| 96 | NRUNS=$((NRUNS + 1)) |
| 97 | if [ $rc -ne 0 ]; then log "limit $L: $(basename "$X") exit $rc: $(tail -2 "$T/stderr" | tr '\n' ' ')"; return 2; fi |
| 98 | "$HT" --oracle "$L" "$T/want.bin" "$K" || { log "limit $L: oracle failed"; return 2; } |
| 99 | if ! cmp -s "$T/got.bin" "$T/want.bin"; then |
| 100 | log "limit $L: bitmap differs from oracle: $(cmp "$T/got.bin" "$T/want.bin" 2>&1 | head -1)"; return 1 |
| 101 | fi |
| 102 | NPASSES=$((NPASSES + K)) |
| 103 | return 0 |
| 104 | } |
| 105 | |
| 106 | if [ -z "$FAIL_REASON" ]; then |
| 107 | exec 9> /tmp/aien-gb10.lock || FAIL_REASON="cannot open /tmp/aien-gb10.lock" |
| 108 | fi |
| 109 | if [ -z "$FAIL_REASON" ]; then |
| 110 | # waits for the lock; no timeout; never killed |
| 111 | flock 9 |
| 112 | LOCK_AT=$(date -u +%Y-%m-%dT%H:%M:%SZ) |
| 113 | log "GPU lock held from $LOCK_AT" |
| 114 | for L in $("$HT" --limits) 10000000; do |
| 115 | K=2; [ "$L" = 1000000 ] && K=5; [ "$L" = 10000000 ] && K=1 |
| 116 | run_audit "$L" "$K" "$BIN"; r=$? |
| 117 | [ $r -eq 0 ] || { FAIL_REASON="limit $L: $( [ $r = 1 ] && echo mismatch || echo run failed )"; break; } |
| 118 | [ "$L" = 1000000 ] && KERNEL_SHA=$(jq -r '.detail.kernel_code_sha256 // empty' "$T/rep.json" 2>/dev/null) |
| 119 | done |
| 120 | log "audit sweep: $NRUNS runs, $NPASSES passes checked" |
| 121 | if [ -z "$FAIL_REASON" ]; then |
| 122 | "$BIN" --limit 1000000 --min-seconds 2 --bitmap-out "$T/got.bin" --report-out "$T/timed.json" > "$T/timed.out" 2> "$T/timed.err" |
| 123 | rc=$? |
| 124 | "$HT" --oracle 1000000 "$T/want.bin" 1 |
| 125 | if [ $rc -eq 0 ] && [ "$(wc -l < "$T/timed.out")" = 1 ] \ |
| 126 | && grep -Eq '^aien-gb10-native;[1-9][0-9]*;[0-9]+\.[0-9]{6};[0-9]+;algorithm=other,faithful=no,bits=1$' "$T/timed.out" \ |
| 127 | && cmp -s "$T/got.bin" "$T/want.bin"; then |
| 128 | TIMED_OK=true; log "timed smoke: $(cat "$T/timed.out")" |
| 129 | else |
| 130 | FAIL_REASON="timed run at 1e6: exit $rc, line '$(head -1 "$T/timed.out")'" |
| 131 | fi |
| 132 | fi |
| 133 | if [ -z "$FAIL_REASON" ]; then |
| 134 | run_audit 1000000 1 "$MUT"; r=$? |
| 135 | if [ $r -eq 1 ]; then MUTANT_CAUGHT=true; log "mutant caught at 1e6" |
| 136 | else FAIL_REASON="mutant not caught at 1e6 (status $r)"; fi |
| 137 | fi |
| 138 | flock -u 9 |
| 139 | fi |
| 140 | |
| 141 | VERDICT=PASS; [ -z "$FAIL_REASON" ] || VERDICT=FAIL |
| 142 | LOG_SHA=$(sha256sum "$LOG" 2>/dev/null | cut -d' ' -f1) |
| 143 | [ -n "$LOG_SHA" ] && [ ! -e "$EVID/blobs/$LOG_SHA.log" ] && cp "$LOG" "$EVID/blobs/$LOG_SHA.log" && chmod 0444 "$EVID/blobs/$LOG_SHA.log" |
| 144 | jq -n --arg v "$VERDICT" --arg reason "$FAIL_REASON" --arg commit "$COMMIT" --arg physics "$PHEAD" \ |
| 145 | --arg started "$STARTED" --arg finished "$(date -u +%Y-%m-%dT%H:%M:%SZ)" --arg bin "${BIN_SHA:-}" --arg mut "${MUT_SHA:-}" \ |
| 146 | --arg kernel "$KERNEL_SHA" --arg log "${LOG_SHA:-}" --argjson host "$HOST_OK" --argjson runs "$NRUNS" \ |
| 147 | --argjson passes "$NPASSES" --argjson mutant "$MUTANT_CAUGHT" --argjson timed "$TIMED_OK" \ |
| 148 | --arg gpu "$(nvidia-smi --query-gpu=name,uuid,driver_version --format=csv,noheader 2>/dev/null || echo unavailable)" \ |
| 149 | --arg kern "$(uname -r)" \ |
| 150 | '{schema:"aien-prime-race/gb10-chip-test/v1", verdict:$v, reason:$reason, omega_commit:$commit, physics_commit:$physics, |
| 151 | started:$started, finished:$finished, binary_sha256:$bin, mutant_binary_sha256:$mut, kernel_code_sha256:$kernel, |
| 152 | host_test_pass:$host, audit_runs:$runs, audit_passes_checked:$passes, timed_smoke_pass:$timed, mutant_caught:$mutant, |
| 153 | gpu:$gpu, kernel:$kern, gpu_lock:"/tmp/aien-gb10.lock", quiet_flag:"not touched (operator window)", |
| 154 | reference:"independent Eratosthenes oracle (gb10_sieve_host_test --oracle), byte-for-byte per pass", log_blob:$log}' \ |
| 155 | > "$T/receipt.json" |
| 156 | RSHA=$(sha256sum "$T/receipt.json" | cut -d' ' -f1) |
| 157 | if [ ! -e "$EVID/$RSHA.json" ]; then cp "$T/receipt.json" "$EVID/$RSHA.json" && chmod 0444 "$EVID/$RSHA.json"; fi |
| 158 | echo "run_gb10_chip: VERDICT $VERDICT ${FAIL_REASON:+($FAIL_REASON) }receipt=$EVID/$RSHA.json" |
| 159 | rm -rf "$T" |
| 160 | [ "$VERDICT" = PASS ] && exit 0 || exit 1 |