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_tensor_chip.sh

213 lines · 13409 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_tensor_chip.sh -- M20 OMEGA_TENSOR GB10 parity chip run.
18#
19# GB10_CHIP_RUN=1 tests/run_tensor_chip.sh --physics-dir DIR [--evidence-dir DIR]
20#
21# Pattern of tests/run_reduce_chip.sh, without any quiet-flag option (this
22# script never creates or touches ~/workspace/.spark-quiet).
23# 1. Refuses unless GB10_CHIP_RUN=1. The omega tree (this repo) must be clean;
24# the run commit is its HEAD. The physics checkout must be clean and at the
25# commit in physics.lock.
26# 2. Builds tests/test_omega_tensor_gb10.c with the CPU table, the GB10 table
27# and the E1 GB10 executors, -ffp-contract=off, into
28# build/tensor-runs/<run-id>/, and refuses a binary with libm math or CUDA
29# symbols.
30# 3. Runs it with --chip under /tmp/aien-gb10.lock (waits for the lock; no
31# timeout; the chip test is never killed). Inside `spark-window run`
32# (SPARK_WINDOW set and AIEN_GB10_LOCK_HELD=1) the window already holds
33# that lock, shared or exclusive, so the script takes no lock of its own:
34# an exclusive flock beside the window's shared one would wait on its own
35# window forever. The markers are only environment text, so the claim is
36# checked first: SPARK_WINDOW_DIR must be that window's directory, marked
37# held, and one of its holder.pid's open files must carry an flock on the
38# lock file's inode (/proc/<holder>/fdinfo "lock:" lines; /proc/locks names
39# the short-lived flock(1) that took it, not the holder). An unverified
40# claim fails the run without touching the chip. The receipt records which
41# lock was held (gb10_lock).
42# 4. PASS needs exit status 0 and the lines "TENSOR_GB10_HOST: PASS",
43# "TENSOR_GB10_PARITY: PASS", "TENSOR_GB10_MUTANTS: PASS" and
44# "M20 Tensor GB10 Verdict: PASS", and clean trees with unmoved HEADs after.
45# 5. Writes a content-addressed receipt <evidence-dir>/<sha256>.json (mode
46# 0444, never overwritten) for PASS and FAIL alike, plus the log and binary
47# as blobs/<sha256>.{log,bin}, and the chip run stderr (GB10_CALL per-call
48# timing, GB10_DEVFAIL device step diagnostics) as blobs/<sha256>.stderr. The evidence dir must lie outside the trees.
49# Shell + coreutils + git + jq + gcc. No Python. Exit 0 PASS, 1 FAIL, 2 refused.
50set -u
51SELF_DIR=$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)
52OMEGA=$(cd "$SELF_DIR/.." && pwd)
53PHYS=""
54EVID=$HOME/workspace/evidence-out/M20-TENSOR-GB10
55while [ $# -gt 0 ]; do
56 case $1 in
57 --physics-dir) PHYS=$2; shift 2 ;;
58 --evidence-dir) EVID=$2; shift 2 ;;
59 *) echo "unknown argument $1" >&2; exit 2 ;;
60 esac
61done
62die() { echo "run_tensor_chip: $*" >&2; exit 2; }
63# window_holds_chip: the spark-window named by SPARK_WINDOW really holds /tmp/aien-gb10.lock now.
64# Its holder is a background process (not our ancestor) whose lock was taken by a flock(1) child
65# that has exited, so the holder's own open file descriptions (fdinfo "lock:") are the check.
66window_holds_chip() {
67 local d=${SPARK_WINDOW_DIR:-} hp ino
68 [ -n "$d" ] && [ "$(basename "$d")" = "$SPARK_WINDOW" ] && [ -f "$d/held" ] || return 1
69 hp=$(cat "$d/holder.pid" 2>/dev/null) || return 1
70 case $hp in ''|*[!0-9]*) return 1 ;; esac
71 ino=$(stat -c %i /tmp/aien-gb10.lock 2>/dev/null) || return 1
72 cat /proc/"$hp"/fdinfo/* 2>/dev/null |
73 awk -v i="$ino" '$1 == "lock:" && $3 == "FLOCK" { split($7, a, ":"); if (a[3] == i) f = 1 } END { exit !f }'
74}
75[ "${GB10_CHIP_RUN:-}" = 1 ] || die "chip run refused: GB10_CHIP_RUN=1 is not set"
76[ -n "$PHYS" ] && [ -d "$PHYS" ] || die "--physics-dir is required"
77PHYS=$(cd "$PHYS" && pwd)
78[ -z "$(git -C "$OMEGA" status --porcelain)" ] || die "omega tree is dirty; refusing"
79COMMIT=$(git -C "$OMEGA" rev-parse HEAD)
80LOCKED=$(tr -d ' \n' < "$OMEGA/physics.lock")
81PHEAD=$(git -C "$PHYS" rev-parse HEAD)
82[ "$PHEAD" = "$LOCKED" ] || die "physics checkout is at $PHEAD, physics.lock pins $LOCKED"
83[ -z "$(git -C "$PHYS" status --porcelain)" ] || die "physics checkout is dirty"
84mkdir -p "$EVID/blobs"
85EVID=$(cd "$EVID" && pwd)
86case "$EVID/" in "$OMEGA/"*|"$PHYS/"*) die "evidence dir must be outside the omega tree and physics checkout" ;; esac
87
88STARTED=$(date -u +%Y-%m-%dT%H:%M:%SZ)
89RUN_ID=$(date -u +%Y%m%dT%H%M%SZ)-${COMMIT:0:12}
90mkdir -p "$OMEGA/build/tensor-runs" || die "cannot create build/tensor-runs"
91# one fresh directory per invocation, so concurrent runs never share files
92OUT=$(mktemp -d "$OMEGA/build/tensor-runs/$RUN_ID.XXXXXX") || die "cannot create a run directory"
93RUN_ID=$(basename "$OUT")
94BIN=$OUT/test_omega_tensor_gb10
95NV=$PHYS/third_party/nvidia-open-580.173.02
96FAIL_REASON=""
97(cd "$OMEGA" && gcc -std=gnu11 -O2 -Wall -Wextra -Werror -D_GNU_SOURCE -ffp-contract=off \
98 -Isrc -Isrc/tensor -I"$PHYS/forge" -I"$PHYS/nvrm" -I"$PHYS/m16" \
99 -I"$NV/src/common/sdk/nvidia/inc" -I"$NV/kernel-open/common/inc" \
100 -I"$NV/kernel-open/nvidia-uvm" -I"$NV/src/nvidia/arch/nvalloc/unix/include" \
101 -o "$BIN" tests/test_omega_tensor_gb10.c src/tensor/omega_tensor.c src/tensor/omega_tensor_cpu.c \
102 src/tensor/omega_tensor_reduce_seam.c src/tensor/omega_tensor_gb10.c \
103 src/omega_numeric_reduce.c src/omega_numeric_transc.c src/omega_numeric_reduce_gb10.c \
104 src/omega_numeric.c src/omega_numeric_gb10.c src/omega_numeric_divsqrt_gb10.c \
105 src/omega_numeric_provenance.c src/omega_blackwell_codegen.c \
106 src/omega_blackwell_encoder.c src/omega_blackwell_matmul.c src/omega_blackwell_qmd.c \
107 src/forge_realization.c src/aegis_verification.c src/omega_om_units.c \
108 "$PHYS/forge/forge_descriptor.c" "$PHYS/forge/forge_realize.c" "$PHYS/sha256_clean.c" \
109 "$PHYS/nvrm/nvrm.c" "$PHYS/m16/m16_native.c") > "$OUT/build.log" 2>&1 || FAIL_REASON="build failed"
110if [ -z "$FAIL_REASON" ]; then
111 nm -u "$BIN" | grep -Eq '\b(sqrtf?|expf?|logf?|powf?|fmaf?|sinf?|cosf?|roundf?|fabsf?)\b' && FAIL_REASON="libm symbols in binary"
112 nm -u "$BIN" | grep -Eq 'libcuda(rt)?\.so|\b(cuInit|cuCtx|cuMem|cuStream|cudaMalloc)\b' && FAIL_REASON="CUDA symbols in binary"
113fi
114STATUS=-1
115BIN_SHA_BUILT=""
116GB10_LOCK=""
117[ -z "$FAIL_REASON" ] && { BIN_SHA_BUILT=$(sha256sum "$BIN" | cut -d' ' -f1); [ -n "$BIN_SHA_BUILT" ] || FAIL_REASON="cannot hash binary after build"; }
118if [ -z "$FAIL_REASON" ]; then
119 if [ "${AIEN_GB10_LOCK_HELD:-}" = 1 ] && [ -n "${SPARK_WINDOW:-}" ]; then
120 GB10_LOCK="spark-window $SPARK_WINDOW"
121 gb10() { "$@"; }
122 window_holds_chip || { GB10_LOCK="refused: unverified spark-window $SPARK_WINDOW"; FAIL_REASON="AIEN_GB10_LOCK_HELD=1 and SPARK_WINDOW=$SPARK_WINDOW, but no open file of that window's holder carries an flock on /tmp/aien-gb10.lock: chip refused"; }
123 else
124 GB10_LOCK="flock /tmp/aien-gb10.lock"
125 gb10() { flock /tmp/aien-gb10.lock "$@"; }
126 fi
127fi
128if [ -z "$FAIL_REASON" ]; then
129 # waits for the lock; no timeout; never killed
130 GB10_CHIP_RUN=1 gb10 "$BIN" --chip > "$OUT/tensor.log" 2> "$OUT/tensor.stderr"
131 STATUS=$?
132 echo "$STATUS" > "$OUT/tensor.status"
133 [ "$STATUS" = 0 ] || FAIL_REASON="test binary exit status $STATUS"
134 for k in TENSOR_GB10_HOST TENSOR_GB10_PARITY TENSOR_GB10_MUTANTS; do
135 grep -q "^$k: PASS" "$OUT/tensor.log" || FAIL_REASON="${FAIL_REASON:-no $k PASS line}"
136 done
137 grep -qx 'M20 Tensor GB10 Verdict: PASS' "$OUT/tensor.log" || FAIL_REASON="${FAIL_REASON:-verdict line is not PASS}"
138fi
139FINISHED=$(date -u +%Y-%m-%dT%H:%M:%SZ)
140[ -z "$(git -C "$OMEGA" status --porcelain)" ] && CLEAN_AFTER=true || { CLEAN_AFTER=false; FAIL_REASON="${FAIL_REASON:-omega tree dirty after run}"; }
141[ "$(git -C "$OMEGA" rev-parse HEAD)" = "$COMMIT" ] && HEAD_SAME=true || { HEAD_SAME=false; FAIL_REASON="${FAIL_REASON:-HEAD moved during run}"; }
142[ -z "$(git -C "$PHYS" status --porcelain)" ] && PCLEAN_AFTER=true || { PCLEAN_AFTER=false; FAIL_REASON="${FAIL_REASON:-physics dirty after run}"; }
143[ "$(git -C "$PHYS" rev-parse HEAD)" = "$PHEAD" ] && PHEAD_SAME=true || { PHEAD_SAME=false; FAIL_REASON="${FAIL_REASON:-physics HEAD moved during run}"; }
144
145# store_blob SRC EXT -> prints the digest. An existing blob is trusted only if
146# its content hashes to its name; a new one is copied to a temp name, checked,
147# sealed and moved into place without overwriting.
148store_blob() {
149 local src=$1 ext=$2 d dst tmp have
150 d=$(sha256sum "$src" | cut -d' ' -f1); [ -n "$d" ] || die "cannot hash $src"
151 dst=$EVID/blobs/$d.$ext
152 if [ -e "$dst" ]; then
153 have=$(sha256sum "$dst" | cut -d' ' -f1)
154 [ "$have" = "$d" ] || die "existing blob $dst does not match its digest"
155 else
156 tmp=$(mktemp "$EVID/blobs/.tmp.XXXXXX") || die "cannot create temp blob"
157 cp "$src" "$tmp" || { rm -f "$tmp"; die "cannot store $ext blob"; }
158 have=$(sha256sum "$tmp" | cut -d' ' -f1)
159 [ "$have" = "$d" ] || { rm -f "$tmp"; die "stored $ext blob does not match its digest"; }
160 chmod 0444 "$tmp" || { rm -f "$tmp"; die "cannot seal $ext blob"; }
161 mv -n "$tmp" "$dst"; rm -f "$tmp"
162 have=$(sha256sum "$dst" | cut -d' ' -f1)
163 [ "$have" = "$d" ] || die "blob $dst does not match its digest after publish"
164 fi
165 echo "$d"
166}
167BIN_SHA=""; LOG_SHA=""; ERR_SHA=""
168if [ -f "$BIN" ]; then BIN_SHA=$(store_blob "$BIN" bin) || exit 2; fi
169[ -z "$BIN_SHA_BUILT" ] || [ "$BIN_SHA" = "$BIN_SHA_BUILT" ] || FAIL_REASON="${FAIL_REASON:-binary changed between build and receipt}"
170if [ -f "$OUT/tensor.log" ]; then LOG_SHA=$(store_blob "$OUT/tensor.log" log) || exit 2; fi
171if [ -f "$OUT/tensor.stderr" ]; then ERR_SHA=$(store_blob "$OUT/tensor.stderr" stderr) || exit 2; fi
172DEVFAIL_N=0; FAILED_CALLS_N=0
173if [ -f "$OUT/tensor.stderr" ]; then
174 DEVFAIL_N=$(grep -c "^GB10_DEVFAIL " "$OUT/tensor.stderr")
175 FAILED_CALLS_N=$(grep -c "^GB10_CALL .* FAILED$" "$OUT/tensor.stderr")
176fi
177VERDICT=PASS; [ -n "$FAIL_REASON" ] && VERDICT=FAIL
178line() { grep "^$1" "$OUT/tensor.log" 2>/dev/null | head -1; }
179TMP=$OUT/receipt.json
180jq -n --arg suite M20_TENSOR_GB10_PARITY --arg status "$VERDICT" --arg reason "$FAIL_REASON" \
181 --arg run_id "$RUN_ID" --arg commit "$COMMIT" --arg physics "$PHEAD" --arg pin "$LOCKED" \
182 --argjson clean_after "$CLEAN_AFTER" --argjson head_same "$HEAD_SAME" \
183 --argjson pclean_after "$PCLEAN_AFTER" --argjson phead_same "$PHEAD_SAME" \
184 --arg started "$STARTED" --arg finished "$FINISHED" \
185 --arg order "RECURSIVE_TILE32_PAIRWISE_TREE_LANE_DELTA_16_8_4_2_1_PAD_IDENTITY_MIN_ONE_LEVEL" \
186 --arg mm_order "MATMUL_V1_FMUL_RNE_PRODUCTS_THEN_E1_REDUCE_SUM_RECURSIVE_TILE32_PAIRWISE_TREE_LANE_DELTA_16_8_4_2_1_PAD_IDENTITY_MIN_ONE_LEVEL" \
187 --arg bin "$BIN_SHA" --arg log "$LOG_SHA" --arg errlog "$ERR_SHA" \
188 --argjson devfail_n "$DEVFAIL_N" --argjson failed_calls_n "$FAILED_CALLS_N" --arg exit_status "$STATUS" \
189 --arg host_line "$(line TENSOR_GB10_HOST:)" --arg parity "$(line TENSOR_GB10_PARITY:)" \
190 --arg mutants "$(line TENSOR_GB10_MUTANTS:)" --arg cases "$(line 'cases:')" \
191 --arg verdict_line "$(line 'M20 Tensor GB10 Verdict:')" \
192 --arg host "$(uname -n)" --arg kernel "$(uname -r)" --arg gb10_lock "$GB10_LOCK" \
193 '{suite:$suite,status:$status,reason:$reason,run_id:$run_id,started_utc:$started,finished_utc:$finished,
194 omega_commit:$commit,omega_tree_clean_before:true,omega_tree_clean_after:$clean_after,
195 omega_commit_unchanged_after:$head_same,physics_commit:$physics,physics_lock_pin:$pin,
196 physics_tree_clean_before:true,physics_tree_clean_after:$pclean_after,physics_commit_unchanged_after:$phead_same,
197 reduce_declared_order:$order,matmul_declared_order:$mm_order,binary_sha256:$bin,chip_log_sha256:$log,
198 chip_stderr_sha256:$errlog,devfail_lines:$devfail_n,failed_gb10_calls:$failed_calls_n,
199 chip_exit_status:$exit_status,cases_line:$cases,host_line:$host_line,parity_line:$parity,
200 mutants_line:$mutants,verdict_line:$verdict_line,
201 realization:{elementwise:"E1 omega_gb10_execute_simt_op (chunks <= 65536)",
202 reduce:"E1 omega_reduce_gb10 (MEAN final division is its declared host step)",
203 reduce_rows_sum:"E1 REDUCE_SUM warp kernel via omega_gb10_execute_simt_op, all rows per level",
204 matmul:"FMUL_RNE products + E1 tree; no Tensor Core, no FFMA"},
205 mutants:["WRONG_REDUCE_ORDER","FFMA_MATMUL","SWAPPED_OPERAND"],quiet_flag:"not used",gb10_lock:$gb10_lock,
206 host:$host,kernel:$kernel}' > "$TMP" || die "receipt json (jq) failed, no receipt written"
207[ -s "$TMP" ] || die "empty receipt, not written"
208[ "$VERDICT" != PASS ] || { [ -n "$BIN_SHA" ] && [ -n "$LOG_SHA" ]; } || die "PASS without binary and log digests refused"
209DIG=$(sha256sum "$TMP" | cut -d' ' -f1)
210(set -o noclobber; cat "$TMP" > "$EVID/$DIG.json") || die "receipt $DIG.json already exists"
211chmod 0444 "$EVID/$DIG.json"
212echo "receipt: $EVID/$DIG.json status=$VERDICT ${FAIL_REASON}"
213[ "$VERDICT" = PASS ]