interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / tools / run_divsqrt_gate.sh

138 lines · 9294 bytes Raw Blame History
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_divsqrt_gate.sh -- E1 row 7 chip gate: correctly rounded FP32 DIV and
18# SQRT on the GB10, bit-identical to the CPU semantic (omega_math_div/sqrt and
19# the AArch64 FDIV/FSQRT, NaN results canonical 0x7fc00000).
20#
21# Order: refuse a dirty omega tree or a physics checkout that is dirty or not
22# at the physics.lock pin; refuse while ~/workspace/.spark-quiet exists, an
23# est_load process runs or /tmp/aien-gb10.lock is held; run the host tier and
24# the offline provenance check (Omega's own disassembler); raise the quiet flag; take the GPU
25# lock; build the chip binary (no libm math, no CUDA symbols); run it to the
26# end (never killed, never timed out); write a content-addressed receipt
27# <evidence-dir>/<sha256>.json (mode 0444, created exclusively, outside the
28# tree) plus the log as blobs/<sha256>.log; drop the flag.
29#
30# Run it detached so a closed terminal cannot cut the chip run:
31# setsid nohup tools/run_divsqrt_gate.sh > /tmp/divsqrt-gate.out 2>&1 < /dev/null &
32# Shell + coreutils + git + jq + gcc. No Python.
33set -u
34HERE=$(cd -P "$(dirname "$0")/.." && pwd)
35PHYSICS=${PHYSICS_DIR:-$HOME/workspace/hive-worktrees/physics-gate14-e95e3ed}
36EVID=${DIVSQRT_EVIDENCE_DIR:-$HOME/workspace/evidence-out/E1-DIVSQRT}
37QUIET=$HOME/workspace/.spark-quiet
38OWNER="lane2 E1 DIV/SQRT chip run"
39RUN=$(mktemp -d /tmp/divsqrt-run.XXXXXX)
40FLAG_MINE=0
41refuse() { echo "REFUSED: $*"; echo "VERDICT NOT_RUN"; exit 1; }
42cleanup() { if [ "$FLAG_MINE" = 1 ] && grep -q "^$OWNER" "$QUIET" 2>/dev/null; then rm -f "$QUIET"; fi; }
43trap cleanup EXIT
44sha() { sha256sum "$1" | cut -d' ' -f1; }
45
46case "$(realpath -m "$EVID")/" in "$HERE"/*|"$(realpath -m "$PHYSICS")"/*) refuse "evidence dir $EVID is inside a candidate tree";; esac
47[ -z "$(git -C "$HERE" status --porcelain)" ] || refuse "omega tree $HERE is dirty"
48OMEGA_COMMIT=$(git -C "$HERE" rev-parse HEAD) || refuse "cannot read omega HEAD"
49PIN=$(tr -d '[:space:]' < "$HERE/physics.lock")
50PHYS_COMMIT=$(git -C "$PHYSICS" rev-parse HEAD) || refuse "cannot read physics HEAD at $PHYSICS"
51[ "$PHYS_COMMIT" = "$PIN" ] || refuse "physics checkout is at $PHYS_COMMIT, physics.lock pins $PIN"
52[ -z "$(git -C "$PHYSICS" status --porcelain)" ] || refuse "physics checkout $PHYSICS is dirty"
53[ -e "$QUIET" ] && refuse "quiet flag is up: $(cat "$QUIET")"
54[ -n "$(pgrep est_load)" ] && refuse "an est_load process is running"
55fuser /tmp/aien-gb10.lock >/dev/null 2>&1 && refuse "/tmp/aien-gb10.lock is held"
56
57echo "== host tier"
58make -s -C "$HERE" build/test_omega_divsqrt_gb10_cpu > "$RUN/host-build.log" 2>&1 || refuse "host build failed"
59"$HERE/build/test_omega_divsqrt_gb10_cpu" > "$RUN/host.log" 2>&1; HOST_RC=$?
60tail -1 "$RUN/host.log"
61echo "== nvdisasm provenance"
62"$HERE/tools/divsqrt_nvdisasm_check.sh" > "$RUN/nvdisasm.log" 2>&1; NVD_RC=$?
63grep -E '^\[|^VERDICT|^disassembler' "$RUN/nvdisasm.log"
64[ "$HOST_RC" = 0 ] && [ "$NVD_RC" = 0 ] || refuse "host tier ($HOST_RC) or nvdisasm check ($NVD_RC) failed; no chip run"
65KDIG=$("$HERE/build/test_omega_divsqrt_gb10_cpu" --digest)
66
67START=$(date -u +%Y-%m-%dT%H:%M:%SZ)
68set -o noclobber
69echo "$OWNER start=$START expected_end=$(date -u -d '+3 hours' +%Y-%m-%dT%H:%M:%SZ) pid=$$" > "$QUIET" || refuse "could not create the quiet flag"
70set +o noclobber
71FLAG_MINE=1
72exec 9> /tmp/aien-gb10.lock || refuse "cannot open /tmp/aien-gb10.lock"
73flock -x 9 || refuse "cannot take /tmp/aien-gb10.lock"
74
75echo "== chip build"
76NV=$PHYSICS/third_party/nvidia-open-580.173.02
77BIN=$RUN/test_omega_divsqrt_gb10
78(cd "$HERE" && gcc -std=gnu11 -O2 -Wall -Wextra -Werror -ffp-contract=off -pthread \
79 -Isrc -I"$PHYSICS/nvrm" -I"$PHYSICS/m16" \
80 -I"$NV/src/common/sdk/nvidia/inc" -I"$NV/kernel-open/common/inc" \
81 -I"$NV/kernel-open/nvidia-uvm" -I"$NV/src/nvidia/arch/nvalloc/unix/include" \
82 -o "$BIN" tests/test_omega_divsqrt_gb10.c src/omega_numeric_divsqrt_gb10.c src/omega_numeric.c \
83 src/omega_numeric_provenance.c src/omega_blackwell_encoder.c src/omega_blackwell_codegen.c \
84 src/omega_blackwell_matmul.c src/omega_blackwell_qmd.c src/omega_om_units.c \
85 "$PHYSICS/nvrm/nvrm.c" "$PHYSICS/m16/m16_native.c") > "$RUN/chip-build.log" 2>&1 || { cat "$RUN/chip-build.log"; refuse "chip build failed"; }
86if nm -u "$BIN" | grep -Eq '\b(sqrtf?|expf?|logf?|powf?|fmaf?|sinf?|cosf?|fdiv|divf)\b'; then refuse "libm math symbols in $BIN"; fi
87if nm -u "$BIN" | grep -Eiq 'cuda|cuInit|cuLaunch|nvrtc|cublas'; then refuse "CUDA symbols in $BIN"; fi
88BIN_SHA=$(sha "$BIN")
89
90echo "== chip run (not killed, not timed out)"
91"$BIN" --chip > "$RUN/chip.log" 2>&1; CHIP_RC=$?
92END=$(date -u +%Y-%m-%dT%H:%M:%SZ)
93exec 9>&-
94grep -E '^RESULT|^VERDICT' "$RUN/chip.log"
95
96OMEGA_CLEAN_AFTER=$([ -z "$(git -C "$HERE" status --porcelain)" ] && echo true || echo false)
97PHYS_CLEAN_AFTER=$([ -z "$(git -C "$PHYSICS" status --porcelain)" ] && echo true || echo false)
98OMEGA_SAME_AFTER=$([ "$(git -C "$HERE" rev-parse HEAD 2>/dev/null)" = "$OMEGA_COMMIT" ] && echo true || echo false)
99PHYS_SAME_AFTER=$([ "$(git -C "$PHYSICS" rev-parse HEAD 2>/dev/null)" = "$PHYS_COMMIT" ] && echo true || echo false)
100field() { grep "^RESULT chip $1 " "$RUN/chip.log" | tr ' ' '\n' | sed -n "s/^$2=//p" | head -1; }
101VERDICT=$(sed -n 's/^VERDICT \([A-Z_]*\).*/\1/p' "$RUN/chip.log" | tail -1)
102[ -n "$VERDICT" ] || VERDICT=NOT_RUN
103[ "$CHIP_RC" = 0 ] || [ "$VERDICT" != PASS ] || VERDICT=FAIL
104[ "$OMEGA_CLEAN_AFTER" = true ] && [ "$PHYS_CLEAN_AFTER" = true ] && [ "$OMEGA_SAME_AFTER" = true ] && [ "$PHYS_SAME_AFTER" = true ] || { [ "$VERDICT" = PASS ] && VERDICT=FAIL; }
105
106mkdir -p "$EVID/blobs"
107LOG_SHA=$(sha "$RUN/chip.log")
108[ -e "$EVID/blobs/$LOG_SHA.log" ] || { cp "$RUN/chip.log" "$EVID/blobs/$LOG_SHA.log" && chmod 0444 "$EVID/blobs/$LOG_SHA.log"; } || { echo "could not store the chip log blob"; echo "VERDICT FAIL"; exit 1; }
109num() { local v; v=$(field "$1" "$2"); echo "${v:-null}"; }
110BODY=$(jq -n --arg gate "E1-DIVSQRT" --arg omega "$OMEGA_COMMIT" --arg phys "$PHYS_COMMIT" --arg pin "$PIN" \
111 --argjson oclean true --argjson pclean true --argjson oafter "$OMEGA_CLEAN_AFTER" --argjson pafter "$PHYS_CLEAN_AFTER" \
112 --argjson osame "$OMEGA_SAME_AFTER" --argjson psame "$PHYS_SAME_AFTER" \
113 --arg bin "$BIN_SHA" --arg log "$LOG_SHA" --arg kd "$KDIG" --arg start "$START" --arg end "$END" \
114 --arg nvd "$(grep '^disassembler' "$RUN/nvdisasm.log")" --arg host "$(tail -1 "$RUN/host.log")" \
115 --argjson dchk "$(num DIV checked)" --argjson dedge "$(num DIV edge_and_corpus)" \
116 --argjson dbad "$(num DIV mismatches)" --argjson dmath "$(num DIV mismatches_vs_omega_math)" --argjson dfill "$(num DIV unwritten)" \
117 --arg dver "$(field DIV verdict)" --arg seed "$(field DIV seed)" \
118 --argjson schk "$(num SQRT checked)" --argjson sbad "$(num SQRT mismatches)" \
119 --argjson smath "$(num SQRT mismatches_vs_omega_math)" --argjson sfill "$(num SQRT unwritten)" --arg sver "$(field SQRT verdict)" \
120 --arg verdict "$VERDICT" --argjson rc "$CHIP_RC" '{
121 gate: $gate, row: "E1 gap table row 7: GB10 correctly rounded FP32 DIV and SQRT",
122 omega_commit: $omega, omega_tree_clean_before: $oclean, omega_tree_clean_after: $oafter, omega_commit_unchanged_after: $osame,
123 physics_commit: $phys, physics_lock_pin: $pin, physics_tree_clean_before: $pclean, physics_tree_clean_after: $pafter, physics_commit_unchanged_after: $psame,
124 binary_sha256: $bin, chip_log_sha256: $log, kernels: ($kd | split("\n") | map(select(length > 0) | split(" ") | {op: .[0], instructions: (.[1] | tonumber), sha256: .[2]})),
125 nvdisasm_check: $nvd, host_tier: $host,
126 div: {checked: $dchk, edge_and_corpus: $dedge, mismatches_vs_fdiv: $dbad, mismatches_vs_omega_math_div: $dmath, mismatches_unwritten: $dfill, rng_seed: $seed, verdict: $dver},
127 sqrt: {checked: $schk, exhaustive: ($schk == 4294967296), mismatches_vs_fsqrt: $sbad, mismatches_vs_omega_math_sqrt: $smath, mismatches_unwritten: $sfill, verdict: $sver},
128 chip_exit_status: $rc, started_utc: $start, finished_utc: $end, verdict: $verdict }')
129[ -n "$BODY" ] && printf '%s\n' "$BODY" > "$RUN/receipt.json" && jq -e . "$RUN/receipt.json" >/dev/null || { echo "receipt JSON could not be built"; echo "VERDICT FAIL"; exit 1; }
130RSHA=$(sha "$RUN/receipt.json")
131OUT=$EVID/$RSHA.json
132if [ -e "$OUT" ]; then echo "receipt $OUT already exists (identical content)"; else
133 set -o noclobber; { cat "$RUN/receipt.json" > "$OUT" && chmod 0444 "$OUT"; } || { echo "could not write receipt $OUT"; echo "VERDICT FAIL"; exit 1; }; set +o noclobber; fi
134cmp -s "$RUN/receipt.json" "$OUT" || { echo "receipt $OUT does not match what was built"; echo "VERDICT FAIL"; exit 1; }
135echo "RECEIPT $OUT"
136echo "VERDICT $VERDICT"
137[ "$VERDICT" = PASS ] || exit 1
138exit 0