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

119 lines · 5561 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# Host test for `cudapp-doctor` (CUDA++ developer bar D2 and D6, docs/PAIN_POINTS.md).
4# usage: tests/doctor/run.sh build/cudapp-doctor (CUDAPP_DOCTOR_SHOW=1 also prints what each fake machine is told)
5# No GPU and no device file is opened: every case is a fake machine built under a temporary
6# folder and handed to the doctor through CUDAPP_DOCTOR_ROOT. Each case states the exit code
7# and the sentences a person must see. A case that passes with the wrong text is a failure.
8set -u
9DOC=${1:?usage: run.sh path/to/cudapp-doctor}
10T=$(mktemp -d "${TMPDIR:-/tmp}/cudapp-doctor-test.XXXXXX")
11trap 'rm -rf "$T"' EXIT
12pass=0; fail=0
13
14# make_machine DIR [module-version-line|none] [pci-device-id|none] [dev nodes...]
15make_machine() {
16 d=$1; ver=$2; pci=$3; shift 3
17 mkdir -p "$d/proc/driver/nvidia" "$d/sys/bus/pci/devices" "$d/dev"
18 if [ "$ver" != none ]; then
19 printf 'NVRM version: %s\nGCC version: gcc version 13.3.0\n' "$ver" > "$d/proc/driver/nvidia/version"
20 else
21 rmdir "$d/proc/driver/nvidia"
22 fi
23 if [ "$pci" != none ]; then
24 g="$d/sys/bus/pci/devices/000f:01:00.0"; mkdir -p "$g"
25 echo 0x10de > "$g/vendor"; echo "$pci" > "$g/device"; echo 0x030000 > "$g/class"
26 fi
27 # an unrelated non-NVIDIA device the doctor must ignore
28 o="$d/sys/bus/pci/devices/0000:00:00.0"; mkdir -p "$o"; echo 0x8086 > "$o/vendor"; echo 0x1234 > "$o/device"; echo 0x060000 > "$o/class"
29 printf 'MemTotal: 127535484 kB\nMemFree: 1000000 kB\nMemAvailable: 42000000 kB\n' > "$d/proc/meminfo"
30 for n in "$@"; do : > "$d/dev/$n"; chmod 666 "$d/dev/$n"; done
31}
32OPEN='NVIDIA UNIX Open Kernel Module for aarch64 580.173.02 Release Build (test) Tue Jun 23 08:34:19 UTC 2026'
33NODES='nvidiactl nvidia0 nvidia-uvm'
34
35# check NAME WANT_EXIT ROOT then one grep -F pattern per argument (all must appear)
36check() {
37 name=$1; want=$2; root=$3; shift 3
38 out=$(CUDAPP_DOCTOR_ROOT="$root" "$DOC" 2>&1); got=$?
39 [ -n "${CUDAPP_DOCTOR_SHOW:-}" ] && { echo "===== fake machine: $name (exit $got)"; printf "%s\n" "$out"; }
40 ok=1
41 [ "$got" -eq "$want" ] || { echo " exit $got, want $want"; ok=0; }
42 for pat in "$@"; do
43 printf '%s\n' "$out" | grep -qF -- "$pat" || { echo " missing: $pat"; ok=0; }
44 done
45 # D6: never the bare CUDA message, in any case
46 printf '%s\n' "$out" | grep -qi 'no kernel image' && ! printf '%s\n' "$out" | grep -qF 'instead of failing later' && { echo " bare 'no kernel image' text"; ok=0; }
47 if [ $ok -eq 1 ]; then pass=$((pass+1)); echo "PASS $name"; else fail=$((fail+1)); echo "FAIL $name"; printf '%s\n' "$out" | sed 's/^/ | /'; fi
48}
49
50# 1. a ready GB10
51make_machine "$T/gb10" "$OPEN" 0x2e12 $NODES
52check gb10-ready 0 "$T/gb10" \
53 'ok NVIDIA kernel module: open module 580.173.02' \
54 'ok GPU 000f:01:00.0: NVIDIA GB10 (sm_121), supported target' \
55 'historical summary: evidence/m16-blackwell-native-path-requalification-receipt.json' \
56 'raw M16 evidence unavailable; not current-commit qualification' \
57 'Diagnostic only: direct library use has no driver-version or PCI-ID admission guard.' \
58 'ok device files: /dev/nvidiactl /dev/nvidia0 /dev/nvidia-uvm' \
59 'CUDA toolkit: not needed' \
60 'READY. Next: make hello-gpu'
61
62# 2. no NVIDIA kernel module loaded
63make_machine "$T/nomod" none 0x2e12
64check no-module 1 "$T/nomod" \
65 'FAIL NVIDIA kernel module: not loaded' \
66 'sudo modprobe nvidia' \
67 'NOT READY'
68
69# 3. a different module version: our ioctl structures come from the 580.173.02 headers
70make_machine "$T/oldmod" 'NVIDIA UNIX Open Kernel Module for aarch64 575.64.05 Release Build (test)' 0x2e12 $NODES
71check module-version 1 "$T/oldmod" \
72 'FAIL NVIDIA kernel module: version 575.64.05 is loaded; CUDA++ speaks the 580.173.02 interface' \
73 'doctor refuses instead of guessing' \
74 'NOT READY'
75
76# 4. the proprietary (closed) module at the right version: allowed, with a warning
77make_machine "$T/closed" 'NVIDIA UNIX aarch64 Kernel Module 580.173.02 Release Build (test)' 0x2e12 $NODES
78check closed-module 0 "$T/closed" \
79 'warn NVIDIA kernel module: the closed module 580.173.02' \
80 'READY. Next: make hello-gpu'
81
82# 5. D6: a GPU CUDA++ has no machine code for. Refused with what is missing and what to do.
83make_machine "$T/newchip" "$OPEN" 0x2b85 $NODES
84check unknown-chip 1 "$T/newchip" \
85 'FAIL GPU 000f:01:00.0: NVIDIA device 0x2b85 is not one CUDA++ has qualified' \
86 'instead of failing later with "no kernel image is available"' \
87 'What is missing:' \
88 'docs/runtime/PORTABILITY.md section 5' \
89 'NOT READY'
90
91# 6. no NVIDIA GPU at all
92make_machine "$T/nogpu" "$OPEN" none $NODES
93check no-gpu 1 "$T/nogpu" \
94 'FAIL GPU: no NVIDIA GPU found in /sys/bus/pci/devices' \
95 'NOT READY'
96
97# 7. the unified-memory device file is missing
98make_machine "$T/nouvm" "$OPEN" 0x2e12 nvidiactl nvidia0
99check no-uvm 1 "$T/nouvm" \
100 'FAIL device files: /dev/nvidia-uvm is missing' \
101 'sudo modprobe nvidia-uvm' \
102 'NOT READY'
103
104# 8. a device file this user may not open
105make_machine "$T/perm" "$OPEN" 0x2e12 $NODES
106chmod 600 "$T/perm/dev/nvidia0"; chmod 000 "$T/perm/dev/nvidia0"
107if [ -r "$T/perm/dev/nvidia0" ]; then
108 echo "SKIP perm (running as root: every file is readable)"
109else
110 check no-permission 1 "$T/perm" \
111 'FAIL device files: /dev/nvidia0 exists but this user cannot open it for reading and writing' \
112 'NOT READY'
113fi
114
115# 9. the memory line on a unified-memory chip
116check memory-line 0 "$T/gb10" 'ok memory: 121.6 GiB shared by the CPU and the GPU, 40.1 GiB available now'
117
118echo "doctor tests: $pass passed, $fail failed"
119[ "$fail" -eq 0 ]