Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/om/encoder/guard-gate.sh # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers 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. 7 set -eu 8 ROOT=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd) 9 cd "$ROOT" 10 OMC=${OMC:-$ROOT/seed/out/omc} 11 NVDISASM=${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; } 14 D=$(mktemp -d) 15 trap 'rm -rf "$D"' EXIT 16 17 compile() { 18 if ! "$OMC" < "$1" > "$2"; then 19 echo "COMPILE FAIL $1" 20 exit 1 21 fi 22 chmod +x "$2" 23 } 24 25 echo "oracle: $("$NVDISASM" --version | grep -o 'release [0-9.]*, V[0-9.]*')" 26 echo "omc: $(sha256sum "$OMC" | cut -d' ' -f1)" 27 28 cat om/encoder/bw_enc_sm121.om om/encoder/guard_pred_test.om > "$D/fixed.om" 29 compile "$D/fixed.om" "$D/fixed" 30 31 echo "==== fixed rows ====" 32 set +e 33 "$D/fixed" > "$D/fixed.rows" 2>"$D/fixed.err" 34 rc=$? 35 set -e 36 cat "$D/fixed.rows" 37 echo "fixed rows exit $rc" 38 [ "$rc" = 0 ] 39 if grep -q . "$D/fixed.err"; then echo "fixed rows stderr:"; cat "$D/fixed.err"; exit 1; fi 40 41 echo "==== fixed oracle ====" 42 "$D/fixed" bin > "$D/fixed.bin" 43 bytes=$(wc -c < "$D/fixed.bin") 44 echo "fixed oracle bytes $bytes" 45 [ "$bytes" = 2128 ] 46 "$NVDISASM" -b SM121 -hex "$D/fixed.bin" > "$D/fixed.nv" 47 set +e 48 "$D/fixed" bin check < "$D/fixed.nv" > "$D/fixed.oracle" 2>"$D/fixed.oerr" 49 rc=$? 50 set -e 51 cat "$D/fixed.oracle" 52 echo "fixed oracle exit $rc" 53 [ "$rc" = 0 ] 54 55 echo "==== guard-7 mutant ====" 56 sed '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" 57 if cmp -s "$D/mutsrc.om" om/encoder/bw_enc_sm121.om; then 58 echo "MUTANT changed nothing" 59 exit 1 60 fi 61 n=$(grep -c 'shl ulong 7 12' "$D/mutsrc.om") 62 [ "$n" = 1 ] 63 cat "$D/mutsrc.om" om/encoder/guard_pred_test.om > "$D/mut.om" 64 compile "$D/mut.om" "$D/mutant" 65 set +e 66 "$D/mutant" > "$D/mut.rows" 2>"$D/mut.err" 67 rc=$? 68 set -e 69 cat "$D/mut.rows" 70 echo "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" 74 set +e 75 "$D/mutant" bin check < "$D/mut.nv" > "$D/mut.oracle" 2>"$D/mut.oerr" 76 rc=$? 77 set -e 78 cat "$D/mut.oracle" 79 echo "mutant oracle exit $rc" 80 [ "$rc" != 0 ] 81 82 echo "==== gpu copy (lock-pinned encoder) ====" 83 cat gpu/nvidia/om/encoder/bw_enc_sm121.om gpu/nvidia/om/encoder/guard_pred_test.om > "$D/gpu.om" 84 compile "$D/gpu.om" "$D/gpu" 85 set +e 86 "$D/gpu" > "$D/gpu.rows" 2>"$D/gpu.err" 87 rc=$? 88 set -e 89 cat "$D/gpu.rows" 90 echo "gpu rows exit $rc" 91 [ "$rc" = 0 ] 92 "$D/gpu" bin > "$D/gpu.bin" 93 gbytes=$(wc -c < "$D/gpu.bin") 94 echo "gpu oracle bytes $gbytes" 95 [ "$gbytes" = 2160 ] 96 "$NVDISASM" -b SM121 -hex "$D/gpu.bin" > "$D/gpu.nv" 97 set +e 98 "$D/gpu" bin check < "$D/gpu.nv" > "$D/gpu.oracle" 99 rc=$? 100 set -e 101 cat "$D/gpu.oracle" 102 echo "gpu oracle exit $rc" 103 [ "$rc" = 0 ] 104 105 echo "==== two copies ====" 106 sha256sum om/encoder/bw_enc_sm121.om gpu/nvidia/om/encoder/bw_enc_sm121.om 107 if cmp -s om/encoder/bw_enc_sm121.om gpu/nvidia/om/encoder/bw_enc_sm121.om; then 108 echo "COPY sources byte-identical" 109 else 110 echo "COPY sources differ" 111 fi 112 cat om/encoder/bw_enc_sm121.om om/encoder/guard_words.om > "$D/wa.om" 113 cat gpu/nvidia/om/encoder/bw_enc_sm121.om om/encoder/guard_words.om > "$D/wb.om" 114 compile "$D/wa.om" "$D/wa" 115 compile "$D/wb.om" "$D/wb" 116 "$D/wa" > "$D/wa.txt" 117 "$D/wb" > "$D/wb.txt" 118 la=$(wc -l < "$D/wa.txt") 119 lb=$(wc -l < "$D/wb.txt") 120 echo "word lines om $la gpu $lb" 121 [ "$la" = 192 ] 122 [ "$lb" = 192 ] 123 awk ' 124 NR==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 } 129 END { 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" 131 echo "GUARD GATE PASS"