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 / c5 / chip.sh

77 lines · 4421 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# C5 sharing and recovery on a GB10 (docs/OMEGA.md row C5), one hold of the GB10 lock:
4# 01 values build/gpu_isolation_test --values-only: our two processes side by side, both right
5# 02 mutant build/gpu_isolation_test_mutant --values-only: red control, the values check must fail (exit 1)
6# 03 hang build/gpu_isolation_test (chip tier): never-ending kernel times out, latch refusal (red check),
7# recover, correct launches in the same process, stale command list refused (red check), two
8# processes, and a hang in one process beside a working one
9# 04 cuda build/c5_matrix c: our two processes beside a CUDA (PyTorch) process
10# 05 pressure build/c5_matrix p: the same while the CUDA process holds 16 GiB of device memory
11# 06 kill build/c5_matrix k: our process SIGKILLed 500 ms into its never-ending launch beside a CUDA process
12# 07 red build/c5_matrix r: the CUDA process against a wrong expectation must exit 1
13# 08 health build/gpu_isolation_test --values-only again, after everything
14# Kernel log lines added during the hold go to dmesg.txt; Xid / NVRM / watchdog lines to xid.txt.
15#
16# tools/c5/build.sh (outside the lock, or the c5-sharing workflow artifact)
17# tools/c5/chip.sh OUTDIR (takes /tmp/aien-gb10.lock itself)
18# Exit 0 only when every step ended as expected.
19set -u
20OUT=${1:?usage: tools/c5/chip.sh OUTDIR}
21B=${BUILD:-build}
22PY=${PY:-$HOME/.venv/bin/python}
23LOCK=${LOCK:-/tmp/aien-gb10.lock}
24for f in "$B/gpu_isolation_test" "$B/gpu_isolation_test_mutant" "$B/c5_matrix"; do
25 [ -x "$f" ] || { echo "NOT_RUN: $f is not built" >&2; exit 2; }
26done
27[ -x "$PY" ] || { echo "NOT_RUN: no Python at $PY for the CUDA tenant" >&2; exit 2; }
28mkdir -p "$OUT"
29S="$OUT/summary.txt"
30{
31 sha256sum "$B/gpu_isolation_test" "$B/gpu_isolation_test_mutant" "$B/c5_matrix"
32 echo "driver $(cat /sys/module/nvidia/version 2>/dev/null || echo unknown)"
33 echo "cuda tenant $("$PY" -c 'import torch; print("torch", torch.__version__, "cuda", torch.version.cuda)' 2>&1 | tail -1)"
34} > "$S"
35
36exec 9>"$LOCK"
37flock -w 900 9 || { echo "NOT_RUN: GB10 lock busy for 900 s" >&2; exit 2; }
38echo "start $(date -u +%Y-%m-%dT%H:%M:%SZ) loadavg $(cat /proc/loadavg)" >> "$S"
39# the kernel ring buffer is full and rotates, so a line-count baseline loses lines: filter by timestamp instead
40since=$(date +%Y-%m-%dT%H:%M:%S,%6N)
41fails=0
42step() { # name want_rc command...
43 name=$1; want=$2; shift 2
44 log="$OUT/$name.log"
45 { echo "loadavg $(cat /proc/loadavg)"; echo "cmd $*"; } > "$log"
46 rc=0
47 timeout -k 10 300 "$@" >> "$log" 2>&1 || rc=$?
48 echo "exit $rc" >> "$log"
49 v=$(grep -E '^C5 (isolation|matrix)' "$log" | tail -1)
50 if [ "$rc" -eq "$want" ]; then r=ok; else r=FAIL; fails=$((fails + 1)); fi
51 echo "$r $name exit $rc (want $want) ${v:-no verdict line}" >> "$S"
52}
53step 01-values 0 "$B/gpu_isolation_test" --values-only
54step 02-mutant 1 "$B/gpu_isolation_test_mutant" --values-only
55step 03-hang 0 "$B/gpu_isolation_test"
56step 04-cuda 0 "$B/c5_matrix" "$(pwd)/$B/gpu_isolation_test" "$PY" c
57step 05-pressure 0 "$B/c5_matrix" "$(pwd)/$B/gpu_isolation_test" "$PY" p
58step 06-kill 0 "$B/c5_matrix" "$(pwd)/$B/gpu_isolation_test" "$PY" k
59step 07-red 0 "$B/c5_matrix" "$(pwd)/$B/gpu_isolation_test" "$PY" r
60# the red control counts only when the values check is what failed: wrong values reported, not a setup error
61if grep -qE 'FAIL: process [12]: .* [1-9][0-9]* wrong values' "$OUT/02-mutant.log"; then
62 echo "ok 02-mutant red because of wrong values" >> "$S"
63else
64 echo "FAIL 02-mutant did not fail on wrong values" >> "$S"; fails=$((fails + 1))
65fi
66step 08-health 0 "$B/gpu_isolation_test" --values-only
67sudo -n dmesg --time-format iso 2>/dev/null | awk -v s="$since" '$1 >= s' > "$OUT/dmesg.txt"
68grep -E 'Xid|NVRM|watchdog|GPU has fallen|nvidia' "$OUT/dmesg.txt" > "$OUT/xid.txt" || true
69nvidia-smi --query-compute-apps=pid,process_name,used_memory --format=csv > "$OUT/compute-apps-after.txt" 2>&1 || true
70flock -u 9
71{
72 echo "end $(date -u +%Y-%m-%dT%H:%M:%SZ)"
73 echo "kernel log lines during the hold: $(wc -l < "$OUT/dmesg.txt"), Xid/NVRM/watchdog lines: $(wc -l < "$OUT/xid.txt")"
74 echo "checks not as expected: $fails of 9 (8 steps and the mutant's cause)"
75} >> "$S"
76cat "$S"
77[ "$fails" -eq 0 ]