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 / seed / spirv / ocl-vendor-matrix.sh

86 lines · 4551 bytes Raw Blame History
1#!/usr/bin/env bash
2# Verification only: replays gate-irspirv artifacts (modules plus native dumps produced on
3# AArch64 by seed/spirv/gate-irspirv.sh) through one opencl-host build that pins another CPU
4# OpenCL runtime. Unlike parity.py it does not stop at the first API failure: every row gets
5# built/ran/match columns and the host's error text, because the point is to list what breaks.
6# usage: ocl-vendor-matrix.sh BUILD_DIR HOST TABLE PREFIX OUT.tsv [--mutant-baseline]
7# --mutant-baseline substitutes mutant-flipped.spv for unit "mutant" (negative control).
8# Exit 0 when every row built, ran and matched; 1 when any row did not; 2 on usage/artifact error.
9# HOST_WRAP (optional) is a command prefix such as an intercept-layer loader.
10set -u
11[ $# -eq 5 ] || [ $# -eq 6 ] || { echo 'usage: ocl-vendor-matrix.sh BUILD_DIR HOST TABLE PREFIX OUT.tsv [--mutant-baseline]' >&2; exit 2; }
12B=$1 HOST=$2 TABLE=$3 PREFIX=$4 OUT=$5 MUTANT=${6:-}
13[ -z "$MUTANT" ] || [ "$MUTANT" = --mutant-baseline ] || { echo "unknown option $MUTANT" >&2; exit 2; }
14tag=${MUTANT:+mutant}; tag=${tag:-vendor}
15LOGS=${OUT%.tsv}.logs # per-row host stdout/stderr, beside the table
16mkdir -p "$LOGS"
17printf 'case\tunit\tkernel\targs\tnative_status\tnative_bits\tbuilt\tran\tresult_bits\tresult_status\tmatch\thost_exit\terror\n' > "$OUT"
18i=0 bad=0
19while IFS=$'\t' read -r unit name _ret typed status; do
20 case "$unit" in ''|'#'*) continue ;; esac
21 i=$((i+1))
22 module=$B/$unit.spv
23 [ -n "$MUTANT" ] && [ "$unit" = mutant ] && module=$B/mutant-flipped.spv
24 [ -f "$module" ] || { echo "missing module $module" >&2; exit 2; }
25 [ -f "$B/$PREFIX-$i.status" ] || { echo "missing native $B/$PREFIX-$i.status" >&2; exit 2; }
26 nstatus=$(cat "$B/$PREFIX-$i.status")
27 [ "$nstatus" = "$status" ] || { echo "row $i native status $nstatus expected $status" >&2; exit 2; }
28 if [ "$nstatus" = 0 ]; then
29 [ "$(wc -c < "$B/$PREFIX-$i.out")" = 8 ] || { echo "row $i incomplete native dump" >&2; exit 2; }
30 nbits=$(od -An -t u8 "$B/$PREFIX-$i.out" | tr -d ' \n')
31 else
32 nbits=0
33 fi
34 args=()
35 if [ "$typed" != - ]; then
36 IFS=, read -ra parts <<< "$typed"
37 for p in "${parts[@]}"; do
38 kind=${p%%:*} v=${p#*:}
39 if [ "$kind" = bool ]; then
40 case "$v" in true) args+=(1) ;; false) args+=(0) ;; *) echo "bad bool $v" >&2; exit 2 ;; esac
41 elif [ "${v#-}" != "$v" ]; then
42 args+=("$(printf '%u' "$v")") # two's complement, as parity.py masks to 64 bits
43 else
44 args+=("$v")
45 fi
46 done
47 fi
48 base=$LOGS/$i
49 # shellcheck disable=SC2086 # HOST_WRAP is an intentional word-split prefix
50 timeout 120 ${HOST_WRAP:-} "$HOST" "$module" "$name" "${args[@]}" > "$base.out" 2> "$base.err"
51 rc=$?
52 built=yes ran=no rbits=- rstatus=- match=no
53 case $rc in
54 0) ran=yes ;;
55 6) built=no ;;
56 7|8) ;;
57 3|4|5) built=env ;;
58 124) built=unknown; echo "opencl-host: timed out after 120 s" >> "$base.err" ;;
59 *) built=unknown; echo "opencl-host: terminated with exit $rc" >> "$base.err" ;;
60 esac
61 if [ $rc = 0 ]; then
62 if read -r rbits rstatus < "$base.out" && [ -n "$rstatus" ]; then
63 [ "$rbits" = "$nbits" ] && [ "$rstatus" = "$nstatus" ] && match=yes
64 else
65 ran=no; rbits=-; rstatus=-; echo "opencl-host: malformed stdout" >> "$base.err"
66 fi
67 fi
68 # Error text: host stderr minus the identity lines and the success-path build log.
69 if [ "$match" = yes ]; then
70 err=-
71 else
72 err=$(grep -v -e '^opencl-host: library=' -e '^opencl-host: platform=' -e '^opencl-host: il=' "$base.err" |
73 tr '\t\n' ' ' | tr -s ' ' | cut -c1-400)
74 [ -n "$err" ] || err="result mismatch: native $nbits/$nstatus got $rbits/$rstatus"
75 [ "$ran" = yes ] && err="result mismatch: native $nbits/$nstatus got $rbits/$rstatus"
76 bad=$((bad+1))
77 fi
78 printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n' "$i" "$unit" "$name" \
79 "$(IFS=,; echo "${args[*]:--}")" "$nstatus" "$nbits" "$built" "$ran" "$rbits" "$rstatus" \
80 "$match" "$rc" "$err" >> "$OUT"
81done < "$TABLE"
82[ "$i" -gt 0 ] || { echo "empty table $TABLE" >&2; exit 2; }
83built_no=$(awk -F'\t' 'NR>1 && $7!="yes"' "$OUT" | wc -l)
84ran_no=$(awk -F'\t' 'NR>1 && $8!="yes"' "$OUT" | wc -l)
85echo "MATRIX $PREFIX $tag rows=$i matched=$((i-bad)) not_matched=$bad not_built=$built_no not_ran=$ran_no table=$OUT"
86[ "$bad" = 0 ]