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
GitHub aien-dev/omega-mv#213 (code only)
Apply it
git checkout -b patch-66d4b5a2add49335 f633e34309179cd2abd84552c8e7422bf345f010 curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/66d4b5a2add49335.patch | git am
Provenance
github-import 1
aien-dev/omega-mv
213
182b8a318f108cd750e229a0321921ef444c1ddc
{"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":213,"url":"https://github.com/aien-dev/omega-mv/pull/213","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:48Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/Makefile b/Makefile index 3309c768c..2d504bb12 100644 --- a/Makefile +++ b/Makefile @@ -177,6 +177,11 @@ test-chip-run: test-chip-run-trap-manifest: tests/test_chip_run_trap_manifest.sh +# Host-only check of the transcendental-gate manifest and its wrapper (fake chip, old-vs-new receipt keys). No GPU. +.PHONY: test-chip-run-transc-manifest +test-chip-run-transc-manifest: + tests/test_chip_run_transc_manifest.sh + # Gate 5 (OMEGA-NUMERIC-0), CPU tiers only: reference, CPU parity, provenance # and negative tests. Opens no device. The GB10 tier and the receipt come # from tests/run_numeric_gates.sh on the chip. Exits nonzero while any gate diff --git a/tests/chip_run_transc_receipt_allowlist.txt b/tests/chip_run_transc_receipt_allowlist.txt new file mode 100644 index 000000000..50a8d227c --- /dev/null +++ b/tests/chip_run_transc_receipt_allowlist.txt @@ -0,0 +1,7 @@ +# Receipt-key differences allowed between the old tools/run_numeric_transc_gate.sh receipt and the +# receipt of tools/run_numeric_transc_gate.sh + tools/manifests/numeric_transc.chiprun. +# One entry per line: "+key reason" (new receipt has a key the old one lacked) or +# "-key reason" (old key missing from the new receipt). Blank lines and # lines are ignored. +# tests/test_chip_run_transc_manifest.sh fails on a difference that is not listed here AND on a +# listed entry that is not a real difference. The manifest rebuilds the old object in the old +# key order, so the list is empty on purpose: no receipt field was added, removed or renamed. diff --git a/tests/test_chip_run.sh b/tests/test_chip_run.sh index 73249b907..2f16e808b 100755 --- a/tests/test_chip_run.sh +++ b/tests/test_chip_run.sh @@ -328,6 +328,74 @@ reset_world; echo other > "$FLAG"; exec 8> "$LOCK"; flock -x 8; CRMAN=$T/m-off.s expect optional_off 0 '^CHIP_RUN: PASS' assert optional_off "a flag we never raised is untouched" flag_is_other +# seam: RECEIPT_EXTRA_JQ can read the whole HOST_TIER_CMD output as $hostlog (empty without one) +mkman "$T/m-hostlog.sh" "HOST_TIER_CMD='echo AAA; echo BBB'; RECEIPT_EXTRA_JQ='. + {hl: \$hostlog}'" +reset_world; CRMAN=$T/m-hostlog.sh cr hostlog -- "${PD[@]}" +expect hostlog 0 '^CHIP_RUN: PASS' +assert hostlog "receipt carries the whole host tier output" jq -e '.hl == "AAA\nBBB\n" and .host_tier == "BBB"' "$T"/ev-hostlog/*.json +mkman "$T/m-hostlog0.sh" "HOST_TIER_CMD=''; RECEIPT_EXTRA_JQ='. + {hl: \$hostlog}'" +reset_world; CRMAN=$T/m-hostlog0.sh cr hostlog_none -- "${PD[@]}" +expect hostlog_none 0 '^CHIP_RUN: PASS' +assert hostlog_none "no host tier gives an empty \$hostlog" jq -e '.hl == ""' "$T"/ev-hostlog_none/*.json + +# seam: RECEIPT_EXTRA_JQ may replace a FAIL verdict with another upper-case word; PASS is never forged or removed +mkman "$T/m-vw.sh" "RECEIPT_EXTRA_JQ='.verdict = \"NOT_RUN\"'" +reset_world; CRMAN=$T/m-vw.sh cr verdict_word_ok FAKE_MODE=fail -- "${PD[@]}" +expect verdict_word_ok 1 '^CHIP_RUN: NOT_RUN last verdict line' +assert verdict_word_ok "receipt verdict is the rewritten word" receipt_verdict verdict_word_ok NOT_RUN +reset_world; CRMAN=$T/m-vw.sh cr verdict_pass_changed -- "${PD[@]}" +expect verdict_pass_changed 1 '^CHIP_RUN: FAIL RECEIPT_EXTRA_JQ changed a PASS verdict' +mkman "$T/m-vf.sh" "RECEIPT_EXTRA_JQ='.verdict = \"PASS\"'" +reset_world; CRMAN=$T/m-vf.sh cr verdict_forged FAKE_MODE=fail -- "${PD[@]}" +expect verdict_forged 1 '^CHIP_RUN: FAIL RECEIPT_EXTRA_JQ forged a PASS verdict' +mkman "$T/m-vb.sh" "RECEIPT_EXTRA_JQ='.verdict = \"not run\"'" +reset_world; CRMAN=$T/m-vb.sh cr verdict_word FAKE_MODE=fail -- "${PD[@]}" +expect verdict_word 1 '^CHIP_RUN: FAIL receipt verdict is not an upper-case word' + +# seam: ECHO_RE limits the stdout echo of the chip log; the log blob stays complete +mkman "$T/m-echo.sh" "ECHO_RE='^VERDICT'" +reset_world; CRMAN=$T/m-echo.sh cr echo_re -- "${PD[@]}" +expect echo_re 0 '^VERDICT PASS$' +assert echo_re "default-echoed noise line is not shown with ECHO_RE" bash -c '! grep -q "^fake chip args" "$1"' _ "$OUT" +assert echo_re "the log blob still holds the whole log" grep -q '^fake chip args' "$T"/ev-echo_re/blobs/*.log +reset_world; cr echo_default -- "${PD[@]}" +assert echo_default "without ECHO_RE the whole chip log is echoed" grep -q '^fake chip args' "$OUT" + +# seam: FINAL_LINE_STYLE=verdict prints "VERDICT <word>" last (old transc style), also for fatal errors +mkman "$T/m-fs.sh" "FINAL_LINE_STYLE=verdict; RECEIPT_EXTRA_JQ='.verdict = \"NOT_RUN\"'" +reset_world; CRMAN=$T/m-fs.sh cr final_style FAKE_MODE=fail -- "${PD[@]}" +expect final_style 1 '^VERDICT NOT_RUN$' +assert final_style "no CHIP_RUN: line in verdict style" bash -c '! grep -q "^CHIP_RUN:" "$1"' _ "$OUT" +assert final_style "the last line is the verdict line" test "$(tail -n 1 "$OUT")" = "VERDICT NOT_RUN" +mkman "$T/m-fs2.sh" "FINAL_LINE_STYLE=verdict" +reset_world; CRMAN=$T/m-fs2.sh cr final_style_pass -- "${PD[@]}" +expect final_style_pass 0 '^VERDICT PASS$' +mkman "$T/m-fs3.sh" "FINAL_LINE_STYLE=verdict; RECEIPT_EXTRA_JQ='.verdict = \"PASS\"'" +reset_world; CRMAN=$T/m-fs3.sh cr final_style_fatal FAKE_MODE=fail -- "${PD[@]}" +expect final_style_fatal 1 '^RECEIPT_EXTRA_JQ forged a PASS verdict$' +assert final_style_fatal "fatal ends with VERDICT FAIL" test "$(tail -n 1 "$OUT")" = "VERDICT FAIL" +assert fatal_verdict_style "fatal prints a VERDICT FAIL line and no CHIP_RUN: FAIL line" bash -c '[ "$(tail -n 2 "$1" | head -n 1)" = "RECEIPT_EXTRA_JQ forged a PASS verdict" ] && [ "$(tail -n 1 "$1")" = "VERDICT FAIL" ] && ! grep -q "^CHIP_RUN: FAIL" "$1"' _ "$OUT" +mkman "$T/m-fs4.sh" "FINAL_LINE_STYLE=bogus" +reset_world; CRMAN=$T/m-fs4.sh cr final_style_value -- "${PD[@]}" +expect final_style_value 1 '^CHIP_RUN: BAD_MANIFEST FINAL_LINE_STYLE=' + +# seam: GPU_LOCK_MODE=fuser refuses early on ANY open handle of the lock file (flock mode does not), then blocks on flock +mkman "$T/m-fu.sh" "GPU_LOCK_MODE=fuser" +reset_world; exec 8> "$LOCK"; CRMAN=$T/m-fu.sh cr gpu_fuser -- "${PD[@]}"; exec 8>&- +expect gpu_fuser 2 "^REFUSED: $LOCK is held\$" +assert gpu_fuser "refused before the host tier and the quiet flag" no_flag +reset_world; exec 8> "$LOCK"; cr gpu_fuser_ctl -- "${PD[@]}"; exec 8>&- +expect gpu_fuser_ctl 0 '^CHIP_RUN: PASS' +reset_world; CRMAN=$T/m-fu.sh cr gpu_fuser_free -- "${PD[@]}" +expect gpu_fuser_free 0 '^CHIP_RUN: PASS' +mkman "$T/m-fu2.sh" "GPU_LOCK_MODE=bogus" +reset_world; CRMAN=$T/m-fu2.sh cr gpu_mode_value -- "${PD[@]}" +expect gpu_mode_value 1 '^CHIP_RUN: BAD_MANIFEST GPU_LOCK_MODE=' +# regression (PR 213 review): a bad manifest value must stop the run (fail-open if bad_manifest is undefined), with no receipt and no shell error +assert bad_manifest_def "bad manifest exits nonzero, no 'command not found'" bash -c '! grep -q "command not found" "$1"' _ "$OUT" +assert final_style_value "bad manifest wrote no receipt" test -z "$(ls "$T"/ev-final_style_value/*.json 2>/dev/null)" +assert gpu_mode_value "bad GPU_LOCK_MODE wrote no receipt" test -z "$(ls "$T"/ev-gpu_mode_value/*.json 2>/dev/null)" + # happy path and receipt reset_world; cr happy -- "${PD[@]}" -- --x 1 expect happy 0 '^VERDICT PASS$' diff --git a/tests/test_chip_run_transc_manifest.sh b/tests/test_chip_run_transc_manifest.sh new file mode 100755 index 000000000..ad0cf464e --- /dev/null +++ b/tests/test_chip_run_transc_manifest.sh @@ -0,0 +1,243 @@ +#!/bin/bash +# Host-only check of tools/manifests/numeric_transc.chiprun and its wrapper +# tools/run_numeric_transc_gate.sh. No GPU, no chip sources, no real build: a fake omega and +# fake physics (git repos in a temp dir), a tiny fake chip binary and fake host tier, run through +# the real module via the CHIPRUN_SELFTEST seam (same method as tests/test_chip_run.sh). +# tests/test_chip_run_transc_manifest.sh +# Checks: (1) receipt keys and key order equal the old script's (pinned below; cross-checked with +# origin/main:tools/run_numeric_transc_gate.sh while main still has the old script); the sorted +# difference must be empty or listed in tests/chip_run_transc_receipt_allowlist.txt, and no stale +# allowlist entry may remain; (2) gcc source list equals the old script's; (3) refusal line and +# exit code for an unknown op and for a missing physics checkout; (4) verdicts, console lines, +# exit codes, receipt values, quiet flag, host tier refusal, fuser refusal. +# Each check is also run against a mutated manifest and must fail there. +set -u +HERE=$(cd -P "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) +MAN=$HERE/tools/manifests/numeric_transc.chiprun +ALLOW=$HERE/tests/chip_run_transc_receipt_allowlist.txt +T=$(mktemp -d); trap 'rm -rf "$T"' EXIT +FAILS=0 +ok() { echo "PASS $1"; } +bad() { echo "FAIL $1"; FAILS=$((FAILS + 1)); } +FAKE_PHYS=/nonexistent-physics-for-test + +# Pinned from the old script (origin/main before this change): receipt keys in order, gcc sources in order. +OLD_KEYS="gate row reference omega_commit omega_tree_clean_before omega_tree_clean_after omega_commit_unchanged_after physics_commit physics_lock_pin physics_tree_clean_before physics_tree_clean_after physics_commit_unchanged_after binary_sha256 chip_log_sha256 kernels nvdisasm_check host_tier ops_requested ops chip_exit_status started_utc finished_utc verdict" +OLD_SRCS="tests/test_omega_numeric_transc_gb10.c src/omega_numeric_divsqrt_gb10.c src/omega_numeric_transc.c src/omega_numeric.c src/omega_numeric_provenance.c src/omega_blackwell_encoder.c src/omega_blackwell_codegen.c src/omega_blackwell_matmul.c src/omega_blackwell_qmd.c src/sha256.c $FAKE_PHYS/nvrm/nvrm.c $FAKE_PHYS/m16/m16_native.c" + +# Cross-check of the pins against the old script, only while origin/main still has it. +OLDSH=$(git -C "$HERE" show origin/main:tools/run_numeric_transc_gate.sh 2>/dev/null) +if printf '%s\n' "$OLDSH" | grep -q 'flock -x 9'; then + printf '%s\n' "$OLDSH" | sed -n '/BODY=\$(jq -n/,/verdict: \$verdict }/p' | sed -E 's/\{op:[^}]*\}//g; s/"[^"]*"//g' | grep -oE '[a-z_0-9]+:' | tr -d ':' | tr '\n' ' ' | sed 's/ $//' > "$T/oldkeys" + [ "$(cat "$T/oldkeys")" = "$OLD_KEYS" ] && ok "0 pinned key list equals the old script's" || bad "0 pinned key list differs from the old script: $(cat "$T/oldkeys")" + printf '%s\n' "$OLDSH" | sed -n '/-o "\$BIN"/,/m16_native\.c/p' | grep -oE '(tests|src)/[A-Za-z0-9_]+\.c|\$PHYSICS/[a-z0-9/_]+\.c' | sed "s#\\\$PHYSICS#$FAKE_PHYS#" | tr '\n' ' ' | sed 's/ $//' > "$T/oldsrcs" + [ "$(cat "$T/oldsrcs")" = "$OLD_SRCS" ] && ok "0 pinned source list equals the old script's" || bad "0 pinned source list differs from the old script: $(cat "$T/oldsrcs")" +else + echo "NOTE 0 origin/main no longer has the old script; the pinned lists are the reference" +fi + +# ---------- fake world ---------- +cat > "$T/chip.c" <<'EOC' +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +int main(int argc, char **argv) { + const char *m = getenv("FAKE_MODE"); if (!m) m = "pass"; + const char *fl = getenv("FAKE_FLAG"); + printf("noise line before results\n"); + if (fl) { FILE *f = fopen(fl, "r"); char b[512] = ""; if (f) { if (!fgets(b, sizeof b, f)) b[0] = 0; fclose(f); } b[strcspn(b, "\n")] = 0; printf("noise flag=%s\n", b); } + const char *v = !strcmp(m, "fail") ? "FAIL" : (!strcmp(m, "notrun") || !strcmp(m, "notrun0")) ? "NOT_RUN" : "PASS"; + for (int i = 1; i < argc; i++) { + if (!strcmp(argv[i], "--chip")) continue; + printf("RESULT chip %s checked=%s exhaustive=%s mismatches=%s unwritten=0 verdict=%s\n", argv[i], + strcmp(v, "NOT_RUN") ? "4294967296" : "0", strcmp(v, "NOT_RUN") ? "true" : "false", strcmp(v, "FAIL") ? "0" : "7", v); + } + if (strcmp(m, "silent")) printf("VERDICT %s\n", v); + return (strcmp(m, "pass") && strcmp(m, "silent") && strcmp(m, "notrun0")) ? 1 : 0; +} +EOC +mkdir -p "$T/bin" "$T/tmp" "$T/home" +gcc -O0 -o "$T/bin/chip" "$T/chip.c" || { echo "FAIL setup: host gcc could not build the fake chip binary"; exit 1; } +FLAG=$T/flag; LOCK=$T/gpu.lock +g() { local d=$1; shift; git -C "$d" -c user.email=t@t -c user.name=t -c commit.gpgsign=false "$@"; } + +W=""; OM=""; PHYS=""; N=0 +build_world() { # MANIFEST + N=$((N + 1)); W=$T/w$N; OM=$W/omega; PHYS=$W/physics + mkdir -p "$PHYS/nvrm" "$OM/tools/manifests" "$W/tmp" + git init -q "$PHYS" && echo "/* fake */" > "$PHYS/nvrm/nvrm.c" && g "$PHYS" add -A && g "$PHYS" commit -q -m physics + git init -q "$OM" + cp "$HERE/tools/chip_run.sh" "$HERE/tools/run_numeric_transc_gate.sh" "$OM/tools/" + cp "$1" "$OM/tools/manifests/numeric_transc.chiprun" + git -C "$PHYS" rev-parse HEAD > "$OM/physics.lock" + echo "build/" > "$OM/.gitignore" + printf '#!/bin/sh\nif [ "$1" = --digest ]; then printf "EXP2 12 aaaa\\nLOG2 34 bbbb\\n"; exit ${FAKE_DIGEST_RC:-0}; fi\necho "[PASS] fake host check"; echo "FAKE_HOST_LAST"; exit ${FAKE_HOST_RC:-0}\n' > "$OM/tools/fakehost.sh" + printf '#!/bin/sh\necho "[PASS] fake nvd"\necho "nvdisasm fake provenance line"\necho "VERDICT PASS"\nexit ${FAKE_NVD_RC:-0}\n' > "$OM/tools/divsqrt_nvdisasm_check.sh" + printf 'build/test_omega_numeric_transc_gb10_cpu:\n\tmkdir -p build && cp tools/fakehost.sh $@ && chmod +x $@\n' > "$OM/Makefile" + chmod +x "$OM/tools/"*.sh "$OM/tools/run_numeric_transc_gate.sh" + g "$OM" add -A && g "$OM" commit -q -m omega + rm -f "$FLAG" +} +OUT=$T/out.txt; RC=0 +# runw NAME [ENV=VALUE ...] -- wrapper args +runw() { + local name=$1; RUNNAME=$name; shift; local extra=(); while [ "$1" != -- ]; do extra+=("$1"); shift; done; shift + rm -f "$FLAG"; g "$OM" clean -fdxq + ( cd "$T" && env -u PHYSICS PHYSICS_DIR="$PHYS" CHIPRUN_SELFTEST=1 CHIPRUN_PREBUILT_BIN="$T/bin/chip" CHIPRUN_QUIET_FLAG="$FLAG" \ + CHIPRUN_GPU_LOCK="$LOCK" CHIPRUN_EST_LOAD_CMD=true TMPDIR="$W/tmp" TRANSC_GB10_EVIDENCE_DIR="$W/ev-$name" FAKE_FLAG="$FLAG" \ + FAKE_MODE=pass "${extra[@]}" bash "$OM/tools/run_numeric_transc_gate.sh" "$@" ) > "$OUT" 2>&1 + RC=$? + R=$(ls "$W"/ev-"$name"/*.json 2>/dev/null | head -1) +} + +# ck_diag: after a failing check, show the first 15 lines of the last run's console, once per run name +# (RUNNAME is set by runw and by the two inline runs). Lines start with " | " so they never +# match the "^PASS" / "^FAIL" greps below. It does not change what counts as a pass. +ck_diag() { [ "${DIAG_NAME:-}" = "${RUNNAME:-}" ] && return 0; DIAG_NAME=${RUNNAME:-}; head -n 15 "$OUT" 2>/dev/null | sed 's/^/ | /'; return 0; } + +# suite MANIFEST: every world-based check; prints "PASS id" / "FAIL id" lines. +suite() { + local man=$1 id k; RUNNAME=""; DIAG_NAME="" + build_world "$man" + ck() { id=$1; shift; if "$@"; then echo "PASS $id"; else echo "FAIL $id"; ck_diag; fi; } + last_is() { [ "$(tail -n 1 "$OUT")" = "$1" ]; } + has() { grep -Eq -- "$1" "$OUT"; } + lacks() { ! grep -Eq -- "$1" "$OUT"; } + rj() { [ -n "${R:-}" ] && jq -e "$1" "$R" > /dev/null 2>&1; } + + # happy path, default ops through the wrapper + runw happy -- ; HAPPY_R=$R + ck happy_exit test "$RC" = 0 + ck happy_last_line last_is "VERDICT PASS" + ck happy_results_echoed test "$(grep -c '^RESULT chip ' "$OUT")" = 4 + ck happy_noise_not_echoed lacks '^noise' + ck happy_receipt_line has '^RECEIPT /.*\.json$' + ck happy_no_chiprun_line lacks '^CHIP_RUN:' + ck happy_default_ops rj '.ops_requested == ["EXP2","LOG2","SIGMOID","TANH"] and (.ops | map(.op)) == ["EXP2","LOG2","SIGMOID","TANH"]' + ck happy_ops_typed rj '.ops[0] == {op:"EXP2",checked:4294967296,exhaustive:true,mismatches:0,unwritten:0,verdict:"PASS"}' + ck happy_kernels rj '.kernels == [{op:"EXP2",instructions:12,sha256:"aaaa"},{op:"LOG2",instructions:34,sha256:"bbbb"}]' + ck happy_nvd rj '.nvdisasm_check == "nvdisasm fake provenance line"' + ck happy_host_tier rj '.host_tier == "FAKE_HOST_LAST"' + ck happy_gate_fields rj '.gate == "E1-TRANSC-GB10" and .verdict == "PASS" and .chip_exit_status == 0 and (.row | startswith("E1 gap table row 10")) and (.reference | startswith("omega_math_<op>"))' + ck happy_flag_dropped test ! -e "$FLAG" + ck happy_flag_owner grep -q 'flag=lane2 E1 transcendental GB10 chip run start=' "$W"/ev-happy/blobs/*.log + ck happy_mode_0444 test "$(stat -c %a "$R" 2>/dev/null)" = 444 + # (1) receipt keys, ordered, equal the old script's + jq -r 'keys_unsorted | join(" ")' "$HAPPY_R" > "$W/newkeys" 2>/dev/null + ck keys_ordered test "$(cat "$W/newkeys")" = "$OLD_KEYS" + # (1b) sorted difference against the allowlist, both directions + tr ' ' '\n' <<< "$OLD_KEYS" | sort > "$W/ko"; tr ' ' '\n' < "$W/newkeys" | sed '/^$/d' | sort > "$W/kn" + { comm -13 "$W/ko" "$W/kn" | sed 's/^/+/'; comm -23 "$W/ko" "$W/kn" | sed 's/^/-/'; } | sort > "$W/diff" + grep -E '^[+-][a-z_0-9]+ ' "$ALLOW" | cut -d' ' -f1 | sort > "$W/allowed" + ck keys_allowlist cmp -s "$W/diff" "$W/allowed" + + # other verdicts: exit code, console, receipt verdict + runw notrun FAKE_MODE=notrun -- EXP2 + ck notrun_exit test "$RC" = 1 + ck notrun_last_line last_is "VERDICT NOT_RUN" + ck notrun_receipt rj '.verdict == "NOT_RUN" and .ops[0].exhaustive == false and .ops_requested == ["EXP2"]' + runw fail FAKE_MODE=fail -- LOG2 TANH + ck fail_exit test "$RC" = 1 + ck fail_last_line last_is "VERDICT FAIL" + ck fail_receipt rj '.verdict == "FAIL" and .ops[0].mismatches == 7 and .ops_requested == ["LOG2","TANH"]' + runw silent FAKE_MODE=silent -- EXP2 + ck silent_exit test "$RC" = 1 + ck silent_last_line last_is "VERDICT NOT_RUN" + ck silent_receipt rj '.verdict == "NOT_RUN" and .chip_exit_status == 0' + runw notrun0 FAKE_MODE=notrun0 -- EXP2 + ck notrun0_exit test "$RC" = 1 + ck notrun0_last_line last_is "VERDICT NOT_RUN" + ck notrun0_receipt rj '.verdict == "NOT_RUN" and .chip_exit_status == 0' + runw passrc FAKE_MODE=passrc -- EXP2 + ck passrc_exit test "$RC" = 1 + ck passrc_last_line last_is "VERDICT FAIL" + ck passrc_receipt rj '.verdict == "FAIL" and .chip_exit_status == 1' + + # (3) refusals: exit 1 and VERDICT NOT_RUN + runw badop -- EXP2 NOPE + ck badop_refusal test "$RC" = 1 -a "$(cat "$OUT")" = "$(printf 'REFUSED: unknown op NOPE\nVERDICT NOT_RUN')" + ck badop_nothing_written test -z "$(ls "$W"/ev-badop 2>/dev/null)" -a ! -e "$FLAG" + runw nophys PHYSICS_DIR="$T/nonexistent" -- EXP2 + ck nophys_refusal test "$RC" = 1 + ck nophys_lines test "$(sed -n 1p "$OUT")" = "REFUSED: no physics checkout at $T/nonexistent" -a "$(tail -n 1 "$OUT")" = "VERDICT NOT_RUN" + runw defphys HOME="$T/home" PHYSICS_DIR= -- EXP2 + ck default_physics_dir has 'REFUSED: no physics checkout at .*/home/workspace/hive-worktrees/physics-gate14-e95e3ed$' + runw hostfail FAKE_HOST_RC=1 -- EXP2 + ck hostfail_refusal test "$RC" = 1 -a "$(tail -n 1 "$OUT")" = "VERDICT NOT_RUN" + ck hostfail_text has '^REFUSED: host tier failed' + ck hostfail_no_chip lacks '^== chip run' + ck hostfail_no_flag test ! -e "$FLAG" + runw nvdfail FAKE_NVD_RC=1 -- EXP2 + ck nvdfail_refusal test "$RC" = 1 -a "$(tail -n 1 "$OUT")" = "VERDICT NOT_RUN" + ck nvdfail_no_chip lacks '^== chip run' + ck nvdfail_text has '^host tier \(0\) or nvdisasm check \(1\) failed$' + runw digfail FAKE_DIGEST_RC=1 -- EXP2 + ck digfail_refusal test "$RC" = 1 -a "$(tail -n 1 "$OUT")" = "VERDICT NOT_RUN" + ck digfail_no_chip lacks '^== chip run' + ck digfail_text has '^kernel digest failed$' + # fuser: any open handle on the lock file refuses, even without flock + exec 8> "$LOCK"; runw fuser -- EXP2; exec 8>&- + ck fuser_refusal test "$RC" = 1 -a "$(tail -n 1 "$OUT")" = "VERDICT NOT_RUN" + ck fuser_text has "^REFUSED: $LOCK is held\$" + ck fuser_no_host_tier lacks '^== host tier' + # dirty omega + echo x > "$OM/junk"; rm -f "$FLAG"; RUNNAME=dirty + ( cd "$T" && env -u PHYSICS PHYSICS_DIR="$PHYS" CHIPRUN_SELFTEST=1 CHIPRUN_PREBUILT_BIN="$T/bin/chip" CHIPRUN_QUIET_FLAG="$FLAG" CHIPRUN_GPU_LOCK="$LOCK" \ + CHIPRUN_EST_LOAD_CMD=true TMPDIR="$W/tmp" TRANSC_GB10_EVIDENCE_DIR="$W/ev-dirty" bash "$OM/tools/run_numeric_transc_gate.sh" EXP2 ) > "$OUT" 2>&1; RC=$? + rm -f "$OM/junk" + ck dirty_refusal test "$RC" = 1 -a "$(sed -n 1p "$OUT")" = "REFUSED: omega tree $OM is dirty" -a "$(tail -n 1 "$OUT")" = "VERDICT NOT_RUN" + # quiet flag up + echo other > "$FLAG"; RUNNAME=flagup + ( cd "$T" && env -u PHYSICS PHYSICS_DIR="$PHYS" CHIPRUN_SELFTEST=1 CHIPRUN_PREBUILT_BIN="$T/bin/chip" CHIPRUN_QUIET_FLAG="$FLAG" CHIPRUN_GPU_LOCK="$LOCK" \ + CHIPRUN_EST_LOAD_CMD=true TMPDIR="$W/tmp" TRANSC_GB10_EVIDENCE_DIR="$W/ev-flagup" bash "$OM/tools/run_numeric_transc_gate.sh" EXP2 ) > "$OUT" 2>&1; RC=$? + ck flagup_refusal test "$RC" = 1 -a "$(sed -n 1p "$OUT")" = "REFUSED: quiet flag is up: other" -a "$(tail -n 1 "$OUT")" = "VERDICT NOT_RUN" + ck flagup_left_alone test "$(cat "$FLAG")" = other + rm -f "$FLAG" +} + +# (2) gcc source list +load_list() { ( PHYSICS=$FAKE_PHYS; . "$1" 2>/dev/null || exit 1; read -ra A <<< "$TEST_SOURCE $SOURCES $EXTRA_BUILD_SOURCES"; echo "${A[*]}" ); } + +suite "$MAN" > "$T/suite.out" +cat "$T/suite.out"; grep -c '^FAIL' "$T/suite.out" > "$T/nfail"; FAILS=$((FAILS + $(cat "$T/nfail"))) +[ "$(grep -c '^PASS' "$T/suite.out")" -ge 45 ] || bad "suite ran fewer than 45 checks" +[ "$(load_list "$MAN")" = "$OLD_SRCS" ] && ok "2 source list identical to old script" || bad "2 source list: $(load_list "$MAN")" + +# every file the manifest names exists in the real tree +( PHYSICS=$FAKE_PHYS; . "$MAN"; for s in $TEST_SOURCE $SOURCES; do [ -f "$HERE/$s" ] || { echo "missing $s"; exit 1; }; done ) && ok "2b sources exist" || bad "2b a named source is missing" + +# ---------- mutants: each manifest or wrapper change must make a named check fail ---------- +mutant() { # NAME SED-EXPR EXPECTED-FAILING-ID + local name=$1 expr=$2 want=$3 + sed "$expr" "$MAN" > "$T/m_$name" + cmp -s "$T/m_$name" "$MAN" && { bad "mutant $name changed nothing"; return; } + suite "$T/m_$name" > "$T/m_$name.out" 2>&1 + grep -q "^FAIL $want\$" "$T/m_$name.out" && ok "mutant $name fails $want" || bad "mutant $name did not fail $want" +} +mutant nokernels 's/^ kernels:/ kernels_x:/' keys_ordered +mutant renamekey 's/^ nvdisasm_check: / zz_nvdisasm_check: /' keys_ordered +mutant extrakey 's/^ gate: \$r.gate,/ gate: $r.gate, owner: $r.owner,/' keys_allowlist +mutant dropkey '/^ row: /d' keys_allowlist +mutant verdictword 's/elif \$cw == "" then "NOT_RUN"/elif $cw == "" then "FAIL"/' silent_receipt +mutant failword 's/elif \$cw == "PASS" then "FAIL"/elif $cw == "PASS" then "PASS"/' passrc_receipt +mutant refuseexit 's/^REFUSE_EXIT=1/REFUSE_EXIT=2/' nophys_refusal +mutant refuseline "s/^REFUSE_VERDICT_LINE=.*/REFUSE_VERDICT_LINE='CHIP_RUN: NOT_RUN'/" nophys_lines +mutant style 's/^FINAL_LINE_STYLE=verdict/FINAL_LINE_STYLE=chip_run/' happy_last_line +mutant echore '/^ECHO_RE=/d' happy_noise_not_echoed +mutant nofuser 's/^GPU_LOCK_MODE=fuser/GPU_LOCK_MODE=flock/' fuser_refusal +mutant noquiet 's/^RAISE_QUIET=1/RAISE_QUIET=0/' happy_flag_owner +mutant owner 's/^OWNER="lane2 E1 transcendental GB10 chip run"/OWNER="other owner"/' happy_flag_owner +mutant gate 's/^GATE=E1-TRANSC-GB10/GATE=E1-TRANSC/' happy_gate_fields +mutant nohost "/^HOST_TIER_CMD=/,/^'\$/c\\HOST_TIER_CMD=true" hostfail_refusal +mutant dirtyok 's/^REFUSE_DIRTY_OMEGA=1/REFUSE_DIRTY_OMEGA=0/' dirty_refusal +mutant nonvd 's#^tools/divsqrt_nvdisasm_check.sh > #true > #' nvdfail_refusal +mutant nokdig 's#^build/test_omega_numeric_transc_gb10_cpu --digest > .*#true#' happy_kernels +mutant nokdigcheck 's#^build/test_omega_numeric_transc_gb10_cpu --digest > \(.*\) || { echo "kernel digest failed"; exit 1; }$#build/test_omega_numeric_transc_gb10_cpu --digest > \1#' digfail_refusal +mutant pass_loose "s/^PASS_LINE=.*/PASS_LINE='^VERDICT'/" notrun0_receipt +sed 's#^SOURCES="src/omega_numeric_divsqrt_gb10.c #SOURCES="#' "$MAN" > "$T/m_dropsrc" +sed 's#src/sha256.c#src/sha256_nope.c#' "$MAN" > "$T/m_badfile" +for m in m_dropsrc m_badfile; do [ "$(load_list "$T/$m")" = "$OLD_SRCS" ] && bad "mutant $m passed check 2" || ok "mutant $m fails check 2"; done +( PHYSICS=$FAKE_PHYS; . "$T/m_badfile"; for s in $TEST_SOURCE $SOURCES; do [ -f "$HERE/$s" ] || exit 1; done ) && bad "mutant badfile passed 2b" || ok "mutant badfile fails 2b" + +[ "$FAILS" = 0 ] && { echo "CHIP_RUN_TRANSC_MANIFEST: PASS"; exit 0; } +echo "CHIP_RUN_TRANSC_MANIFEST: FAIL ($FAILS)"; exit 1 diff --git a/tools/chip_run.sh b/tools/chip_run.sh index 7f3aa9f67..0fa93a35a 100755 --- a/tools/chip_run.sh +++ b/tools/chip_run.sh @@ -11,8 +11,13 @@ # VERDICT_RE must also match PASS_LINE, so set VERDICT_RE to verdict lines only), CHILD_EXIT_PASSTHROUGH # (default 0; 0 or 1; when 1 and the binary exited nonzero, this module exits with the binary's # exit code, receipt and verdict still written; exit 0 with a non-PASS verdict still gives 1), hooks -# HOST_TIER_CMD (run first; nonzero refuses) and RECEIPT_EXTRA_JQ (jq filter on the receipt, -# $log = chip log). The manifest cannot change the test seam variables below, QUIET_FLAG, +# GPU_LOCK_MODE (default flock = flock -n after the host tier; fuser = refuse early, before the host tier, if ANY process has +# the lock file open (old transc test, text "<lock> is held"), then take it with a blocking flock -x), +# FINAL_LINE_STYLE (default chip_run: last line "CHIP_RUN: <verdict> [reason]", fatal errors "CHIP_RUN: FAIL why"; verdict: last line +# "VERDICT <verdict>", fatal errors print "why" then "VERDICT FAIL"), ECHO_RE (default empty = echo the whole chip log; else echo only lines matching it; the chip log blob and +# the verdict are unaffected), HOST_TIER_CMD (run first; nonzero refuses) and RECEIPT_EXTRA_JQ (jq filter on the receipt, +# $log = chip log, $hostlog = the whole HOST_TIER_CMD output, empty if none; it may replace a FAIL +# verdict with another upper-case word such as NOT_RUN, never create or remove a PASS). The manifest cannot change the test seam variables below, QUIET_FLAG, # GPU_LOCK or EST_LOAD_CMD (checked and restored after it is sourced). That is an accident guard, # not a boundary: the manifest is sourced into this shell and could still set any other variable. # Gate args after "--" REPLACE the manifest RUN_ARGS (not appended); RUN_ARGS is split on whitespace. @@ -46,10 +51,8 @@ # run_args host_tier verdict_lines chip_exit_status started_utc finished_utc verdict reason # (plus whatever RECEIPT_EXTRA_JQ adds). # NOT COVERED by this module (a gate that needs one adds it, or does not use this module yet): -# - transc's KDIG kernel-digest field and its unknown-op check: use RECEIPT_EXTRA_JQ. -# - transc's nvdisasm check: use HOST_TIER_CMD. -# - transc locks with fuser (refuses if ANY process holds the lock file); this module uses -# flock -n (refuses only if another flock holder has it). Not the same test. +# - transc's kernel-digest field and unknown-op check: RECEIPT_EXTRA_JQ over $hostlog, and the wrapper; its nvdisasm check: HOST_TIER_CMD. +# - transc locks with fuser; set GPU_LOCK_MODE=fuser for that (default flock -n is the other test). # - reduce WAITS for the lock and the quiet flag; this module REFUSES at once. # - binary blob storage: reduce stores blobs/<sha>.bin and refuses a PASS with no digests; # this module stores only the log blob, and records binary_sha256 without keeping the binary. @@ -74,8 +77,9 @@ EST_LOAD_CMD=${CHIPRUN_EST_LOAD_CMD:-pgrep est_load} FLAG_MINE=0; FLAG_TEXT=""; FAIL_REASON="" REFUSE_EXIT=2; REFUSE_VERDICT_LINE="CHIP_RUN: NOT_RUN" refuse() { echo "REFUSED: $*"; echo "$REFUSE_VERDICT_LINE"; exit "$REFUSE_EXIT"; } -bad_manifest() { echo "CHIP_RUN: BAD_MANIFEST $*"; exit 1; } -fatal() { echo "CHIP_RUN: FAIL $*"; exit 1; } +bad_manifest() { echo "CHIP_RUN: BAD_MANIFEST $*"; exit 1; } # REFUSAL:bad_manifest_def +FINAL_LINE_STYLE=chip_run # manifest may set "verdict": the last line is "VERDICT <word>" (old transc style) +fatal() { if [ "$FINAL_LINE_STYLE" = verdict ]; then echo "$*"; echo "VERDICT FAIL"; else echo "CHIP_RUN: FAIL $*"; fi; exit 1; } # REFUSAL:fatal_verdict_style fail() { FAIL_REASON=${FAIL_REASON:-$*}; } cleanup() { [ "$FLAG_MINE" = 1 ] || return 0 @@ -119,7 +123,7 @@ PHYSICS=${PHYS_FLAG:-${PHYSICS_DIR:-${PHYSICS:-$HOME/workspace/physics}}} PHYSICS=$(realpath -m "$PHYSICS") GATE=""; TEST_SOURCE=""; SOURCES=""; EXTRA_BUILD_SOURCES=""; RUN_ARGS=""; VERDICT_RE=""; PASS_LINE="" -OWNER=""; EVIDENCE_DIR=""; RAISE_QUIET=1; TAKE_GPU_LOCK=1; REFUSE_DIRTY_OMEGA=1; HOST_TIER_CMD=""; RECEIPT_EXTRA_JQ=""; REQUIRE_ALL_PASS=0; CHILD_EXIT_PASSTHROUGH=0 +OWNER=""; EVIDENCE_DIR=""; RAISE_QUIET=1; TAKE_GPU_LOCK=1; REFUSE_DIRTY_OMEGA=1; HOST_TIER_CMD=""; RECEIPT_EXTRA_JQ=""; REQUIRE_ALL_PASS=0; CHILD_EXIT_PASSTHROUGH=0; ECHO_RE=""; GPU_LOCK_MODE=flock [ -f "$MANIFEST" ] || refuse "no manifest at $MANIFEST" # REFUSAL:no_manifest . "$MANIFEST"; MRC=$? REX_BAD="" @@ -127,6 +131,8 @@ case $REFUSE_EXIT in ''|*[!0-9]*) REX_BAD=1 ;; *) { [ "${#REFUSE_EXIT}" -le 3 ] [ -z "$REX_BAD" ] || bad_manifest "REFUSE_EXIT=$REFUSE_EXIT is not an integer from 1 to 125" # REFUSAL:refuse_exit case $REQUIRE_ALL_PASS in 0|1) ;; *) bad_manifest "REQUIRE_ALL_PASS=$REQUIRE_ALL_PASS is not 0 or 1" ;; esac # REFUSAL:require_all_value case $CHILD_EXIT_PASSTHROUGH in 0|1) ;; *) bad_manifest "CHILD_EXIT_PASSTHROUGH=$CHILD_EXIT_PASSTHROUGH is not 0 or 1" ;; esac # REFUSAL:child_exit_value +case $FINAL_LINE_STYLE in chip_run|verdict) ;; *) bad_manifest "FINAL_LINE_STYLE=$FINAL_LINE_STYLE is not chip_run or verdict" ;; esac # REFUSAL:final_style_value +case $GPU_LOCK_MODE in flock|fuser) ;; *) bad_manifest "GPU_LOCK_MODE=$GPU_LOCK_MODE is not flock or fuser" ;; esac # REFUSAL:gpu_mode_value seam_check # REFUSAL:seam_after for v in "${SEAM_VARS[@]}"; do [ "${!v:-}" = "${SEAM0[$v]}" ] || refuse "manifest changed $v, a test seam variable"; done # REFUSAL:seam_changed QUIET_FLAG=$QUIET0; GPU_LOCK=$GPU0; EST_LOAD_CMD=$EST0 # REFUSAL:restore_vars @@ -150,6 +156,7 @@ PHYS_COMMIT=$(head_of "$PHYSICS") || refuse "cannot read physics HEAD at $PHYSIC OMEGA_CLEAN_BEFORE=$(clean "$HERE"); PHYS_CLEAN_BEFORE=true [ "$RAISE_QUIET" != 1 ] || [ ! -e "$QUIET_FLAG" ] || refuse "quiet flag is up: $(cat "$QUIET_FLAG")" # REFUSAL:quiet_flag [ -z "$(bash -c "$EST_LOAD_CMD" 2>/dev/null)" ] || refuse "an est_load process is running" # REFUSAL:est_load +[ "$TAKE_GPU_LOCK" != 1 ] || [ "$GPU_LOCK_MODE" != fuser ] || ! fuser "$GPU_LOCK" > /dev/null 2>&1 || refuse "$GPU_LOCK is held" # REFUSAL:gpu_fuser RUN=$(mktemp -d "${TMPDIR:-/tmp}/chip-run.XXXXXX") || refuse "cannot create a run directory" # REFUSAL:mktemp if [ -n "$HOST_TIER_CMD" ]; then @@ -157,6 +164,7 @@ if [ -n "$HOST_TIER_CMD" ]; then tail -n 3 "$RUN/host.log" [ "$HRC" = 0 ] || refuse "host tier failed (exit $HRC); no chip run" # REFUSAL:host_tier fi +[ -e "$RUN/host.log" ] || : > "$RUN/host.log" # seam: $hostlog is always readable by RECEIPT_EXTRA_JQ HOST_TIER=$(tail -n 1 "$RUN/host.log" 2>/dev/null) START=$(date -u +%Y-%m-%dT%H:%M:%SZ) @@ -170,7 +178,8 @@ fi if [ "$TAKE_GPU_LOCK" = 1 ]; then { : >> "$GPU_LOCK"; } 2>/dev/null || refuse "cannot open $GPU_LOCK" # REFUSAL:gpu_open exec 9>> "$GPU_LOCK" - flock -n 9 || refuse "GPU lock $GPU_LOCK is held" # REFUSAL:gpu_lock + [ "$GPU_LOCK_MODE" != fuser ] || flock -x 9 || refuse "cannot take $GPU_LOCK" # fuser mode: the early fuser check refused any holder, now wait for the lock like the old transc script + [ "$GPU_LOCK_MODE" = fuser ] || flock -n 9 || refuse "GPU lock $GPU_LOCK is held" # REFUSAL:gpu_lock fi if [ -n "${CHIPRUN_PREBUILT_BIN:-}" ]; then @@ -199,7 +208,7 @@ echo "== chip run (not killed, not timed out): ${GATE_ARGS[*]}" END=$(date -u +%Y-%m-%dT%H:%M:%SZ) exec 9>&- mapfile -t VLINES < <(grep -E -- "$VERDICT_RE" "$RUN/chip.log") -cat "$RUN/chip.log" # the full chip log goes to stdout, as the old trap script did (HIT and DEVERR lines included) +if [ -n "$ECHO_RE" ]; then grep -E -- "$ECHO_RE" "$RUN/chip.log"; else cat "$RUN/chip.log"; fi # default: the full chip log goes to stdout (HIT and DEVERR lines included); seam: ECHO_RE limits the echo OMEGA_CLEAN_AFTER=$(clean "$HERE"); PHYS_CLEAN_AFTER=$(clean "$PHYSICS") OMEGA_SAME=$([ "$(head_of "$HERE")" = "$OMEGA_COMMIT" ] && echo true || echo false) @@ -233,15 +242,20 @@ BODY=$(jq -n --arg gate "$GATE" --arg owner "$OWNER" --arg omega "$OMEGA_COMMIT" physics_tree_clean_after: $pafter, physics_commit_unchanged_after: $psame, binary_sha256: $bin, chip_log_sha256: $log, run_args: $run_args, host_tier: $host, verdict_lines: $vlines, chip_exit_status: $rc, started_utc: $start, finished_utc: $end, verdict: $verdict, reason: $reason }') || fatal "receipt JSON could not be built" -if [ -n "$RECEIPT_EXTRA_JQ" ]; then BODY=$(printf '%s' "$BODY" | jq --rawfile log "$RUN/chip.log" "$RECEIPT_EXTRA_JQ") || fatal "RECEIPT_EXTRA_JQ failed"; fi +if [ -n "$RECEIPT_EXTRA_JQ" ]; then BODY=$(printf '%s' "$BODY" | jq --rawfile log "$RUN/chip.log" --rawfile hostlog "$RUN/host.log" "$RECEIPT_EXTRA_JQ") || fatal "RECEIPT_EXTRA_JQ failed"; fi printf '%s\n' "$BODY" > "$RUN/receipt.json" jq -e '.gate and .verdict and .binary_sha256' "$RUN/receipt.json" > /dev/null || fatal "receipt lost its required fields" +RVERDICT=$(jq -r ".verdict | strings" "$RUN/receipt.json" 2>/dev/null) +case $RVERDICT in ""|*[!A-Z_]*) fatal "receipt verdict is not an upper-case word" ;; esac # REFUSAL:verdict_word +[ "$VERDICT" != PASS ] || [ "$RVERDICT" = PASS ] || fatal "RECEIPT_EXTRA_JQ changed a PASS verdict" # REFUSAL:verdict_pass_changed +[ "$VERDICT" = PASS ] || [ "$RVERDICT" != PASS ] || fatal "RECEIPT_EXTRA_JQ forged a PASS verdict" # REFUSAL:verdict_forged +VERDICT=$RVERDICT # seam: RECEIPT_EXTRA_JQ may replace a FAIL with another non-PASS word (for example NOT_RUN); PASS cannot be forged RSHA=$(sha "$RUN/receipt.json"); OUT=$EVID/$RSHA.json if [ ! -e "$OUT" ]; then set -o noclobber; { cat "$RUN/receipt.json" > "$OUT" && chmod 0444 "$OUT"; } || { set +o noclobber; fatal "could not write receipt $OUT"; }; set +o noclobber fi cmp -s "$RUN/receipt.json" "$OUT" || fatal "receipt $OUT does not match what was built" echo "RECEIPT $OUT" -echo "CHIP_RUN: $VERDICT${FAIL_REASON:+ $FAIL_REASON}" +if [ "$FINAL_LINE_STYLE" = verdict ]; then echo "VERDICT $VERDICT"; else echo "CHIP_RUN: $VERDICT${FAIL_REASON:+ $FAIL_REASON}"; fi # REFUSAL:final_style [ "$CHILD_EXIT_PASSTHROUGH" = 1 ] && [ "$CHIP_RC" != 0 ] && exit "$CHIP_RC" # REFUSAL:child_exit_passthrough [ "$VERDICT" = PASS ] diff --git a/tools/manifests/numeric_transc.chiprun b/tools/manifests/numeric_transc.chiprun new file mode 100644 index 000000000..bef926dca --- /dev/null +++ b/tools/manifests/numeric_transc.chiprun @@ -0,0 +1,89 @@ +# Manifest for tools/chip_run.sh: E1 row 10, GB10 transcendentals (EXP2 LOG2 SIGMOID TANH), +# every 2^32 input compared bit for bit with the CPU tier. Sourced as shell by chip_run.sh, +# which provides $HERE (omega root) and $PHYSICS. Forge queue only. +# Converted from the old tools/run_numeric_transc_gate.sh (origin/main) without changing what +# the gate measures: same sources, same gcc flags (the module's), same chip args, same verdict +# words, same receipt fields in the same order. The old-versus-new differences are listed in +# the PR and pinned by tests/test_chip_run_transc_manifest.sh. +# Verdict semantics, from tests/test_omega_numeric_transc_gb10.c: +# one "RESULT chip <op> checked=.. exhaustive=.. mismatches=.. unwritten=.. verdict=.." per op, +# then "VERDICT PASS|FAIL|NOT_RUN" (line 223); exit 1 unless PASS. +GATE=E1-TRANSC-GB10 +OWNER="lane2 E1 transcendental GB10 chip run" +TEST_SOURCE="tests/test_omega_numeric_transc_gb10.c" +SOURCES="src/omega_numeric_divsqrt_gb10.c src/omega_numeric_transc.c src/omega_numeric.c src/omega_numeric_provenance.c src/omega_blackwell_encoder.c src/omega_blackwell_codegen.c src/omega_blackwell_matmul.c src/omega_blackwell_qmd.c src/sha256.c" +EXTRA_BUILD_SOURCES="$PHYSICS/nvrm/nvrm.c $PHYSICS/m16/m16_native.c" +# The wrapper passes "--chip OP..." itself; this is the old default for direct use. +RUN_ARGS="--chip EXP2 LOG2 SIGMOID TANH" +# Old verdict: the last "VERDICT <word>" line of the chip log. RESULT lines come before it. +VERDICT_RE='^RESULT|^VERDICT' +PASS_LINE='^VERDICT PASS([^A-Z_]|$)' +EVIDENCE_DIR=${TRANSC_GB10_EVIDENCE_DIR:-$HOME/workspace/evidence-out/E1-TRANSC-GB10} +# Old refusals: exit 1 and "VERDICT NOT_RUN". Old console: RESULT and VERDICT lines of the chip +# log, then RECEIPT and a final "VERDICT <word>" line. Old exit: 0 PASS, else 1. +REFUSE_EXIT=1 +REFUSE_VERDICT_LINE='VERDICT NOT_RUN' +ECHO_RE='^RESULT|^VERDICT' +FINAL_LINE_STYLE=verdict +CHILD_EXIT_PASSTHROUGH=0 +# Old script: dirty omega refused, quiet flag raised for the run (owner string above), GPU lock +# taken, refusal on ANY process holding the lock file (fuser), then a blocking flock. +REFUSE_DIRTY_OMEGA=1 +RAISE_QUIET=1 +TAKE_GPU_LOCK=1 +GPU_LOCK_MODE=fuser +REQUIRE_ALL_PASS=0 +# Host tier, in the old order's spirit: host build, offline nvdisasm provenance check (all +# whole-program kernels), kernel digest, then the host run LAST so the receipt's host_tier +# (the module records the last line of this output) is the host run's last line, as before. +# Lines tagged HOSTTIER_NVD: and HOSTTIER_KDIG: are read back by RECEIPT_EXTRA_JQ via $hostlog. +HOST_TIER_CMD=' +echo "== host tier" +make -s -C . build/test_omega_numeric_transc_gb10_cpu > "$CHIPRUN_RUN_DIR/host-build.log" 2>&1 || { echo "host build failed"; exit 1; } +echo "== nvdisasm provenance" +tools/divsqrt_nvdisasm_check.sh > "$CHIPRUN_RUN_DIR/nvdisasm.log" 2>&1; NVD_RC=$? +grep -E "^\[|^VERDICT|^nvdisasm" "$CHIPRUN_RUN_DIR/nvdisasm.log" +grep "^nvdisasm" "$CHIPRUN_RUN_DIR/nvdisasm.log" | sed "s/^/HOSTTIER_NVD:/" +build/test_omega_numeric_transc_gb10_cpu --digest > "$CHIPRUN_RUN_DIR/kdig.txt" || { echo "kernel digest failed"; exit 1; } +sed "s/^/HOSTTIER_KDIG:/" "$CHIPRUN_RUN_DIR/kdig.txt" +build/test_omega_numeric_transc_gb10_cpu; HOST_RC=$? +[ "$HOST_RC" = 0 ] && [ "$NVD_RC" = 0 ] || { echo "host tier ($HOST_RC) or nvdisasm check ($NVD_RC) failed"; exit 1; } +' +# Receipt: the old object, same fields in the same order. The module's own owner, run_args, +# verdict_lines and reason are dropped (the old receipt had none); row, reference, kernels, +# nvdisasm_check, ops_requested and ops are rebuilt from the chip log and the host tier output. +# verdict: the chip's own last word (PASS, FAIL or NOT_RUN; none = NOT_RUN); a PASS the module +# does not confirm (nonzero exit, dirty tree, moved HEAD) becomes FAIL, as in the old script. +RECEIPT_EXTRA_JQ=' +def tagged($t): $hostlog | split("\n") | map(select(startswith($t)) | .[($t | length):]); +def chipword: ([$log | split("\n")[] | capture("^VERDICT (?<w>[A-Z_]*)") | .w] | last) // ""; +def typed($v): if $v == "true" then true elif $v == "false" then false elif ($v | test("^[0-9]")) then ($v | tonumber) else $v end; +def opsjson: try ([$log | split("\n")[] | select(startswith("RESULT chip ")) | split(" ") | map(select(length > 0)) as $f + | reduce $f[3:][] as $kv ({op: $f[2]}; ($kv | split("=")) as $p | . + {($p[0]): typed(if ($p | length) > 1 then ($p[1:] | join("=")) else $kv end)})]) catch []; +. as $r | (chipword) as $cw +| { + gate: $r.gate, + row: "E1 gap table row 10: GB10 transcendentals bit-identical to the frozen CPU sequences", + reference: "omega_math_<op> of src/omega_numeric_transc.c (CPU tier), every 32-bit input, bits compared exactly", + omega_commit: $r.omega_commit, + omega_tree_clean_before: $r.omega_tree_clean_before, + omega_tree_clean_after: $r.omega_tree_clean_after, + omega_commit_unchanged_after: $r.omega_commit_unchanged_after, + physics_commit: $r.physics_commit, + physics_lock_pin: $r.physics_lock_pin, + physics_tree_clean_before: $r.physics_tree_clean_before, + physics_tree_clean_after: $r.physics_tree_clean_after, + physics_commit_unchanged_after: $r.physics_commit_unchanged_after, + binary_sha256: $r.binary_sha256, + chip_log_sha256: $r.chip_log_sha256, + kernels: (tagged("HOSTTIER_KDIG:") | join("\n") | split("\n") | map(select(length > 0) | split(" ") | {op: .[0], instructions: (.[1] | tonumber), sha256: .[2]})), + nvdisasm_check: (tagged("HOSTTIER_NVD:") | join("\n")), + host_tier: $r.host_tier, + ops_requested: ($r.run_args[1:]), + ops: opsjson, + chip_exit_status: $r.chip_exit_status, + started_utc: $r.started_utc, + finished_utc: $r.finished_utc, + verdict: (if $r.verdict == "PASS" then "PASS" elif $cw == "PASS" then "FAIL" elif $cw == "" then "NOT_RUN" else $cw end) +} +' diff --git a/tools/run_numeric_transc_gate.sh b/tools/run_numeric_transc_gate.sh index d8c1619ad..fa09254ce 100755 --- a/tools/run_numeric_transc_gate.sh +++ b/tools/run_numeric_transc_gate.sh @@ -4,124 +4,24 @@ # 2^32 input of each op compared bit for bit with the CPU tier. # # Usage: tools/run_numeric_transc_gate.sh [OP ...] (default: EXP2 LOG2 SIGMOID TANH) -# Order: refuse a dirty omega tree or a physics checkout that is dirty or not -# at the physics.lock pin; refuse while ~/workspace/.spark-quiet exists, an -# est_load process runs or /tmp/aien-gb10.lock is held; run the host tier and -# the offline nvdisasm provenance check (tools/divsqrt_nvdisasm_check.sh, all -# whole-program kernels); raise the quiet flag; take the GPU lock; build the -# chip binary (no libm math, no CUDA symbols); run it to the end (never -# killed, never timed out); write a content-addressed receipt -# <evidence-dir>/<sha256>.json (mode 0444, created exclusively, outside the -# tree) plus the log as blobs/<sha256>.log; drop the flag. +# Exit: 0 PASS; 1 anything else (FAIL, NOT_RUN, refused). Refusals print +# "REFUSED: why" and "VERDICT NOT_RUN". Last stdout line: "VERDICT <word>". +# +# Thin wrapper: refusals, host tier (host build, host run and the offline nvdisasm +# provenance check), quiet flag, GPU lock, chip build, never-killed run and the +# content-addressed receipt <evidence-dir>/<sha256>.json plus blobs/<sha256>.log live +# in tools/chip_run.sh, configured by tools/manifests/numeric_transc.chiprun. This +# wrapper keeps the op-name check and the default ops. Env: PHYSICS_DIR (default +# ~/workspace/hive-worktrees/physics-gate14-e95e3ed, the module's own default differs) +# and TRANSC_GB10_EVIDENCE_DIR (read by the manifest). # # Run it detached so a closed terminal cannot cut the chip run: # setsid nohup tools/run_numeric_transc_gate.sh > /tmp/transc-gate.out 2>&1 < /dev/null & # Shell + coreutils + git + jq + gcc + nvdisasm. No Python. set -u -HERE=$(cd -P "$(dirname "$0")/.." && pwd) +HERE=$(cd -P "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) PHYSICS=${PHYSICS_DIR:-$HOME/workspace/hive-worktrees/physics-gate14-e95e3ed} -EVID=${TRANSC_GB10_EVIDENCE_DIR:-$HOME/workspace/evidence-out/E1-TRANSC-GB10} -QUIET=$HOME/workspace/.spark-quiet -OWNER="lane2 E1 transcendental GB10 chip run" OPS=("$@"); [ ${#OPS[@]} -gt 0 ] || OPS=(EXP2 LOG2 SIGMOID TANH) -RUN=$(mktemp -d /tmp/transc-gb10-run.XXXXXX) -FLAG_MINE=0 refuse() { echo "REFUSED: $*"; echo "VERDICT NOT_RUN"; exit 1; } -cleanup() { if [ "$FLAG_MINE" = 1 ] && grep -q "^$OWNER" "$QUIET" 2>/dev/null; then rm -f "$QUIET"; fi; } -trap cleanup EXIT -sha() { sha256sum "$1" | cut -d' ' -f1; } - -for op in "${OPS[@]}"; do case "$op" in EXP2|LOG2|SIGMOID|TANH) ;; *) refuse "unknown op $op";; esac; done -case "$(realpath -m "$EVID")/" in "$HERE"/*|"$(realpath -m "$PHYSICS")"/*) refuse "evidence dir $EVID is inside a candidate tree";; esac -[ -z "$(git -C "$HERE" status --porcelain)" ] || refuse "omega tree $HERE is dirty" -OMEGA_COMMIT=$(git -C "$HERE" rev-parse HEAD) || refuse "cannot read omega HEAD" -PIN=$(tr -d '[:space:]' < "$HERE/physics.lock") -PHYS_COMMIT=$(git -C "$PHYSICS" rev-parse HEAD) || refuse "cannot read physics HEAD at $PHYSICS" -[ "$PHYS_COMMIT" = "$PIN" ] || refuse "physics checkout is at $PHYS_COMMIT, physics.lock pins $PIN" -[ -z "$(git -C "$PHYSICS" status --porcelain)" ] || refuse "physics checkout $PHYSICS is dirty" -[ -e "$QUIET" ] && refuse "quiet flag is up: $(cat "$QUIET")" -[ -n "$(pgrep est_load)" ] && refuse "an est_load process is running" -fuser /tmp/aien-gb10.lock >/dev/null 2>&1 && refuse "/tmp/aien-gb10.lock is held" - -echo "== host tier" -make -s -C "$HERE" build/test_omega_numeric_transc_gb10_cpu > "$RUN/host-build.log" 2>&1 || refuse "host build failed" -"$HERE/build/test_omega_numeric_transc_gb10_cpu" > "$RUN/host.log" 2>&1; HOST_RC=$? -tail -1 "$RUN/host.log" -echo "== nvdisasm provenance" -"$HERE/tools/divsqrt_nvdisasm_check.sh" > "$RUN/nvdisasm.log" 2>&1; NVD_RC=$? -grep -E '^\[|^VERDICT|^nvdisasm' "$RUN/nvdisasm.log" -[ "$HOST_RC" = 0 ] && [ "$NVD_RC" = 0 ] || refuse "host tier ($HOST_RC) or nvdisasm check ($NVD_RC) failed; no chip run" -KDIG=$("$HERE/build/test_omega_numeric_transc_gb10_cpu" --digest) - -START=$(date -u +%Y-%m-%dT%H:%M:%SZ) -set -o noclobber -echo "$OWNER start=$START expected_end=$(date -u -d '+2 hours' +%Y-%m-%dT%H:%M:%SZ) pid=$$" > "$QUIET" || refuse "could not create the quiet flag" -set +o noclobber -FLAG_MINE=1 -exec 9> /tmp/aien-gb10.lock || refuse "cannot open /tmp/aien-gb10.lock" -flock -x 9 || refuse "cannot take /tmp/aien-gb10.lock" - -echo "== chip build" -NV=$PHYSICS/third_party/nvidia-open-580.173.02 -BIN=$RUN/test_omega_numeric_transc_gb10 -(cd "$HERE" && gcc -std=gnu11 -O2 -Wall -Wextra -Werror -ffp-contract=off -fno-fast-math -pthread \ - -Isrc -I"$PHYSICS/nvrm" -I"$PHYSICS/m16" \ - -I"$NV/src/common/sdk/nvidia/inc" -I"$NV/kernel-open/common/inc" \ - -I"$NV/kernel-open/nvidia-uvm" -I"$NV/src/nvidia/arch/nvalloc/unix/include" \ - -o "$BIN" tests/test_omega_numeric_transc_gb10.c src/omega_numeric_divsqrt_gb10.c src/omega_numeric_transc.c \ - src/omega_numeric.c src/omega_numeric_provenance.c src/omega_blackwell_encoder.c src/omega_blackwell_codegen.c \ - src/omega_blackwell_matmul.c src/omega_blackwell_qmd.c src/sha256.c \ - "$PHYSICS/nvrm/nvrm.c" "$PHYSICS/m16/m16_native.c") > "$RUN/chip-build.log" 2>&1 || { cat "$RUN/chip-build.log"; refuse "chip build failed"; } -if nm -u "$BIN" | grep -Eq '\b(sqrtf?|expf?|exp2f?|logf?|log2f?|powf?|fmaf?|sinf?|cosf?|tanhf?|erff?)\b'; then refuse "libm math symbols in $BIN"; fi -if nm -u "$BIN" | grep -Eiq 'cuda|cuInit|cuLaunch|nvrtc|cublas'; then refuse "CUDA symbols in $BIN"; fi -BIN_SHA=$(sha "$BIN") - -echo "== chip run (not killed, not timed out): ${OPS[*]}" -"$BIN" --chip "${OPS[@]}" > "$RUN/chip.log" 2>&1; CHIP_RC=$? -END=$(date -u +%Y-%m-%dT%H:%M:%SZ) -exec 9>&- -grep -E '^RESULT|^VERDICT' "$RUN/chip.log" - -OMEGA_CLEAN_AFTER=$([ -z "$(git -C "$HERE" status --porcelain)" ] && echo true || echo false) -PHYS_CLEAN_AFTER=$([ -z "$(git -C "$PHYSICS" status --porcelain)" ] && echo true || echo false) -OMEGA_SAME_AFTER=$([ "$(git -C "$HERE" rev-parse HEAD 2>/dev/null)" = "$OMEGA_COMMIT" ] && echo true || echo false) -PHYS_SAME_AFTER=$([ "$(git -C "$PHYSICS" rev-parse HEAD 2>/dev/null)" = "$PHYS_COMMIT" ] && echo true || echo false) -VERDICT=$(sed -n 's/^VERDICT \([A-Z_]*\).*/\1/p' "$RUN/chip.log" | tail -1) -[ -n "$VERDICT" ] || VERDICT=NOT_RUN -[ "$CHIP_RC" = 0 ] || [ "$VERDICT" != PASS ] || VERDICT=FAIL -[ "$OMEGA_CLEAN_AFTER" = true ] && [ "$PHYS_CLEAN_AFTER" = true ] && [ "$OMEGA_SAME_AFTER" = true ] && [ "$PHYS_SAME_AFTER" = true ] || { [ "$VERDICT" = PASS ] && VERDICT=FAIL; } - -mkdir -p "$EVID/blobs" -LOG_SHA=$(sha "$RUN/chip.log") -[ -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; } -# one object per RESULT line: {op, checked, exhaustive, mismatches, unwritten, verdict} -OPS_JSON=$(grep '^RESULT chip ' "$RUN/chip.log" | while read -r _ _ op rest; do - printf '{"op":"%s"' "$op" - for kv in $rest; do k=${kv%%=*}; v=${kv#*=} - case "$v" in true|false|[0-9]*) printf ',"%s":%s' "$k" "$v";; *) printf ',"%s":"%s"' "$k" "$v";; esac; done - printf '}\n'; done | jq -s .) -[ -n "$OPS_JSON" ] || OPS_JSON='[]' -BODY=$(jq -n --arg gate "E1-TRANSC-GB10" --arg omega "$OMEGA_COMMIT" --arg phys "$PHYS_COMMIT" --arg pin "$PIN" \ - --argjson oclean true --argjson pclean true --argjson oafter "$OMEGA_CLEAN_AFTER" --argjson pafter "$PHYS_CLEAN_AFTER" \ - --argjson osame "$OMEGA_SAME_AFTER" --argjson psame "$PHYS_SAME_AFTER" \ - --arg bin "$BIN_SHA" --arg log "$LOG_SHA" --arg kd "$KDIG" --arg start "$START" --arg end "$END" \ - --arg nvd "$(grep '^nvdisasm' "$RUN/nvdisasm.log")" --arg host "$(tail -1 "$RUN/host.log")" \ - --argjson ops "$OPS_JSON" --arg requested "${OPS[*]}" \ - --arg verdict "$VERDICT" --argjson rc "$CHIP_RC" '{ - gate: $gate, row: "E1 gap table row 10: GB10 transcendentals bit-identical to the frozen CPU sequences", - reference: "omega_math_<op> of src/omega_numeric_transc.c (CPU tier), every 32-bit input, bits compared exactly", - omega_commit: $omega, omega_tree_clean_before: $oclean, omega_tree_clean_after: $oafter, omega_commit_unchanged_after: $osame, - physics_commit: $phys, physics_lock_pin: $pin, physics_tree_clean_before: $pclean, physics_tree_clean_after: $pafter, physics_commit_unchanged_after: $psame, - binary_sha256: $bin, chip_log_sha256: $log, kernels: ($kd | split("\n") | map(select(length > 0) | split(" ") | {op: .[0], instructions: (.[1] | tonumber), sha256: .[2]})), - nvdisasm_check: $nvd, host_tier: $host, ops_requested: ($requested | split(" ")), ops: $ops, - chip_exit_status: $rc, started_utc: $start, finished_utc: $end, verdict: $verdict }') -[ -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; } -RSHA=$(sha "$RUN/receipt.json") -OUT=$EVID/$RSHA.json -if [ -e "$OUT" ]; then echo "receipt $OUT already exists (identical content)"; else - 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 -cmp -s "$RUN/receipt.json" "$OUT" || { echo "receipt $OUT does not match what was built"; echo "VERDICT FAIL"; exit 1; } -echo "RECEIPT $OUT" -echo "VERDICT $VERDICT" -[ "$VERDICT" = PASS ] || exit 1 -exit 0 +for op in "${OPS[@]}"; do case "$op" in EXP2|LOG2|SIGMOID|TANH) ;; *) refuse "unknown op $op" ;; esac; done +exec bash "$HERE/tools/chip_run.sh" "$HERE/tools/manifests/numeric_transc.chiprun" --physics-dir "$PHYSICS" -- --chip "${OPS[@]}"