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 / tests / run_ad_chip.sh
| 1 | #!/bin/bash |
| 2 | # tests/run_ad_chip.sh -- native .om tape fixture replayed on the GB10 table. |
| 3 | # |
| 4 | # GB10_CHIP_RUN=1 tests/run_ad_chip.sh --physics-dir DIR --fixture FILE [--evidence-dir DIR] |
| 5 | # |
| 6 | # Pattern of tests/run_tensor_chip.sh (no quiet-flag option). |
| 7 | # 1. Refuses unless GB10_CHIP_RUN=1. The omega tree must be clean (the run |
| 8 | # commit is its HEAD); the physics checkout must be clean and at |
| 9 | # physics.lock. FILE is the 748-byte fixture written by the native trainer |
| 10 | # (aien-train tests/adtrain, mode D) and must lie outside both trees. |
| 11 | # 2. Builds tests/test_omega_ad_fixture.c with -DOMEGA_AD_FIXTURE_CHIP, the C |
| 12 | # M21 tape, the M20 CPU and GB10 tables and the E1 GB10 executors, |
| 13 | # -ffp-contract=off, into build/ad-runs/<run-id>/, and refuses a binary |
| 14 | # with libm math or CUDA symbols. |
| 15 | # 3. Runs it under /tmp/aien-gb10.lock (waits; no timeout; never killed): |
| 16 | # --chip FILE, then --chip --mutant-sign FILE, which must exit 1. |
| 17 | # Inside `spark-window run` (SPARK_WINDOW set and AIEN_GB10_LOCK_HELD=1) |
| 18 | # the window already holds that lock, shared or exclusive, so the script |
| 19 | # takes no lock of its own: an exclusive flock beside the window's shared |
| 20 | # hold would wait for its own window. The receipt records which held it. |
| 21 | # 4. PASS needs exit 0 with "AD_FIXTURE_CHIP: ... verdict=PASS" or |
| 22 | # "verdict=PASS_TOL" (max_ulp <= 2; the receipt records which), the |
| 23 | # negative control's FAIL, and clean trees with unmoved HEADs after. |
| 24 | # 5. Writes a content-addressed receipt <evidence-dir>/<sha256>.json (0444, |
| 25 | # never overwritten) for PASS and FAIL alike, plus binary, fixture, logs |
| 26 | # and stderr as blobs/<sha256>.{bin,fixture,log,stderr}. |
| 27 | # Shell + coreutils + git + jq + gcc. No Python. Exit 0 PASS, 1 FAIL, 2 refused. |
| 28 | set -u |
| 29 | SELF_DIR=$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd) |
| 30 | OMEGA=$(cd "$SELF_DIR/.." && pwd) |
| 31 | PHYS="" |
| 32 | FIX="" |
| 33 | EVID=$HOME/workspace/evidence-out/AD-FIXTURE-GB10 |
| 34 | while [ $# -gt 0 ]; do |
| 35 | case $1 in |
| 36 | --physics-dir) PHYS=$2; shift 2 ;; |
| 37 | --fixture) FIX=$2; shift 2 ;; |
| 38 | --evidence-dir) EVID=$2; shift 2 ;; |
| 39 | *) echo "unknown argument $1" >&2; exit 2 ;; |
| 40 | esac |
| 41 | done |
| 42 | die() { echo "run_ad_chip: $*" >&2; exit 2; } |
| 43 | [ "${GB10_CHIP_RUN:-}" = 1 ] || die "chip run refused: GB10_CHIP_RUN=1 is not set" |
| 44 | [ -n "$PHYS" ] && [ -d "$PHYS" ] || die "--physics-dir is required" |
| 45 | [ -n "$FIX" ] && [ -f "$FIX" ] || die "--fixture FILE is required" |
| 46 | PHYS=$(cd "$PHYS" && pwd) |
| 47 | FIX=$(cd "$(dirname "$FIX")" && pwd)/$(basename "$FIX") |
| 48 | [ "$(stat -c %s "$FIX")" = 748 ] || die "fixture is not 748 bytes" |
| 49 | [ -z "$(git -C "$OMEGA" status --porcelain)" ] || die "omega tree is dirty; refusing" |
| 50 | COMMIT=$(git -C "$OMEGA" rev-parse HEAD) |
| 51 | LOCKED=$(tr -d ' \n' < "$OMEGA/physics.lock") |
| 52 | PHEAD=$(git -C "$PHYS" rev-parse HEAD) |
| 53 | [ "$PHEAD" = "$LOCKED" ] || die "physics checkout is at $PHEAD, physics.lock pins $LOCKED" |
| 54 | [ -z "$(git -C "$PHYS" status --porcelain)" ] || die "physics checkout is dirty" |
| 55 | mkdir -p "$EVID/blobs" |
| 56 | EVID=$(cd "$EVID" && pwd) |
| 57 | case "$EVID/" in "$OMEGA/"*|"$PHYS/"*) die "evidence dir must be outside the omega tree and physics checkout" ;; esac |
| 58 | case "$FIX" in "$OMEGA/"*|"$PHYS/"*) die "fixture must be outside the omega tree and physics checkout" ;; esac |
| 59 | |
| 60 | STARTED=$(date -u +%Y-%m-%dT%H:%M:%SZ) |
| 61 | RUN_ID=$(date -u +%Y%m%dT%H%M%SZ)-${COMMIT:0:12} |
| 62 | mkdir -p "$OMEGA/build/ad-runs" || die "cannot create build/ad-runs" |
| 63 | OUT=$(mktemp -d "$OMEGA/build/ad-runs/$RUN_ID.XXXXXX") || die "cannot create a run directory" |
| 64 | RUN_ID=$(basename "$OUT") |
| 65 | BIN=$OUT/test_omega_ad_fixture |
| 66 | cp "$FIX" "$OUT/fixture.bin" || die "cannot copy fixture" |
| 67 | FIX_SHA=$(sha256sum "$OUT/fixture.bin" | cut -d' ' -f1) |
| 68 | NV=$PHYS/third_party/nvidia-open-580.173.02 |
| 69 | FAIL_REASON="" |
| 70 | (cd "$OMEGA" && gcc -std=gnu11 -O2 -Wall -Wextra -Werror -D_GNU_SOURCE -ffp-contract=off \ |
| 71 | -DOMEGA_AD_FIXTURE_CHIP -Isrc -Isrc/tensor -Isrc/autodiff -I"$PHYS/forge" -I"$PHYS/nvrm" -I"$PHYS/m16" \ |
| 72 | -I"$NV/src/common/sdk/nvidia/inc" -I"$NV/kernel-open/common/inc" \ |
| 73 | -I"$NV/kernel-open/nvidia-uvm" -I"$NV/src/nvidia/arch/nvalloc/unix/include" \ |
| 74 | -o "$BIN" tests/test_omega_ad_fixture.c src/autodiff/omega_autodiff.c \ |
| 75 | src/tensor/omega_tensor.c src/tensor/omega_tensor_cpu.c \ |
| 76 | src/tensor/omega_tensor_reduce_seam.c src/tensor/omega_tensor_gb10.c \ |
| 77 | src/omega_numeric_reduce.c src/omega_numeric_transc.c src/omega_numeric_reduce_gb10.c \ |
| 78 | src/omega_numeric.c src/omega_numeric_gb10.c src/omega_numeric_divsqrt_gb10.c \ |
| 79 | src/omega_numeric_provenance.c src/omega_blackwell_codegen.c \ |
| 80 | src/omega_blackwell_encoder.c src/omega_blackwell_matmul.c src/omega_blackwell_qmd.c \ |
| 81 | src/forge_realization.c src/aegis_verification.c src/omega_om_units.c \ |
| 82 | "$PHYS/forge/forge_descriptor.c" "$PHYS/forge/forge_realize.c" "$PHYS/sha256_clean.c" \ |
| 83 | "$PHYS/nvrm/nvrm.c" "$PHYS/m16/m16_native.c") > "$OUT/build.log" 2>&1 || FAIL_REASON="build failed" |
| 84 | if [ -z "$FAIL_REASON" ]; then |
| 85 | nm -u "$BIN" | grep -Eq '\b(sqrtf?|expf?|logf?|powf?|fmaf?|sinf?|cosf?|roundf?|fabsf?)\b' && FAIL_REASON="libm symbols in binary" |
| 86 | nm -u "$BIN" | grep -Eq 'libcuda(rt)?\.so|\b(cuInit|cuCtx|cuMem|cuStream|cudaMalloc)\b' && FAIL_REASON="CUDA symbols in binary" |
| 87 | fi |
| 88 | STATUS=-1 |
| 89 | MSTATUS=-1 |
| 90 | GB10_LOCK="" |
| 91 | BIN_SHA_BUILT="" |
| 92 | [ -z "$FAIL_REASON" ] && { BIN_SHA_BUILT=$(sha256sum "$BIN" | cut -d' ' -f1); [ -n "$BIN_SHA_BUILT" ] || FAIL_REASON="cannot hash binary after build"; } |
| 93 | if [ -z "$FAIL_REASON" ]; then |
| 94 | # waits for the lock; no timeout; never killed |
| 95 | if [ "${AIEN_GB10_LOCK_HELD:-}" = 1 ] && [ -n "${SPARK_WINDOW:-}" ]; then |
| 96 | GB10_LOCK="spark-window $SPARK_WINDOW" |
| 97 | gb10() { "$@"; } |
| 98 | else |
| 99 | GB10_LOCK="flock /tmp/aien-gb10.lock" |
| 100 | gb10() { flock /tmp/aien-gb10.lock "$@"; } |
| 101 | fi |
| 102 | GB10_CHIP_RUN=1 gb10 "$BIN" --chip "$OUT/fixture.bin" > "$OUT/ad.log" 2> "$OUT/ad.stderr" |
| 103 | STATUS=$? |
| 104 | GB10_CHIP_RUN=1 gb10 "$BIN" --chip --mutant-sign "$OUT/fixture.bin" \ |
| 105 | > "$OUT/ad-mutant.log" 2> "$OUT/ad-mutant.stderr" |
| 106 | MSTATUS=$? |
| 107 | [ "$STATUS" = 0 ] || FAIL_REASON="test binary exit status $STATUS" |
| 108 | grep -Eq '^AD_FIXTURE_CHIP: exact=[0-9]+/75 max_ulp=[0-9]+ verdict=(PASS|PASS_TOL)$' "$OUT/ad.log" \ |
| 109 | || FAIL_REASON="${FAIL_REASON:-no AD_FIXTURE_CHIP PASS line}" |
| 110 | [ "$MSTATUS" = 1 ] || FAIL_REASON="${FAIL_REASON:-mutant-sign control exit $MSTATUS, want 1}" |
| 111 | grep -q '^AD_FIXTURE_CHIP: .* verdict=FAIL (mutant-sign)$' "$OUT/ad-mutant.log" \ |
| 112 | || FAIL_REASON="${FAIL_REASON:-mutant-sign control printed no FAIL line}" |
| 113 | fi |
| 114 | FINISHED=$(date -u +%Y-%m-%dT%H:%M:%SZ) |
| 115 | [ -z "$(git -C "$OMEGA" status --porcelain)" ] && CLEAN_AFTER=true || { CLEAN_AFTER=false; FAIL_REASON="${FAIL_REASON:-omega tree dirty after run}"; } |
| 116 | [ "$(git -C "$OMEGA" rev-parse HEAD)" = "$COMMIT" ] && HEAD_SAME=true || { HEAD_SAME=false; FAIL_REASON="${FAIL_REASON:-HEAD moved during run}"; } |
| 117 | [ -z "$(git -C "$PHYS" status --porcelain)" ] && PCLEAN_AFTER=true || { PCLEAN_AFTER=false; FAIL_REASON="${FAIL_REASON:-physics dirty after run}"; } |
| 118 | [ "$(git -C "$PHYS" rev-parse HEAD)" = "$PHEAD" ] && PHEAD_SAME=true || { PHEAD_SAME=false; FAIL_REASON="${FAIL_REASON:-physics HEAD moved during run}"; } |
| 119 | |
| 120 | # store_blob SRC EXT -> prints the digest (same rules as run_tensor_chip.sh). |
| 121 | store_blob() { |
| 122 | local src=$1 ext=$2 d dst tmp have |
| 123 | d=$(sha256sum "$src" | cut -d' ' -f1); [ -n "$d" ] || die "cannot hash $src" |
| 124 | dst=$EVID/blobs/$d.$ext |
| 125 | if [ -e "$dst" ]; then |
| 126 | have=$(sha256sum "$dst" | cut -d' ' -f1) |
| 127 | [ "$have" = "$d" ] || die "existing blob $dst does not match its digest" |
| 128 | else |
| 129 | tmp=$(mktemp "$EVID/blobs/.tmp.XXXXXX") || die "cannot create temp blob" |
| 130 | cp "$src" "$tmp" || { rm -f "$tmp"; die "cannot store $ext blob"; } |
| 131 | have=$(sha256sum "$tmp" | cut -d' ' -f1) |
| 132 | [ "$have" = "$d" ] || { rm -f "$tmp"; die "stored $ext blob does not match its digest"; } |
| 133 | chmod 0444 "$tmp" || { rm -f "$tmp"; die "cannot seal $ext blob"; } |
| 134 | mv -n "$tmp" "$dst"; rm -f "$tmp" |
| 135 | have=$(sha256sum "$dst" | cut -d' ' -f1) |
| 136 | [ "$have" = "$d" ] || die "blob $dst does not match its digest after publish" |
| 137 | fi |
| 138 | echo "$d" |
| 139 | } |
| 140 | BIN_SHA=""; LOG_SHA=""; ERR_SHA=""; MLOG_SHA="" |
| 141 | if [ -f "$BIN" ]; then BIN_SHA=$(store_blob "$BIN" bin) || exit 2; fi |
| 142 | [ -z "$BIN_SHA_BUILT" ] || [ "$BIN_SHA" = "$BIN_SHA_BUILT" ] || FAIL_REASON="${FAIL_REASON:-binary changed between build and receipt}" |
| 143 | STORED_FIX=$(store_blob "$OUT/fixture.bin" fixture) || exit 2 |
| 144 | [ "$STORED_FIX" = "$FIX_SHA" ] || FAIL_REASON="${FAIL_REASON:-fixture changed during run}" |
| 145 | if [ -f "$OUT/ad.log" ]; then LOG_SHA=$(store_blob "$OUT/ad.log" log) || exit 2; fi |
| 146 | if [ -f "$OUT/ad.stderr" ]; then ERR_SHA=$(store_blob "$OUT/ad.stderr" stderr) || exit 2; fi |
| 147 | if [ -f "$OUT/ad-mutant.log" ]; then MLOG_SHA=$(store_blob "$OUT/ad-mutant.log" log) || exit 2; fi |
| 148 | VERDICT=PASS; [ -n "$FAIL_REASON" ] && VERDICT=FAIL |
| 149 | line() { grep "^$1" "$2" 2>/dev/null | head -1; } |
| 150 | TMP=$OUT/receipt.json |
| 151 | jq -n --arg suite AD_FIXTURE_GB10 --arg status "$VERDICT" --arg reason "$FAIL_REASON" \ |
| 152 | --arg run_id "$RUN_ID" --arg commit "$COMMIT" --arg physics "$PHEAD" --arg pin "$LOCKED" \ |
| 153 | --argjson clean_after "$CLEAN_AFTER" --argjson head_same "$HEAD_SAME" \ |
| 154 | --argjson pclean_after "$PCLEAN_AFTER" --argjson phead_same "$PHEAD_SAME" \ |
| 155 | --arg started "$STARTED" --arg finished "$FINISHED" \ |
| 156 | --arg bin "$BIN_SHA" --arg fix "$FIX_SHA" --arg log "$LOG_SHA" --arg errlog "$ERR_SHA" --arg mlog "$MLOG_SHA" \ |
| 157 | --arg exit_status "$STATUS" --arg mexit "$MSTATUS" \ |
| 158 | --arg chip_line "$(line AD_FIXTURE_CHIP: "$OUT/ad.log")" \ |
| 159 | --arg mutant_line "$(line AD_FIXTURE_CHIP: "$OUT/ad-mutant.log")" \ |
| 160 | --arg host "$(uname -n)" --arg kernel "$(uname -r)" --arg gb10_lock "$GB10_LOCK" \ |
| 161 | '{suite:$suite,status:$status,reason:$reason,run_id:$run_id,started_utc:$started,finished_utc:$finished, |
| 162 | omega_commit:$commit,omega_tree_clean_before:true,omega_tree_clean_after:$clean_after, |
| 163 | omega_commit_unchanged_after:$head_same,physics_commit:$physics,physics_lock_pin:$pin, |
| 164 | physics_tree_clean_before:true,physics_tree_clean_after:$pclean_after,physics_commit_unchanged_after:$phead_same, |
| 165 | fixture_sha256:$fix,binary_sha256:$bin,chip_log_sha256:$log,chip_stderr_sha256:$errlog, |
| 166 | mutant_log_sha256:$mlog,chip_exit_status:$exit_status,mutant_exit_status:$mexit, |
| 167 | chip_line:$chip_line,mutant_line:$mutant_line, |
| 168 | tolerance:"PASS max_ulp 0; PASS_TOL max_ulp <= 2; else FAIL", |
| 169 | realization:"M20 omega_tensor_gb10_realization under the C M21 tape", |
| 170 | quiet_flag:"not used",gb10_lock:$gb10_lock,host:$host,kernel:$kernel}' > "$TMP" || die "receipt json (jq) failed, no receipt written" |
| 171 | [ -s "$TMP" ] || die "empty receipt, not written" |
| 172 | [ "$VERDICT" != PASS ] || { [ -n "$BIN_SHA" ] && [ -n "$LOG_SHA" ]; } || die "PASS without binary and log digests refused" |
| 173 | DIG=$(sha256sum "$TMP" | cut -d' ' -f1) |
| 174 | (set -o noclobber; cat "$TMP" > "$EVID/$DIG.json") || die "receipt $DIG.json already exists" |
| 175 | chmod 0444 "$EVID/$DIG.json" |
| 176 | echo "receipt: $EVID/$DIG.json status=$VERDICT ${FAIL_REASON}" |
| 177 | [ "$VERDICT" = PASS ] |