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_controls.sh

68 lines · 4423 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# Negative and positive controls for tools/runtime_portability_check.sh (omega-mv#596, slice R3).
4# usage: runtime_portability_controls.sh <scratch-dir> <table.tsv> <engine.mk>
5# Each control builds a scratch copy of the GPU source files, breaks one thing, and requires the
6# checker to FAIL with the expected message (or, for the positive control, to still PASS).
7# A check that cannot fail proves nothing. Exit 0 only when every control behaves as required.
8scratch=$1; table=$2; mk=$3
9here=$(cd "$(dirname "$0")" && pwd)
10chk="$here/runtime_portability_check.sh"
11[ -n "$scratch" ] && [ -f "$table" ] && [ -f "$mk" ] || { echo "usage: $0 <scratch-dir> <table.tsv> <engine.mk>"; exit 2; }
12ok=0
13
14fresh() { # fresh <name>: scratch root with a copy of the GPU files and the table
15 r="$scratch/$1"; rm -rf "$r"; mkdir -p "$r/src"
16 cp src/omega_gpu_* src/omega_blackwell_* src/omega_bw_* src/omega_ampere_* "$r/src/"
17 cp "$table" "$r/table.tsv"
18}
19expect_fail() { # expect_fail <name> <pattern> <what was broken>
20 out=$("$chk" "$scratch/$1" "$scratch/$1/table.tsv" "$mk" 2>&1); rc=$?
21 if [ $rc -eq 1 ] && printf '%s\n' "$out" | grep -q "$2"; then
22 echo "CONTROL $1: FAIL as required ($3)"; printf '%s\n' "$out" | grep "$2" | head -2 | sed 's/^/ /'
23 else
24 echo "CONTROL $1: WRONG, the checker exit was $rc and did not report '$2' ($3)"; printf '%s\n' "$out" | head -5 | sed 's/^/ /'; ok=1
25 fi
26}
27expect_pass() {
28 out=$("$chk" "$scratch/$1" "$scratch/$1/table.tsv" "$mk" 2>&1); rc=$?
29 if [ $rc -eq 0 ]; then echo "CONTROL $1: PASS as required ($2)"
30 else echo "CONTROL $1: WRONG, the checker failed ($2)"; printf '%s\n' "$out" | head -5 | sed 's/^/ /'; ok=1; fi
31}
32setclass() { # setclass <name> <src/file> <class>
33 awk -F'\t' -v f="$2" -v c="$3" 'BEGIN{OFS="\t"} $1==f{$2=c} {print}' "$scratch/$1/table.tsv" > "$scratch/$1/t.new" && mv "$scratch/$1/t.new" "$scratch/$1/table.tsv"
34}
35
36fresh unchanged; expect_pass unchanged "scratch copy of the real tree and table"
37
38fresh new-file-no-row
39printf 'int omega_gpu_zz_dummy(void) { return 0; }\n' > "$scratch/new-file-no-row/src/omega_gpu_zz_dummy.c"
40expect_fail new-file-no-row "no row in the table for src/omega_gpu_zz_dummy.c" "a new omega_gpu_ file with no row"
41
42fresh row-missing-file
43printf 'src/omega_gpu_zz_ghost.c\tPORTABLE\tghost\tNO_HOSTED_INCLUDE\n' >> "$scratch/row-missing-file/table.tsv"
44expect_fail row-missing-file "row names a missing file: src/omega_gpu_zz_ghost.c" "a row for a file that does not exist"
45
46fresh portable-includes-nvrm
47printf '#include "nvrm.h"\n' | cat - "$scratch/portable-includes-nvrm/src/omega_gpu_wait.c" > "$scratch/p.c" && mv "$scratch/p.c" "$scratch/portable-includes-nvrm/src/omega_gpu_wait.c"
48expect_fail portable-includes-nvrm "omega_gpu_wait.c: PORTABLE but includes a Linux/NVRM header: nvrm.h" "a PORTABLE file that includes nvrm.h"
49
50fresh portable-row-on-linux-file
51setclass portable-row-on-linux-file src/omega_gpu_platform_linux.c PORTABLE
52expect_fail portable-row-on-linux-file "omega_gpu_platform_linux.c: PORTABLE but includes a Linux/NVRM header" "the real Linux backend relabelled PORTABLE"
53
54fresh portable-row-on-chip-file
55setclass portable-row-on-chip-file src/omega_blackwell_qmd.h PORTABLE
56setclass portable-row-on-chip-file src/omega_gpu_attention_api.c PORTABLE
57expect_fail portable-row-on-chip-file "omega_gpu_attention_api.c: PORTABLE but includes a Blackwell chip header" "a file that includes Blackwell headers relabelled PORTABLE"
58
59fresh guarded-include
60{ printf '#ifndef OMEGA_GPU_NO_POSIX\n#include "nvrm.h"\n#include <pthread.h>\n#endif\n'; cat "$scratch/guarded-include/src/omega_gpu_engine.c"; } > "$scratch/g.c" && mv "$scratch/g.c" "$scratch/guarded-include/src/omega_gpu_engine.c"
61expect_pass guarded-include "an nvrm.h include inside #ifndef OMEGA_GPU_NO_POSIX is the hosted-only build and must not count"
62
63fresh freestanding-claim-broken
64printf '#include <stdlib.h>\n' | cat - "$scratch/freestanding-claim-broken/src/omega_gpu_fmt.c" > "$scratch/g.c" && mv "$scratch/g.c" "$scratch/freestanding-claim-broken/src/omega_gpu_fmt.c"
65expect_fail freestanding-claim-broken "omega_gpu_fmt.c: is in GPU_FS_SRCS but the include scan finds stdlib.h" "a freestanding-closure file that gained stdlib.h"
66
67[ $ok -eq 0 ] && echo "ALL CONTROLS BEHAVED AS REQUIRED" || echo "A CONTROL DID NOT BEHAVE: the check is not trustworthy"
68exit $ok