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 / tests / tools-om / artexp.sh

217 lines · 13090 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# artexp acceptance: tools/artifact_export.c (seeded Omega om/tools/artexp.om) against its C oracle
4# (-DCUDAPP_MIGRATION_PENDING_C_TOOLS_ARTEXP). Both builds link the real library (host only, no device).
5# Every case runs each build in a fresh directory and compares stdout, stderr, exit and every file the
6# export wrote (name, size, sha256) byte for byte. Then a flipped-record negative control and recompiled
7# mutants. TOOLS_OM_COVERAGE=DIR writes gcov branch data of the oracle.
8# Run under: bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10
9set -eu
10ROOT=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)
11cd "$ROOT"
12tmp=$(mktemp -d)
13trap 'rm -rf "$tmp"' EXIT
14. tests/tools-om/lib.sh
15tom_pin
16SRC=tools/artifact_export.c
17OFF=-DCUDAPP_MIGRATION_PENDING_C_TOOLS_ARTEXP
18make -j3 OUT_DIR="$tmp/b" "$tmp/b/libomega_gpu.a" > "$tmp/b.log" 2>&1 ||
19 { tail -20 "$tmp/b.log"; echo "FAIL building the library"; exit 1; }
20LIBS="src/omega_native_artifact.c src/omega_cubin.c $tmp/b/libomega_gpu.a -lpthread -lm"
21$CC $TOM_CFLAGS $OFF -o "$tmp/ae_c" $SRC $LIBS
22$CC $TOM_CFLAGS -o "$tmp/ae_om" $SRC $LIBS
23
24CM=647116fc1ba1e1394982fc8ba181ce565293f160a6b56afc0f02b2128a675704
25AT=003696e422bba7274877ba9e01a61076ea0f862f32760cbaa06c60f85a115359
26G=0123456789abcdef0123456789abcdef01234567
27LONG=$(printf 'p%.0s' $(seq 1 5000))
28# One case per line: SETUP then the arguments (shell words). SETUP: - nothing, exists (out.cubin is there),
29# link (out.manifest is a symlink), nodir (the prefix names a missing directory).
30cat > "$tmp/cases" <<EOF
31-
32- matmul
33- attention
34- bogus
35- matmul --out
36- matmul --bogus x
37- matmul --out out --m
38- matmul --out out --contract-id
39- matmul --out out --commit
40- matmul --out out --k
41- matmul --out out --n
42- attention --out out --q-heads
43- attention --out out --kv-heads
44- matmul --m 16 --k 16 --n 8 --contract-id $CM --commit $G
45- matmul --m 16 --k 16 --n 8 --out out --commit $G
46- matmul --m 16 --k 16 --n 8 --contract-id ${CM}0 --out out --commit $G
47- matmul --m 16 --k 16 --n 8 --contract-id $(printf %.63s $CM) --out out --commit $G
48- matmul --m 16 --k 16 --n 8 --contract-id $CM --out out
49- matmul --m 16 --k 16 --n 8 --contract-id $CM --out out --commit $(printf %.39s $G)
50- matmul --m 16 --k 16 --n 8 --contract-id $CM --out out --commit ${G}0
51- matmul --m 16 --k 16 --n 8 --contract-id $CM --out out --commit 0123456789ABCDEF0123456789abcdef01234567
52- matmul --m 16 --k 16 --n 8 --contract-id $CM --out out --commit 0123456789abcdeg0123456789abcdef01234567
53- matmul --m 16 --k 16 --n 8 --contract-id $CM --out out --commit '012345678/abcdef0123456789abcdef01234567'
54- matmul --m 16 --k 16 --n 8 --contract-id $CM --out out --commit '0123456789:bcdef0123456789abcdef01234567'
55- matmul --m 16 --k 16 --n 8 --contract-id $CM --out out --commit '0123456789\`bcdef0123456789abcdef01234567'
56- matmul --m 16 --k 16 --n 8 --contract-id $AT --out out --commit $G
57- matmul --m 16 --k 16 --n 8 --contract-id $(printf %.63s $CM)5 --out out --commit $G
58- attention --q-heads 8 --kv-heads 8 --contract-id $CM --out out --commit $G
59- attention --q-heads 8 --kv-heads 8 --contract-id $(printf %.63s $AT)8 --out out --commit $G
60- other --m 16 --k 16 --n 8 --contract-id $CM --out out --commit $G
61- matmu --m 16 --k 16 --n 8 --contract-id $CM --out out --commit $G
62- matmull --m 16 --k 16 --n 8 --contract-id $CM --out out --commit $G
63- attentio --q-heads 8 --kv-heads 8 --contract-id $AT --out out --commit $G
64- matmul --m 8208 --k 16 --n 8 --contract-id $CM --out out --commit $G
65- matmul --m 16 --k 16400 --n 8 --contract-id $CM --out out --commit $G
66- matmul --m 16 --k 16 --n 8200 --contract-id $CM --out out --commit $G
67- matmul --m 8193 --k 16 --n 8 --contract-id $CM --out out --commit $G
68- matmul --m 16 --k 16385 --n 8 --contract-id $CM --out out --commit $G
69- matmul --m 16 --k 16 --n 8193 --contract-id $CM --out out --commit $G
70- matmul --m 0 --k 16 --n 8 --contract-id $CM --out out --commit $G
71- matmul --m 16 --k 0 --n 8 --contract-id $CM --out out --commit $G
72- matmul --m 16 --k 16 --n 0 --contract-id $CM --out out --commit $G
73- matmul --k 16 --n 8 --contract-id $CM --out out --commit $G
74- matmul --m 17 --k 16 --n 8 --contract-id $CM --out out --commit $G
75- matmul --m 16 --k 17 --n 8 --contract-id $CM --out out --commit $G
76- matmul --m 16 --k 16 --n 9 --contract-id $CM --out out --commit $G
77- matmul --m 16 --k 24 --n 8 --contract-id $CM --out out --commit $G
78- matmul --m 24 --k 16 --n 8 --contract-id $CM --out out --commit $G
79- matmul --m 16 --k 16 --n 12 --contract-id $CM --out out --commit $G
80- matmul --m 16 --k 16 --n 8 --contract-id $CM --out out --commit $G
81- matmul --m 32 --k 16 --n 64 --contract-id $CM --out out --commit $G
82- matmul --m 64 --k 2048 --n 512 --contract-id $CM --out out --commit $G
83- matmul --m 16 --k 32 --n 8 --contract-id $CM --out out --commit $G
84- matmul --m 8192 --k 16384 --n 8192 --contract-id $CM --out out --commit $G
85- matmul --m 8192 --k 32 --n 16 --contract-id $CM --out out --commit $G
86- matmul --m 8192 --k 32 --n 8 --contract-id $CM --out out --commit $G
87- matmul --m 512 --k 32 --n 1024 --contract-id $CM --out out --commit $G
88- matmul --m 256 --k 48 --n 520 --contract-id $CM --out out --commit $G
89- matmul --m 8192 --k 16 --n 8192 --contract-id $CM --out out --commit $G
90- matmul --m ' 16' --k ' 16' --n '+8' --contract-id $CM --out out --commit $G
91- matmul --m 0x10 --k 0X10 --n 010 --contract-id $CM --out out --commit $G
92- matmul --m 0x1F --k 16 --n 8 --contract-id $CM --out out --commit $G
93- matmul --m 0x --k 16 --n 8 --contract-id $CM --out out --commit $G
94- matmul --m 0xg --k 16 --n 8 --contract-id $CM --out out --commit $G
95- matmul --m 08 --k 16 --n 8 --contract-id $CM --out out --commit $G
96- matmul --m 020 --k 16 --n 8 --contract-id $CM --out out --commit $G
97- matmul --m '16 ' --k 16 --n 8 --contract-id $CM --out out --commit $G
98- matmul --m '' --k 16 --n 8 --contract-id $CM --out out --commit $G
99- matmul --m 1e3 --k 16 --n 8 --contract-id $CM --out out --commit $G
100- matmul --m -16 --k 16 --n 8 --contract-id $CM --out out --commit $G
101- matmul --m -0 --k 16 --n 8 --contract-id $CM --out out --commit $G
102- matmul --m 16 --k 16 --n -18446744073709551608 --contract-id $CM --out out --commit $G
103- matmul --m 16 --k 16 --n -18446744073709551616 --contract-id $CM --out out --commit $G
104- matmul --m 4294967295 --k 16 --n 8 --contract-id $CM --out out --commit $G
105- matmul --m 4294967296 --k 16 --n 8 --contract-id $CM --out out --commit $G
106- matmul --m 18446744073709551615 --k 16 --n 8 --contract-id $CM --out out --commit $G
107- matmul --m 18446744073709551616 --k 16 --n 8 --contract-id $CM --out out --commit $G
108- matmul --m 99999999999999999999999 --k 16 --n 8 --contract-id $CM --out out --commit $G
109- matmul --m 18446744073709551632 --k 16 --n 8 --contract-id $CM --out out --commit $G
110- matmul --m -18446744073709551632 --k 16 --n 8 --contract-id $CM --out out --commit $G
111- matmul --m 00000000000000000000000000000016 --k 16 --n 8 --contract-id $CM --out out --commit $G
112- matmul --m 0x00000000000000000000000000000010 --k 16 --n 8 --contract-id $CM --out out --commit $G
113- matmul --m ' - 16' --k 16 --n 8 --contract-id $CM --out out --commit $G
114- matmul --m +-16 --k 16 --n 8 --contract-id $CM --out out --commit $G
115- matmul --m 32 --m 16 --k 16 --n 8 --contract-id $AT --contract-id $CM --out x --out out --commit 1 --commit $G
116- matmul --m 16 --k 16 --n 8 --q-heads 3 --kv-heads 999 --contract-id $CM --out out --commit $G
117- attention --q-heads 8 --kv-heads 8 --contract-id $AT --out out --commit $G
118- attention --q-heads 16 --kv-heads 8 --contract-id $AT --out out --commit $G
119- attention --q-heads 32 --kv-heads 8 --contract-id $AT --out out --commit $G
120- attention --q-heads 64 --kv-heads 8 --contract-id $AT --out out --commit $G
121- attention --q-heads 64 --kv-heads 16 --contract-id $AT --out out --commit $G
122- attention --q-heads 64 --kv-heads 32 --contract-id $AT --out out --commit $G
123- attention --q-heads 64 --kv-heads 64 --contract-id $AT --out out --commit $G
124- attention --q-heads 32 --kv-heads 1 --contract-id $AT --out out --commit $G
125- attention --q-heads 64 --kv-heads 1 --contract-id $AT --out out --commit $G
126- attention --q-heads 4 --kv-heads 1 --contract-id $AT --out out --commit $G
127- attention --q-heads 2 --kv-heads 1 --contract-id $AT --out out --commit $G
128- attention --q-heads 1 --kv-heads 1 --contract-id $AT --out out --commit $G
129- attention --q-heads 12 --kv-heads 4 --contract-id $AT --out out --commit $G
130- attention --q-heads 48 --kv-heads 1 --contract-id $AT --out out --commit $G
131- attention --q-heads 24 --kv-heads 4 --contract-id $AT --out out --commit $G
132- attention --q-heads 0 --kv-heads 8 --contract-id $AT --out out --commit $G
133- attention --q-heads 8 --kv-heads 0 --contract-id $AT --out out --commit $G
134- attention --q-heads 8 --kv-heads 3 --contract-id $AT --out out --commit $G
135- attention --q-heads 65 --kv-heads 1 --contract-id $AT --out out --commit $G
136- attention --q-heads 1 --kv-heads 65 --contract-id $AT --out out --commit $G
137- attention --q-heads 64 --kv-heads 65 --contract-id $AT --out out --commit $G
138- attention --kv-heads 8 --contract-id $AT --out out --commit $G
139- attention --q-heads 0x40 --kv-heads 010 --contract-id $AT --out out --commit $G
140- attention --q-heads 8 --kv-heads 8 --m 1 --contract-id $AT --out out --commit $G
141exists matmul --m 16 --k 16 --n 8 --contract-id $CM --out out --commit $G
142link matmul --m 16 --k 16 --n 8 --contract-id $CM --out out --commit $G
143nodir matmul --m 16 --k 16 --n 8 --contract-id $CM --out missing/out --commit $G
144exists attention --q-heads 8 --kv-heads 8 --contract-id $AT --out out --commit $G
145- matmul --m 16 --k 16 --n 8 --contract-id $CM --out $LONG --commit $G
146- matmul --m 16 --k 16 --n 8 --contract-id $CM --out '' --commit $G
147EOF
148
149one() { # BIN SETUP ARGS...: the report of one case
150 bin=$1 setup=$2
151 shift 2
152 d="$tmp/run"
153 rm -rf "$d"; mkdir -p "$d"
154 case $setup in
155 exists) : > "$d/out.cubin" ;;
156 link) ln -s /nonexistent "$d/out.manifest" ;;
157 esac
158 rc=0
159 (cd "$d" && "$bin" "$@" < /dev/null > "$tmp/o" 2> "$tmp/e") || rc=$?
160 echo "case $setup $(printf '%s|' "$@" | cut -c1-200)"
161 sed 's/^/ out /' "$tmp/o"
162 sed 's/^/ err /' "$tmp/e"
163 echo " exit $rc"
164 (cd "$d" && find . \( -type f -o -type l \) | LC_ALL=C sort | while read -r f; do
165 if [ -L "$f" ]; then echo " link $f"; else echo " file $f $(wc -c < "$f") $(sha256sum < "$f" | cut -c1-64)"; fi
166 done)
167}
168run() { # BIN OUT: every case of $tmp/cases
169 bin=$1
170 while IFS= read -r line; do
171 eval "set -- $line"
172 one "$bin" "$@"
173 done < "$tmp/cases" > "$2"
174}
175run "$tmp/ae_c" "$tmp/c.out"
176run "$tmp/ae_om" "$tmp/om.out"
177cmp "$tmp/c.out" "$tmp/om.out" || { echo "FAIL artexp differential"; diff "$tmp/c.out" "$tmp/om.out" | head -20; exit 1; }
178cases=$(grep -c '^case ' "$tmp/c.out")
179files=$(grep -c '^ file ' "$tmp/c.out")
180outs=$(grep '^ exit ' "$tmp/c.out" | sort | uniq -c | tr -s ' \n' ' ')
181grep -q '^ out artifact_id=' "$tmp/c.out" || { echo "FAIL artexp oracle exported nothing"; exit 1; }
182echo "differential: $cases cases identical, $files files written (exits:$outs)"
183tom_flip "$tmp/c.out" "$tmp/om.out"
184
185killed=0
186mut() { # NAME SITE REPLACEMENT
187 tom_mutant "$1" om/tools/artexp.om "$2" "$3"
188 $CC $TOM_CFLAGS -o "$tmp/$1.bin" $SRC "$tmp/$1.c" $LIBS
189 run "$tmp/$1.bin" "$tmp/$1.out"
190 if cmp -s "$tmp/c.out" "$tmp/$1.out"; then echo "FAIL mutant $1 survived"; exit 1; fi
191 echo "mutant $1: killed ($(diff "$tmp/c.out" "$tmp/$1.out" | grep -m1 '^[<>]' | cut -c1-60))"
192 killed=$((killed + 1))
193}
194mut ktile 'if ne rem k 16 0' 'if ne rem k 8 0'
195mut single 'if eq get s 14 16' 'if eq get s 14 32'
196mut colgrid 'gx = div n 8' 'gx = div n 16'
197mut hexbase 'b = ulong 16' 'b = ulong 10'
198mut overflow 'ov = ulong 1' 'ov = ulong 0'
199mut u32max 'if gt v 4294967295' 'if gt v 4294967296'
200mut shared 'sh = and mul sh 512 4294967295' 'sh = and mul sh 256 4294967295'
201mut lowhex 'if not or and ge c 48 le c 57 and ge c 97 le c 102' 'if not or and ge c 48 le c 57 and ge c 97 le c 101'
202mut pow2 'while lt shl ulong 1 l r bound 64' 'while le shl ulong 1 l r bound 64'
203mut hbound 'if gt get s 17 64' 'if gt get s 17 63'
204echo "artexp mutants: $killed killed"
205
206if [ -n "${TOOLS_OM_COVERAGE:-}" ]; then
207 mkdir -p "$TOOLS_OM_COVERAGE" "$tmp/cov"
208 cp $SRC "$tmp/cov/artifact_export.c"
209 (cd "$tmp/cov" && $CC -std=gnu11 -D_GNU_SOURCE -O0 --coverage -I"$ROOT/src" $OFF -o ae_cov artifact_export.c \
210 "$ROOT/src/omega_native_artifact.c" "$ROOT/src/omega_cubin.c" "$tmp/b/libomega_gpu.a" -lpthread -lm)
211 run "$tmp/cov/ae_cov" "$tmp/cov/r.out"
212 cmp -s "$tmp/c.out" "$tmp/cov/r.out" || { echo "FAIL artexp coverage build differs from the oracle"; exit 1; }
213 (cd "$tmp/cov" && gcov -b -c ae_cov-artifact_export.c > "$TOOLS_OM_COVERAGE/artexp.gcov.txt" 2>&1)
214 cp "$tmp/cov/artifact_export.c.gcov" "$TOOLS_OM_COVERAGE/artifact_export.c.gcov"
215 echo "coverage: $TOOLS_OM_COVERAGE/artexp.gcov.txt"
216fi
217echo "tools-om artexp: PASS (differential $cases cases, $files files, negative control, $killed mutants killed)"