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 / om / encoder / guard-gate.sh

131 lines · 4114 bytes Raw Blame History
1#!/bin/sh
2# guard-gate.sh: the sm_121 guard predicate, on the encoder the C build links.
3# Oracle: NVIDIA nvdisasm -b SM121 -hex (not shipped, not first-party).
4# A guard-7 mutant of enc1 must fail both the row check and the oracle.
5# The two encoder sources are compared on ops 0..63. Guards must agree, and any
6# other word difference fails the gate. Run from anywhere.
7set -eu
8ROOT=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)
9cd "$ROOT"
10OMC=${OMC:-$ROOT/seed/out/omc}
11NVDISASM=${NVDISASM:-/usr/local/cuda/bin/nvdisasm}
12[ -x "$OMC" ] || { echo "NOT_RUN: $OMC missing"; exit 3; }
13[ -x "$NVDISASM" ] || { echo "NOT_RUN: $NVDISASM missing"; exit 3; }
14D=$(mktemp -d)
15trap 'rm -rf "$D"' EXIT
16
17compile() {
18 if ! "$OMC" < "$1" > "$2"; then
19 echo "COMPILE FAIL $1"
20 exit 1
21 fi
22 chmod +x "$2"
23}
24
25echo "oracle: $("$NVDISASM" --version | grep -o 'release [0-9.]*, V[0-9.]*')"
26echo "omc: $(sha256sum "$OMC" | cut -d' ' -f1)"
27
28cat om/encoder/bw_enc_sm121.om om/encoder/guard_pred_test.om > "$D/fixed.om"
29compile "$D/fixed.om" "$D/fixed"
30
31echo "==== fixed rows ===="
32set +e
33"$D/fixed" > "$D/fixed.rows" 2>"$D/fixed.err"
34rc=$?
35set -e
36cat "$D/fixed.rows"
37echo "fixed rows exit $rc"
38[ "$rc" = 0 ]
39if grep -q . "$D/fixed.err"; then echo "fixed rows stderr:"; cat "$D/fixed.err"; exit 1; fi
40
41echo "==== fixed oracle ===="
42"$D/fixed" bin > "$D/fixed.bin"
43bytes=$(wc -c < "$D/fixed.bin")
44echo "fixed oracle bytes $bytes"
45[ "$bytes" = 2128 ]
46"$NVDISASM" -b SM121 -hex "$D/fixed.bin" > "$D/fixed.nv"
47set +e
48"$D/fixed" bin check < "$D/fixed.nv" > "$D/fixed.oracle" 2>"$D/fixed.oerr"
49rc=$?
50set -e
51cat "$D/fixed.oracle"
52echo "fixed oracle exit $rc"
53[ "$rc" = 0 ]
54
55echo "==== guard-7 mutant ===="
56sed 's/^put w 0 or sub x and x 61440 shl pred o 12$/put w 0 or sub x and x 61440 shl ulong 7 12/' om/encoder/bw_enc_sm121.om > "$D/mutsrc.om"
57if cmp -s "$D/mutsrc.om" om/encoder/bw_enc_sm121.om; then
58 echo "MUTANT changed nothing"
59 exit 1
60fi
61n=$(grep -c 'shl ulong 7 12' "$D/mutsrc.om")
62[ "$n" = 1 ]
63cat "$D/mutsrc.om" om/encoder/guard_pred_test.om > "$D/mut.om"
64compile "$D/mut.om" "$D/mutant"
65set +e
66"$D/mutant" > "$D/mut.rows" 2>"$D/mut.err"
67rc=$?
68set -e
69cat "$D/mut.rows"
70echo "mutant rows exit $rc"
71[ "$rc" != 0 ]
72"$D/mutant" bin > "$D/mut.bin"
73"$NVDISASM" -b SM121 -hex "$D/mut.bin" > "$D/mut.nv"
74set +e
75"$D/mutant" bin check < "$D/mut.nv" > "$D/mut.oracle" 2>"$D/mut.oerr"
76rc=$?
77set -e
78cat "$D/mut.oracle"
79echo "mutant oracle exit $rc"
80[ "$rc" != 0 ]
81
82echo "==== gpu copy (lock-pinned encoder) ===="
83cat gpu/nvidia/om/encoder/bw_enc_sm121.om gpu/nvidia/om/encoder/guard_pred_test.om > "$D/gpu.om"
84compile "$D/gpu.om" "$D/gpu"
85set +e
86"$D/gpu" > "$D/gpu.rows" 2>"$D/gpu.err"
87rc=$?
88set -e
89cat "$D/gpu.rows"
90echo "gpu rows exit $rc"
91[ "$rc" = 0 ]
92"$D/gpu" bin > "$D/gpu.bin"
93gbytes=$(wc -c < "$D/gpu.bin")
94echo "gpu oracle bytes $gbytes"
95[ "$gbytes" = 2160 ]
96"$NVDISASM" -b SM121 -hex "$D/gpu.bin" > "$D/gpu.nv"
97set +e
98"$D/gpu" bin check < "$D/gpu.nv" > "$D/gpu.oracle"
99rc=$?
100set -e
101cat "$D/gpu.oracle"
102echo "gpu oracle exit $rc"
103[ "$rc" = 0 ]
104
105echo "==== two copies ===="
106sha256sum om/encoder/bw_enc_sm121.om gpu/nvidia/om/encoder/bw_enc_sm121.om
107if cmp -s om/encoder/bw_enc_sm121.om gpu/nvidia/om/encoder/bw_enc_sm121.om; then
108 echo "COPY sources byte-identical"
109else
110 echo "COPY sources differ"
111fi
112cat om/encoder/bw_enc_sm121.om om/encoder/guard_words.om > "$D/wa.om"
113cat gpu/nvidia/om/encoder/bw_enc_sm121.om om/encoder/guard_words.om > "$D/wb.om"
114compile "$D/wa.om" "$D/wa"
115compile "$D/wb.om" "$D/wb"
116"$D/wa" > "$D/wa.txt"
117"$D/wb" > "$D/wb.txt"
118la=$(wc -l < "$D/wa.txt")
119lb=$(wc -l < "$D/wb.txt")
120echo "word lines om $la gpu $lb"
121[ "$la" = 192 ]
122[ "$lb" = 192 ]
123awk '
124NR==FNR { k=$1" "$2; st[k]=$3; g[k]=$4; w[k]=$5" "$6" "$7" "$8; next }
125{ k=$1" "$2
126 if (st[k] != $3 || g[k] != $4) { print "GUARD DIFF " k " link " st[k] " " g[k] " ng " $3 " " $4; bad++ }
127 if (w[k] != $5" "$6" "$7" "$8) { print "WORD DIFF " k " link " w[k] " ng " $5" "$6" "$7" "$8; words++ }
128}
129END { print "guard diffs " bad+0; print "word diffs " words+0; if (bad+0 > 0 || words+0 > 0) exit 1 }
130' "$D/wa.txt" "$D/wb.txt"
131echo "GUARD GATE PASS"