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 / tests / run_reduce_chip.sh

166 lines · 10173 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# tests/run_reduce_chip.sh -- E1 WP-D reduction chip parity run (GB10).
18#
19# tests/run_reduce_chip.sh --physics-dir DIR [--evidence-dir DIR] [--quiet-flag]
20#
21# 1. The omega tree (this repo) must be clean; the run commit is its HEAD.
22# The physics checkout must be clean and at the commit in physics.lock.
23# 2. Builds the chip test binary (tests/test_omega_reduce.c with the GB10
24# executor) with -ffp-contract=off into build/reduce-runs/<run-id>/ and
25# refuses a binary with libm math or CUDA symbols.
26# 3. Runs it under /tmp/aien-gb10.lock (waits for the lock; never times out
27# or kills the chip test). --quiet-flag also creates ~/workspace/.spark-quiet
28# (only when no flag exists) and removes it afterwards.
29# 4. PASS needs exit status 0, "RED_GB10_PARITY_<OP>: PASS" for each of
30# SUM, MAX, MIN and MEAN, "RED_GB10_PARITY: PASS" and "E1 Reduce Verdict:
31# PASS" in the log, and a clean tree afterwards. MEAN is chip SUM levels
32# plus one chip division (the GB10 DIV kernel, E1 row 7); the receipt says so.
33# 5. Writes a content-addressed receipt <evidence-dir>/<sha256>.json (mode
34# 0444, never overwritten) for PASS and FAIL alike, plus the log and binary
35# as blobs/<sha256>.{log,bin}. The evidence dir must lie outside the tree.
36# Shell + coreutils + git + jq + gcc. No Python. Exit 0 PASS, 1 FAIL, 2 refused.
37set -u
38SELF_DIR=$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)
39OMEGA=$(cd "$SELF_DIR/.." && pwd)
40PHYS=""
41EVID=$HOME/workspace/evidence-out/E1-REDUCE
42QUIET=0
43FLAG=$HOME/workspace/.spark-quiet
44FLAG_OWNER="lane2 E1 WP-D reduce chip run"
45while [ $# -gt 0 ]; do
46 case $1 in
47 --physics-dir) PHYS=$2; shift 2 ;;
48 --evidence-dir) EVID=$2; shift 2 ;;
49 --quiet-flag) QUIET=1; shift ;;
50 *) echo "unknown argument $1" >&2; exit 2 ;;
51 esac
52done
53die() { echo "run_reduce_chip: $*" >&2; exit 2; }
54[ -n "$PHYS" ] && [ -d "$PHYS" ] || die "--physics-dir is required"
55PHYS=$(cd "$PHYS" && pwd)
56[ -z "$(git -C "$OMEGA" status --porcelain)" ] || die "omega tree is dirty; refusing"
57COMMIT=$(git -C "$OMEGA" rev-parse HEAD)
58LOCKED=$(tr -d ' \n' < "$OMEGA/physics.lock")
59PHEAD=$(git -C "$PHYS" rev-parse HEAD)
60[ "$PHEAD" = "$LOCKED" ] || die "physics checkout is at $PHEAD, physics.lock pins $LOCKED"
61[ -z "$(git -C "$PHYS" status --porcelain)" ] || die "physics checkout is dirty"
62mkdir -p "$EVID/blobs"
63EVID=$(cd "$EVID" && pwd)
64case "$EVID/" in "$OMEGA/"*|"$PHYS/"*) die "evidence dir must be outside the omega tree and physics checkout" ;; esac
65
66RUN_ID=$(date -u +%Y%m%dT%H%M%SZ)-${COMMIT:0:12}
67mkdir -p "$OMEGA/build/reduce-runs" || die "cannot create build/reduce-runs"
68# one fresh directory per invocation, so concurrent runs never share files
69OUT=$(mktemp -d "$OMEGA/build/reduce-runs/$RUN_ID.XXXXXX") || die "cannot create a run directory"
70RUN_ID=$(basename "$OUT")
71BIN=$OUT/test_omega_reduce_gb10
72NV=$PHYS/third_party/nvidia-open-580.173.02
73FAIL_REASON=""
74(cd "$OMEGA" && gcc -std=gnu11 -O2 -Wall -Wextra -Werror -ffp-contract=off \
75 -Isrc -I"$PHYS/forge" -I"$PHYS/nvrm" -I"$PHYS/m16" \
76 -I"$NV/src/common/sdk/nvidia/inc" -I"$NV/kernel-open/common/inc" \
77 -I"$NV/kernel-open/nvidia-uvm" -I"$NV/src/nvidia/arch/nvalloc/unix/include" \
78 -o "$BIN" tests/test_omega_reduce.c src/omega_numeric_reduce.c src/omega_numeric_reduce_gb10.c \
79 src/omega_numeric.c src/omega_numeric_gb10.c src/omega_numeric_divsqrt_gb10.c \
80 src/omega_numeric_provenance.c src/omega_blackwell_codegen.c \
81 src/omega_blackwell_encoder.c src/omega_blackwell_matmul.c src/omega_blackwell_qmd.c \
82 src/forge_realization.c src/aegis_verification.c src/omega_om_units.c \
83 "$PHYS/forge/forge_descriptor.c" "$PHYS/forge/forge_realize.c" "$PHYS/sha256_clean.c" \
84 "$PHYS/nvrm/nvrm.c" "$PHYS/m16/m16_native.c") > "$OUT/build.log" 2>&1 || FAIL_REASON="build failed"
85if [ -z "$FAIL_REASON" ]; then
86 nm -u "$BIN" | grep -Eq '\b(sqrtf?|expf?|logf?|powf?|fmaf?|sinf?|cosf?|roundf?|fabsf?)\b' && FAIL_REASON="libm symbols in binary"
87 nm -u "$BIN" | grep -Eq 'libcuda(rt)?\.so|\b(cuInit|cuCtx|cuMem|cuStream|cudaMalloc)\b' && FAIL_REASON="CUDA symbols in binary"
88fi
89STATUS=-1
90BIN_SHA_BUILT=""
91[ -z "$FAIL_REASON" ] && { BIN_SHA_BUILT=$(sha256sum "$BIN" | cut -d' ' -f1); [ -n "$BIN_SHA_BUILT" ] || FAIL_REASON="cannot hash binary after build"; }
92if [ -z "$FAIL_REASON" ]; then
93 CREATED_FLAG=0
94 if [ "$QUIET" = 1 ]; then
95 # wait until no other flag exists, then create ours atomically
96 until (set -o noclobber; echo "$FLAG_OWNER" > "$FLAG") 2>/dev/null; do sleep 60; done
97 # remove our flag (never anyone else's) however this script ends
98 trap '[ "$(cat "$FLAG" 2>/dev/null)" = "$FLAG_OWNER" ] && rm -f "$FLAG"' EXIT
99 CREATED_FLAG=1
100 fi
101 flock /tmp/aien-gb10.lock "$BIN" > "$OUT/reduce.log" 2> "$OUT/reduce.stderr"
102 STATUS=$?
103 if [ "$CREATED_FLAG" = 1 ] && [ "$(cat "$FLAG" 2>/dev/null)" = "$FLAG_OWNER" ]; then rm -f "$FLAG"; fi
104 echo "$STATUS" > "$OUT/reduce.status"
105 [ "$STATUS" = 0 ] || FAIL_REASON="test binary exit status $STATUS"
106 for op in SUM MAX MIN MEAN; do
107 grep -q "^RED_GB10_PARITY_${op}: PASS" "$OUT/reduce.log" || FAIL_REASON="${FAIL_REASON:-no RED_GB10_PARITY_${op} PASS line}"
108 done
109 grep -q '^RED_GB10_PARITY: PASS' "$OUT/reduce.log" || FAIL_REASON="${FAIL_REASON:-no RED_GB10_PARITY PASS line}"
110 grep -qx 'E1 Reduce Verdict: PASS' "$OUT/reduce.log" || FAIL_REASON="${FAIL_REASON:-verdict line is not PASS}"
111fi
112[ -z "$(git -C "$OMEGA" status --porcelain)" ] && CLEAN_AFTER=true || { CLEAN_AFTER=false; FAIL_REASON="${FAIL_REASON:-tree dirty after run}"; }
113[ "$(git -C "$OMEGA" rev-parse HEAD)" = "$COMMIT" ] || FAIL_REASON="${FAIL_REASON:-HEAD moved during run}"
114
115# store_blob SRC EXT -> prints the digest. An existing blob is trusted only if
116# its content hashes to its name; a new one is copied to a temp name, checked,
117# sealed and moved into place without overwriting.
118store_blob() {
119 local src=$1 ext=$2 d dst tmp have
120 d=$(sha256sum "$src" | cut -d' ' -f1); [ -n "$d" ] || die "cannot hash $src"
121 dst=$EVID/blobs/$d.$ext
122 if [ -e "$dst" ]; then
123 have=$(sha256sum "$dst" | cut -d' ' -f1)
124 [ "$have" = "$d" ] || die "existing blob $dst does not match its digest"
125 else
126 tmp=$(mktemp "$EVID/blobs/.tmp.XXXXXX") || die "cannot create temp blob"
127 cp "$src" "$tmp" || { rm -f "$tmp"; die "cannot store $ext blob"; }
128 have=$(sha256sum "$tmp" | cut -d' ' -f1)
129 [ "$have" = "$d" ] || { rm -f "$tmp"; die "stored $ext blob does not match its digest"; }
130 chmod 0444 "$tmp" || { rm -f "$tmp"; die "cannot seal $ext blob"; }
131 mv -n "$tmp" "$dst"; rm -f "$tmp"
132 have=$(sha256sum "$dst" | cut -d' ' -f1)
133 [ "$have" = "$d" ] || die "blob $dst does not match its digest after publish"
134 fi
135 echo "$d"
136}
137BIN_SHA=""; LOG_SHA=""; STDERR_SHA=""
138if [ -f "$BIN" ]; then BIN_SHA=$(store_blob "$BIN" bin) || exit 2; fi
139[ -z "$BIN_SHA_BUILT" ] || [ "$BIN_SHA" = "$BIN_SHA_BUILT" ] || FAIL_REASON="${FAIL_REASON:-binary changed between build and receipt}"
140if [ -f "$OUT/reduce.log" ]; then LOG_SHA=$(store_blob "$OUT/reduce.log" log) || exit 2; fi
141if [ -f "$OUT/reduce.stderr" ]; then STDERR_SHA=$(store_blob "$OUT/reduce.stderr" stderr) || exit 2; fi
142VERDICT=PASS; [ -n "$FAIL_REASON" ] && VERDICT=FAIL
143PARITY=$(grep '^RED_GB10_PARITY:' "$OUT/reduce.log" 2>/dev/null | head -1)
144PSUM=$(grep '^RED_GB10_PARITY_SUM:' "$OUT/reduce.log" 2>/dev/null | head -1)
145PMAX=$(grep '^RED_GB10_PARITY_MAX:' "$OUT/reduce.log" 2>/dev/null | head -1)
146PMIN=$(grep '^RED_GB10_PARITY_MIN:' "$OUT/reduce.log" 2>/dev/null | head -1)
147PMEAN=$(grep '^RED_GB10_PARITY_MEAN:' "$OUT/reduce.log" 2>/dev/null | head -1)
148TMP=$OUT/receipt.json
149jq -n --arg suite E1_REDUCE_GB10_PARITY --arg status "$VERDICT" --arg reason "$FAIL_REASON" \
150 --arg run_id "$RUN_ID" --arg commit "$COMMIT" --arg physics "$PHEAD" --argjson clean_after "$CLEAN_AFTER" \
151 --arg order "RECURSIVE_TILE32_PAIRWISE_TREE_LANE_DELTA_16_8_4_2_1_PAD_IDENTITY_MIN_ONE_LEVEL" \
152 --arg bin "$BIN_SHA" --arg log "$LOG_SHA" --arg stderr_sha "$STDERR_SHA" --arg parity "$PARITY" --arg psum "$PSUM" --arg pmax "$PMAX" --arg pmin "$PMIN" --arg pmean "$PMEAN" --arg exit_status "$STATUS" \
153 --arg host "$(uname -n)" --arg kernel "$(uname -r)" \
154 '{suite:$suite,status:$status,reason:$reason,run_id:$run_id,omega_commit:$commit,omega_clean_before:true,
155 omega_clean_after:$clean_after,physics_commit:$physics,declared_order:$order,binary_sha256:$bin,
156 log_sha256:$log,stderr_sha256:$stderr_sha,exit_status:$exit_status,parity_line:$parity,
157 ops:["SUM","MAX","MIN","MEAN"],parity_by_op:{SUM:$psum,MAX:$pmax,MIN:$pmin,MEAN:$pmean},
158 chip_kernels:{SUM:"REDUCE_SUM (WP-C patch, SHFL.DOWN+FADD)",MAX:"reduce minmax patch SHFL.DOWN+FMNMX !PT",MIN:"reduce minmax patch SHFL.DOWN+FMNMX PT",MEAN:"chip SUM levels + chip DIV (omega_ds_gb10_run)"},
159 mean_final_division:"GB10_DIV omega_ds_gb10_run(DIV, sum, u2f(n)); no host step",host:$host,kernel:$kernel}' > "$TMP" || die "receipt json (jq) failed, no receipt written"
160[ -s "$TMP" ] || die "empty receipt, not written"
161[ "$VERDICT" != PASS ] || { [ -n "$BIN_SHA" ] && [ -n "$LOG_SHA" ]; } || die "PASS without binary and log digests refused"
162DIG=$(sha256sum "$TMP" | cut -d' ' -f1)
163(set -o noclobber; cat "$TMP" > "$EVID/$DIG.json") || die "receipt $DIG.json already exists"
164chmod 0444 "$EVID/$DIG.json"
165echo "receipt: $EVID/$DIG.json status=$VERDICT ${FAIL_REASON}"
166[ "$VERDICT" = PASS ]