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 / runtime_portability_check.sh
| 1 | #!/bin/sh |
| 2 | # Omega runtime R3 (omega-mv#596): the portability table must match the source tree. |
| 3 | # usage: runtime_portability_check.sh <root> <table.tsv> <engine.mk> |
| 4 | # Host only, no compiler, no device. POSIX sh + awk. |
| 5 | # |
| 6 | # Fails (exit 1, one line per problem) when: |
| 7 | # 1. a src/omega_gpu_*, src/omega_blackwell_* or src/omega_bw_* file has no row in the table |
| 8 | # 2. a row names a file that does not exist, or is duplicated, or has a bad class / binding / empty reason |
| 9 | # 3. a PORTABLE row's file includes a Linux or NVRM header (nvrm.h, m16_native.h, omega_gpu_platform_linux.h, |
| 10 | # pthread.h, unistd.h, fcntl.h, sys/*, linux/*) or a Blackwell chip header (omega_blackwell_*, omega_bw_*) |
| 11 | # 4. the os_binding column disagrees with what the include scan finds, or a .c file in GPU_FS_SRCS |
| 12 | # (engine.mk, the make gpu-engine-freestanding list) is not FREESTANDING_PROVEN |
| 13 | # It proves every file has a row and that the rows agree with the includes. It does not prove that |
| 14 | # a row's reason is right. |
| 15 | # |
| 16 | # Include scan: direct #include lines only. Lines inside "#ifdef OMEGA_ATTN_DEBUG" (a debug trace, off by default) and "#ifndef OMEGA_GPU_NO_POSIX" (or the #else |
| 17 | # of "#ifdef OMEGA_GPU_NO_POSIX") are the hosted-only build and are not counted, because the |
| 18 | # freestanding build never sees them. |
| 19 | root=$1; table=$2; mk=$3 |
| 20 | [ -d "$root/src" ] && [ -f "$table" ] && [ -f "$mk" ] || { echo "usage: $0 <root> <table.tsv> <engine.mk>"; exit 2; } |
| 21 | |
| 22 | fail=0 |
| 23 | bad() { echo "FAIL: $*"; fail=1; } |
| 24 | |
| 25 | # unguarded includes of one file, one per line, as written between <> or "" |
| 26 | includes() { |
| 27 | awk ' |
| 28 | function hosted( i) { for (i = 1; i <= d; i++) if (h[i]) return 1; return 0 } |
| 29 | /^[ \t]*#[ \t]*ifdef[ \t]+OMEGA_ATTN_DEBUG/ { d++; h[d] = 1; isdef[d] = 0; next } |
| 30 | /^[ \t]*#[ \t]*if/ && !/^[ \t]*#[ \t]*(ifdef|ifndef)[ \t]+OMEGA_GPU_NO_POSIX/ { |
| 31 | d++; h[d] = 0; isdef[d] = 0 |
| 32 | if ($0 ~ /^[ \t]*#[ \t]*if[ \t]+!defined[ \t]*\(?[ \t]*OMEGA_GPU_NO_POSIX/) h[d] = 1 |
| 33 | next } |
| 34 | /^[ \t]*#[ \t]*ifndef[ \t]+OMEGA_GPU_NO_POSIX/ { d++; h[d] = 1; isdef[d] = 0; next } |
| 35 | /^[ \t]*#[ \t]*ifdef[ \t]+OMEGA_GPU_NO_POSIX/ { d++; h[d] = 0; isdef[d] = 1; next } |
| 36 | /^[ \t]*#[ \t]*(else|elif)/ { if (d > 0 && isdef[d]) h[d] = 1; next } |
| 37 | /^[ \t]*#[ \t]*endif/ { if (d > 0) d--; next } |
| 38 | /^[ \t]*#[ \t]*include/ { |
| 39 | if (hosted()) next |
| 40 | s = $0; sub(/^[ \t]*#[ \t]*include[ \t]*[<"]/, "", s); sub(/[>"].*$/, "", s); print s } |
| 41 | ' "$1" |
| 42 | } |
| 43 | |
| 44 | # --- row syntax and file existence ----------------------------------------------------------- |
| 45 | rows=$(grep -v '^#' "$table" | grep -v '^file ' || true) |
| 46 | tmp_rows=$(mktemp); printf '%s\n' "$rows" | grep -v '^$' > "$tmp_rows" |
| 47 | fs_srcs=$(awk '/^GPU_FS_SRCS[ \t]*=/ {on=1} on {print} on && !/\\$/ {exit}' "$mk" | tr -d '\\' | tr ' \t' '\n\n' | grep '^src/.*\.c$' || true) |
| 48 | [ -n "$fs_srcs" ] || bad "no GPU_FS_SRCS list found in $mk" |
| 49 | |
| 50 | dups=$(cut -f1 "$tmp_rows" | sort | uniq -d) |
| 51 | [ -z "$dups" ] || bad "duplicate rows: $(echo $dups)" |
| 52 | |
| 53 | while IFS=' ' read -r f class reason bind extra; do |
| 54 | [ -n "$f" ] || continue |
| 55 | [ -f "$root/$f" ] || { bad "row names a missing file: $f"; continue; } |
| 56 | case "$class" in CHIP_SPECIFIC|PORTABLE) ;; *) bad "$f: class '$class' is not CHIP_SPECIFIC or PORTABLE" ;; esac |
| 57 | case "$bind" in FREESTANDING_PROVEN|NO_HOSTED_INCLUDE|HOSTED_LIBC|LINUX_DRIVER) ;; *) bad "$f: os_binding '$bind' is not one of FREESTANDING_PROVEN NO_HOSTED_INCLUDE HOSTED_LIBC LINUX_DRIVER" ;; esac |
| 58 | [ -n "$reason" ] || bad "$f: empty reason" |
| 59 | [ -z "$extra" ] || bad "$f: more than four columns" |
| 60 | |
| 61 | inc=$(includes "$root/$f") |
| 62 | linux=$(printf '%s\n' "$inc" | grep -E '^(nvrm\.h|m16_native\.h|omega_gpu_platform_linux\.h|pthread\.h|unistd\.h|fcntl\.h|sys/.*|linux/.*)$' || true) |
| 63 | driver=$(printf '%s\n' "$linux" | grep -E '^(nvrm\.h|m16_native\.h|omega_gpu_platform_linux\.h|sys/.*|linux/.*)$' || true) |
| 64 | hosted=$(printf '%s\n' "$inc" | grep -E '^(stdio\.h|stdlib\.h|time\.h|errno\.h|math\.h|pthread\.h|unistd\.h|fcntl\.h|assert\.h|inttypes\.h|signal\.h|ctype\.h|sys/.*|linux/.*)$' || true) |
| 65 | chip=$(printf '%s\n' "$inc" | grep -E '^omega_(blackwell_|bw_)' || true) |
| 66 | |
| 67 | # derived binding |
| 68 | if [ -n "$driver" ]; then want=LINUX_DRIVER |
| 69 | elif [ -n "$hosted" ]; then want=HOSTED_LIBC |
| 70 | else want=NO_HOSTED_INCLUDE; fi |
| 71 | if printf '%s\n' "$fs_srcs" | grep -qx "$f"; then |
| 72 | [ "$want" = NO_HOSTED_INCLUDE ] || bad "$f: is in GPU_FS_SRCS but the include scan finds $(echo $driver $hosted)" |
| 73 | want=FREESTANDING_PROVEN |
| 74 | fi |
| 75 | [ "$bind" = "$want" ] || bad "$f: os_binding is $bind, the include scan and GPU_FS_SRCS say $want" |
| 76 | |
| 77 | if [ "$class" = PORTABLE ]; then |
| 78 | [ -z "$linux" ] || bad "$f: PORTABLE but includes a Linux/NVRM header: $(echo $linux)" |
| 79 | [ -z "$chip" ] || bad "$f: PORTABLE but includes a Blackwell chip header: $(echo $chip)" |
| 80 | fi |
| 81 | done < "$tmp_rows" |
| 82 | |
| 83 | # --- every file has a row ---------------------------------------------------------------------- |
| 84 | for p in "$root"/src/omega_gpu_* "$root"/src/omega_blackwell_* "$root"/src/omega_bw_*; do |
| 85 | [ -f "$p" ] || continue |
| 86 | f=src/$(basename "$p") |
| 87 | cut -f1 "$tmp_rows" | grep -qx "$f" || bad "no row in the table for $f" |
| 88 | done |
| 89 | |
| 90 | n=$(wc -l < "$tmp_rows" | tr -d ' ') |
| 91 | rm -f "$tmp_rows" |
| 92 | if [ "$fail" = 0 ]; then echo "PASS: $n rows, every omega_gpu_* / omega_blackwell_* / omega_bw_* file in src/ has one and the rows agree with the includes"; exit 0; fi |
| 93 | echo "FAIL: portability table does not match the tree"; exit 1 |