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 / host-trace / run-host-trace.sh

139 lines · 9174 bytes Raw Blame History
1#!/bin/sh
2# Host checks for the unified trace (docs/trace/UNIFIED_TRACE.md). No device is opened.
3#
4# Every check is a seeded Omega program compiled by the pinned seed compiler; this script only
5# composes units, runs them and compares exit codes and output lines. It also applies ten
6# deliberate source mutations (four trace, six batch) and requires each to make a check fail
7# (negative controls).
8#
9# Usage: OMEGA_COMPILER=/path/to/seed/out/omc sh tests/host-trace/run-host-trace.sh [OUTDIR]
10# OUTDIR keeps the sample trace files (default: a temporary directory, removed on exit).
11set -eu
12root=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)
13compiler=${OMEGA_COMPILER:-}
14[ -n "$compiler" ] && [ -x "$compiler" ] || {
15 echo 'OMEGA_COMPILER must name the pinned seed compiler (seed/out/omc)' >&2
16 exit 69
17}
18work=${TMPDIR:-/tmp}/cudapp-host-trace.$$
19mkdir -p "$work"
20trap 'rm -rf -- "$work"' EXIT HUP INT TERM
21out=${1:-$work/out}
22mkdir -p "$out"
23t=$root/tests/host-trace
24n=$root/native
25echo "compiler $(sha256sum "$compiler" | cut -d' ' -f1)"
26fail() { echo "FAIL: $*" >&2; exit 1; }
27build() { # build NAME FILE...
28 name=$1; shift
29 cat "$@" > "$work/$name.om"
30 "$compiler" < "$work/$name.om" > "$work/$name" || return 1
31 chmod +x "$work/$name"
32}
33launch_units="$t/fakenv.om $n/blackwell/vector.om $n/blackwell/launch.om $t/fakedev.om $n/trace/htrec.om $n/trace/htlaunch.om $t/launch-test.om"
34
35# 1. recorder
36build recorder "$n/trace/htrec.om" "$t/recorder-test.om" || fail 'recorder-test does not compile'
37"$work/recorder" > "$work/recorder.out" || fail "recorder-test exit $?: $(cat "$work/recorder.out")"
38grep -qx 'HOSTTRACE_RECORDER_PASS [0-9]*' "$work/recorder.out" || fail 'recorder-test'
39echo "recorder: $(cat "$work/recorder.out")"
40
41# 2. omtrace itself, then the launch test traced end to end (compile phases + runtime fragment)
42build omtrace "$n/trace/htrec.om" "$root/tools/omtrace/omtrace.om" || fail 'omtrace does not compile'
43cd "$root"
44# shellcheck disable=SC2086
45"$work/omtrace" f "$compiler" "$out/launch" "$out/launch.otr" $launch_units > "$work/launch.out" 2>&1 ||
46 fail "omtrace f exit $?: $(cat "$work/launch.out")"
47grep -qx 'HOSTTRACE_LAUNCH_PASS [0-9]*' "$work/launch.out" || fail "launch-test: $(cat "$work/launch.out")"
48grep -qx 'OMTRACE_OK [0-9]*' "$work/launch.out" || fail 'omtrace f did not report OK'
49echo "launch: $(paste -sd' ' "$work/launch.out")"
50for k in '"cat":"kernel.launch"' '"stage_name":"host.wait"' '"cat":"mem.copy"' '"name":"omc.compile"' \
51 '"name":"device.timing.NOT_RUN"' '"name":"kernel:VECTOR_1D/vector.om:gbvec"'; do
52 grep -qF "$k" "$out/launch.trace.json" || fail "trace lacks $k"
53done
54grep -qF '"parentSpanId":"' "$out/launch.otlp.json" || fail 'otlp has no parent links'
55"$work/omtrace" v "$out/launch.otr" > /dev/null 2>&1 || fail 'the recorded fragment does not validate'
56grep -qF '"dropped":0,"refused":0,"open_spans":0}' "$out/launch.trace.json" || fail 'clean trace reports losses'
57# a full recording that lost events must say so in both exports (and must export at all)
58"$work/omtrace" f "$compiler" "$work/lossy" "$work/lossy.otr" "$n/trace/htrec.om" "$t/lossy.om" \
59 > "$work/lossy.out" 2>&1 || fail "omtrace f on the lossy fixture exit $?: $(cat "$work/lossy.out")"
60grep -qF '"dropped":2,"refused":1,"open_spans":1}' "$work/lossy.trace.json" || fail 'chrome export hides losses'
61for k in '"aien.dropped","value":{"intValue":"2"}' '"aien.refused","value":{"intValue":"1"}' \
62 '"aien.open_spans","value":{"intValue":"1"}'; do
63 grep -qF "$k" "$work/lossy.otlp.json" || fail "otlp export lacks $k"
64done
65echo "lossy: $(cat "$work/lossy.out") with dropped 2, refused 1, open_spans 1 in both exports"
66
67# 3. compile diagnostics and traps are located in the unit that caused them
68printf 'fn f a ulong to ulong\nif gt a 3\ntrap 3\nend\nret a\nend\n' > "$work/t1.om"
69printf 'fn main to int\nr = f 9\nret 0\nend\n' > "$work/t2.om"
70printf 'om2 diag\nfn main to int\nret int add zz 1\nend\n' > "$work/d2.om"
71s=0; "$work/omtrace" r "$compiler" "$work/trap" - "$work/t1.om" "$work/t2.om" > /dev/null 2>&1 || s=$?
72[ "$s" = 0 ] || fail "omtrace r on a trapping program exit $s"
73grep -qF '"trap_name":"range","candidates":"'"$work"'/t1.om:3"' "$work/trap.trace.json" || fail 'trap not located'
74s=0; "$work/omtrace" c "$compiler" "$work/diag" - "$work/d2.om" > /dev/null 2>&1 || s=$?
75[ "$s" = 3 ] || fail "omtrace c on a failing unit exit $s, expected 3"
76grep -qF '"status":3,"line":3,"col":13,"file":"'"$work"'/d2.om"' "$work/diag.trace.json" || fail 'diagnostic not located'
77echo 'locate: trap and diagnostic located'
78
79# 4. malformed fragments: each mutant must be rejected with its own reason
80build badfrag "$t/badfrag.om" || fail 'badfrag does not compile'
81"$work/badfrag" "$out/launch.otr" "$work/mut" || fail 'badfrag could not write mutants'
82expect='20 21 22 23 24 25 26 27 28 29 30 31 27'
83m=0
84for e in $expect; do
85 s=0; "$work/omtrace" v "$work/mut.$m.otr" > /dev/null 2>&1 || s=$?
86 [ "$s" = "$e" ] || fail "mutant $m exit $s, expected $e"
87 m=$((m + 1))
88done
89s=0; "$work/omtrace" v "$work/missing.otr" > /dev/null 2>&1 || s=$?
90[ "$s" = 6 ] || fail "missing fragment exit $s, expected 6"
91echo "reject: $m malformed fragments rejected with distinct reasons, missing file exit 6"
92
93# 5. source mutations: each must turn a passing check into a failing one
94mutate() { # mutate FILE OLDLINE NEWLINE OUT
95 awk -v old="$2" -v new="$3" '$0 == old { print new; hit++; next } { print } END { exit hit != 1 }' "$1" > "$4" ||
96 fail "mutation anchor not found once in $1: $2"
97}
98# A mutant that no longer compiles proves nothing, so each must compile and then fail its check.
99killed() { # killed NAME MUTATED-SOURCE FILE...: build, run; true when the run fails
100 name=$1; shift
101 build "$name" "$@" || fail "mutant $name does not compile"
102 ! "$work/$name" > /dev/null 2>&1
103}
104mutate "$n/trace/htrec.om" 'if ne get htfl i 0' 'if false' "$work/m1.src"
105killed m1 "$work/m1.src" "$t/recorder-test.om" || fail 'mutant: second end accepted, test still passes'
106mutate "$n/trace/htrec.om" 'ret or or eq b 58 eq b 47 eq b 45' 'ret true' "$work/m2.src"
107killed m2 "$work/m2.src" "$t/recorder-test.om" || fail 'mutant: any name byte accepted, test still passes'
108mutate "$n/trace/htrec.om" 'ret eq get htst 0 1' 'ret true' "$work/m3.src"
109killed m3 "$work/m3.src" "$t/recorder-test.om" || fail 'mutant: recorder on by default, test still passes'
110mutate "$root/tools/omtrace/omtrace.om" 'if lt t1 t0' 'if false' "$work/m4.src"
111build m4 "$n/trace/htrec.om" "$work/m4.src" || fail 'mutant m4 does not compile'
112s=0; "$work/m4" v "$work/mut.8.otr" > /dev/null 2>&1 || s=$?
113[ "$s" != 28 ] || fail 'mutant: end-before-start check removed, still rejected as time'
114echo 'mutations: 4 of 4 compile and are detected'
115# 6. Native launch batches: actual packet bytes, one kick/wait, refusal and index attribution.
116# The coordinator remains migration debt; policy, queue model and every new check are Omega.
117batch_units="$t/batch-fake.om $n/blackwell/vector.om $n/blackwell/launch.om"
118build batch $batch_units "$n/blackwell/batch.om" "$t/batch-device.om" "$t/batch-test.om" || fail 'batch does not compile'
119"$work/batch" > "$out/batch.txt" || fail "batch: $(cat "$out/batch.txt")"
120grep -qx 'BATCH_HOST_PASS checks=[0-9]* parity_cases=32 parity_bytes=[0-9]* batch_launches=287 kicks=1 waits=1 negatives=8' "$out/batch.txt" || fail 'batch output'
121cat "$out/batch.txt"
122mutate "$n/blackwell/batch.om" 'if gt dep idx' 'if false' "$work/bdep.src"
123killed bdep $batch_units "$work/bdep.src" "$t/batch-device.om" "$t/batch-test.om" || fail 'batch: dependency mutant survived'
124mutate "$n/blackwell/batch.om" 'if or eq count 0 gt count 512' 'if eq count 0' "$work/bcap.src"
125killed bcap $batch_units "$work/bcap.src" "$t/batch-device.om" "$t/batch-test.om" || fail 'batch: capacity mutant survived'
126mutate "$n/blackwell/batch.om" 'put gbst 4 i' 'put gbst 4 n' "$work/bindex.src"
127killed bindex $batch_units "$work/bindex.src" "$t/batch-device.om" "$t/batch-test.om" || fail 'batch: index mutant survived'
128mutate "$n/blackwell/batch.om" 'gbemit 4113' 'gbemit 0' "$work/border.src"
129killed border $batch_units "$work/border.src" "$t/batch-device.om" "$t/batch-test.om" || fail 'batch: cache ordering mutant survived'
130mutate "$n/blackwell/batch.om" 'if gt add n get gbst 2 1048476' 'if false' "$work/bbyte.src"
131killed bbyte $batch_units "$work/bbyte.src" "$t/batch-device.om" "$t/batch-test.om" || fail 'batch: byte capacity mutant survived'
132mutate "$n/blackwell/launch.om" 'm = nvalloc size ge i 5' 'm = nvalloc size true' "$work/bcache.src"
133killed bcache "$t/batch-fake.om" "$n/blackwell/vector.om" "$work/bcache.src" "$n/blackwell/batch.om" "$t/batch-device.om" "$t/batch-test.om" || fail 'batch: GPU-cache attribute mutant survived'
134echo 'batch mutations: 6 of 6 compile and are detected'
135build batchwait "$n/nvrm/context.om" "$t/batch-wait-test.om" || fail 'native batch wait does not compile'
136"$work/batchwait" > "$out/batch-wait.txt" || fail 'native batch wait failed'
137grep -qx 'BATCH_NATIVE_WAIT_PASS completion timeout refusal' "$out/batch-wait.txt" || fail 'native batch wait output'
138cat "$out/batch-wait.txt"
139echo 'HOST TRACE CHECKS PASS'