interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / tools / runtime_portability_check.sh

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