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
omega-mv / tools / sm121dis / check.sh
| 1 | #!/bin/sh |
| 2 | # check.sh <sm121dis> <kernel-dir> <work-dir>: Omega's disassembler against nvdisasm (the oracle) on every <kernel-dir>/*.bin. |
| 3 | # Per kernel: PASS when every word's text is the same (spacing collapsed), else FAIL with the first differences. |
| 4 | # Exit 0 only when every kernel passes; 2 when nvdisasm or a kernel is missing. nvdisasm is a decoder used offline as |
| 5 | # the reference (docs/OMEGA.md C6); nothing it prints is used anywhere else. |
| 6 | # Kernels are checked SM121DIS_JOBS at a time (default: every CPU this process may use); each writes |
| 7 | # <work-dir>/<name>.res and the report below reads them back in kernel order, so it is the same at any job count. |
| 8 | # A kernel without a result fails. |
| 9 | set -u |
| 10 | HERE=$(cd "$(dirname "$0")" && pwd) |
| 11 | NVDISASM=${NVDISASM:-/usr/local/cuda/bin/nvdisasm} |
| 12 | |
| 13 | if [ "${1:-}" = --one ]; then |
| 14 | # check.sh --one <sm121dis> <work-dir> <kernel.bin>: one kernel. First line of .res: PASS|FAIL <words>; the rest |
| 15 | # is what the report prints for it. Written under a temporary name and renamed, so a cut-short check leaves none. |
| 16 | DIS=$2; WORK=$3; f=$4 |
| 17 | b=$(basename "$f" .bin) |
| 18 | if ! "$NVDISASM" -b SM121 -hex "$f" > "$WORK/$b.nv" 2>&1; then |
| 19 | { echo "FAIL 0"; echo "[FAIL] $b: nvdisasm refused it"; head -3 "$WORK/$b.nv"; } > "$WORK/$b.res.tmp" |
| 20 | else |
| 21 | sh "$HERE/oracle_pairs.sh" "$WORK/$b.nv" > "$WORK/$b.want" |
| 22 | n=$(wc -l < "$WORK/$b.want") |
| 23 | # Capture the decoder directly: a pipeline would hide its exit status behind sed. |
| 24 | rc=0 |
| 25 | "$DIS" --pairs "$f" > "$WORK/$b.raw" 2> "$WORK/$b.err" || rc=$? |
| 26 | if [ "$rc" -ne 0 ]; then |
| 27 | { echo "FAIL $n"; echo "[FAIL] $b: decoder exited $rc"; head -3 "$WORK/$b.err"; } > "$WORK/$b.res.tmp" |
| 28 | elif ! sed 's/[[:space:]]\{1,\}/ /g' "$WORK/$b.raw" > "$WORK/$b.got"; then |
| 29 | { echo "FAIL $n"; echo "[FAIL] $b: decoder output normalization failed"; } > "$WORK/$b.res.tmp" |
| 30 | elif [ "$n" -gt 0 ] && cmp -s "$WORK/$b.want" "$WORK/$b.got"; then |
| 31 | { echo "PASS $n"; echo "[PASS] $b: $n words"; } > "$WORK/$b.res.tmp" |
| 32 | else |
| 33 | { echo "FAIL $n"; echo "[FAIL] $b: $(diff "$WORK/$b.want" "$WORK/$b.got" | grep -c '^<') of $n words differ" |
| 34 | diff "$WORK/$b.want" "$WORK/$b.got" | head -6; } > "$WORK/$b.res.tmp" |
| 35 | fi |
| 36 | fi |
| 37 | mv "$WORK/$b.res.tmp" "$WORK/$b.res" |
| 38 | exit 0 |
| 39 | fi |
| 40 | |
| 41 | DIS=$1; DIR=$2; WORK=$3 |
| 42 | [ -x "$NVDISASM" ] || { echo "VERDICT NOT_RUN: $NVDISASM missing"; exit 2; } |
| 43 | ls "$DIR"/*.bin >/dev/null 2>&1 || { echo "VERDICT NOT_RUN: no kernels in $DIR"; exit 2; } |
| 44 | mkdir -p "$WORK" |
| 45 | # "$WORK/." so a work dir that is a symlink (to /dev/shm, say) is swept too; a stale PASS must never be read back. |
| 46 | find "$WORK/." -maxdepth 1 \( -name '*.res' -o -name '*.res.tmp' \) -exec rm -f {} + |
| 47 | echo "oracle: $("$NVDISASM" --version | grep -o "release [0-9.]*, V[0-9.]*")" |
| 48 | JOBS=${SM121DIS_JOBS:-$(nproc 2>/dev/null || echo 1)} |
| 49 | for f in "$DIR"/*.bin; do printf '%s\0' "$f"; done | xargs -0 -n 1 -P "$JOBS" sh "$HERE/check.sh" --one "$DIS" "$WORK" |
| 50 | k=0; bad=0; words=0 |
| 51 | for f in "$DIR"/*.bin; do |
| 52 | b=$(basename "$f" .bin) |
| 53 | k=$((k + 1)) |
| 54 | if [ -f "$WORK/$b.res" ] && read -r st n < "$WORK/$b.res"; then |
| 55 | sed 1d "$WORK/$b.res" |
| 56 | words=$((words + n)) |
| 57 | [ "$st" = PASS ] || bad=$((bad + 1)) |
| 58 | else |
| 59 | echo "[FAIL] $b: no result"; bad=$((bad + 1)) |
| 60 | fi |
| 61 | done |
| 62 | echo "kernels: $k, words: $words, failed kernels: $bad" |
| 63 | [ $bad = 0 ] && { echo "VERDICT PASS"; exit 0; } |
| 64 | echo "VERDICT FAIL"; exit 1 |