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 / smi / live.sh

79 lines · 5352 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# live.sh: read-only live tier for cudapp-smi. Builds cudapp-smi with the aien-dev/omega-mv#1048
4# candidate omc (native/smi/util.om needs its devcall bound), runs it WITHOUT --rm against the real
5# /proc and /sys, runs nvidia-smi read-only queries, and compares field by field.
6# Usage: sh tests/smi/live.sh OMC OUTDIR
7# Writes OUTDIR/{cudapp-smi.txt,nvidia-smi-gpu.csv,nvidia-smi-apps.csv,nvidia-smi-q.txt,compare.tsv}.
8# The resource-manager path (--rm) opens /dev/nvidiactl and /dev/nvidia0 and is never run here.
9# Last line: CUDAPP-SMI LIVE PASS (<n> fields) or CUDAPP-SMI LIVE FAIL (<n>).
10set -u
11omc=${1:?usage: live.sh OMC OUTDIR}
12o=${2:?usage: live.sh OMC OUTDIR}
13here=$(cd "$(dirname "$0")/../.." && pwd)
14pin=390629fd22590aaefca852045f8b0ace86c62cefb3b1bc203ce400773c8abc2f
15got=$(sha256sum "$omc") || exit 74
16if [ "${got%% *}" != "$pin" ]; then echo "REFUSED: omc digest ${got%% *} is not the omega-mv#1048 candidate (e9b63587)" >&2; exit 69; fi
17mkdir -p "$o" || exit 3
18bin=$(mktemp -d)/cudapp-smi
19cat "$here/native/smi/smi.om" "$here/native/nvrm/context.om" "$here/native/smi/util.om" "$here/native/smi/rm.om" | "$omc" > "$bin" || {
20 echo 'CUDAPP-SMI LIVE FAIL (build)'; exit 1; }
21chmod +x "$bin"
22"$bin" > "$o/cudapp-smi.txt"; rc=$?
23q='driver_version,count,pci.bus_id,pci.domain,pci.bus,pci.device,uuid,vbios_version,pci.device_id,pci.sub_device_id,pci.baseClass,pci.subClass,pcie.link.gen.current,pcie.link.gen.max,pcie.link.width.current,pcie.link.width.max,name,temperature.gpu,pstate,utilization.gpu,utilization.memory'
24nvidia-smi --query-gpu="$q" --format=csv,noheader > "$o/nvidia-smi-gpu.csv" || { echo 'CUDAPP-SMI LIVE FAIL (nvidia-smi)'; exit 1; }
25nvidia-smi --query-compute-apps=pid,process_name,used_memory --format=csv,noheader > "$o/nvidia-smi-apps.csv" || exit 1
26nvidia-smi -q > "$o/nvidia-smi-q.txt" || exit 1
27if [ "$rc" -ne 0 ]; then echo "CUDAPP-SMI LIVE FAIL (cudapp-smi rc=$rc)"; exit 1; fi
28if [ "$(wc -l < "$o/nvidia-smi-gpu.csv")" -ne 1 ]; then echo 'CUDAPP-SMI LIVE FAIL (expects one GPU)'; exit 1; fi
29
30ours() { sed -n "s/^$1=//p" "$o/cudapp-smi.txt"; }
31theirs() { awk -F', ' -v i="$1" '{print $i}' "$o/nvidia-smi-gpu.csv"; }
32qline() { awk -F': ' -v k="$1" 'index($1, k) && !s {sub(/[ \t]+$/, "", $2); print $2; s=1}' "$o/nvidia-smi-q.txt"; }
33bad=0; n=0
34printf 'field\tcudapp-smi\tnvidia-smi\tverdict\n' > "$o/compare.tsv"
35row() { # field ours theirs verdict
36 printf '%s\t%s\t%s\t%s\n' "$1" "$2" "$3" "$4" >> "$o/compare.tsv"
37 case $4 in MATCH) n=$((n + 1)) ;; DIFF) bad=$((bad + 1)) ;; esac
38}
39same() { if [ "$2" = "$3" ]; then row "$1" "$2" "$3" MATCH; else row "$1" "$2" "$3" DIFF; fi; }
40num() { if [ "$(printf '%d' "$2")" = "$(printf '%d' "$3")" ]; then row "$1" "$2" "$3" MATCH; else row "$1" "$2" "$3" DIFF; fi; }
41
42same driver_version "$(ours driver_version)" "$(theirs 1)"
43same count "$(ours count)" "$(theirs 2)"
44i=3
45for k in pci.bus_id pci.domain pci.bus pci.device uuid vbios_version pci.device_id; do
46 same "$k" "$(ours "gpu.0.$k")" "$(theirs $i)"; i=$((i + 1))
47done
48num pci.sub_device_id "$(ours gpu.0.pci.sub_device_id)" "$(theirs 10)"
49same pci.baseClass "$(ours gpu.0.pci.base_classcode)" "$(theirs 11)"
50same pci.subClass "$(ours gpu.0.pci.sub_classcode)" "$(theirs 12)"
51i=13
52for k in pcie.link.gen.current pcie.link.gen.max pcie.link.width.current pcie.link.width.max; do
53 same "$k" "$(ours "gpu.0.$k")" "$(theirs $i)"; i=$((i + 1))
54done
55same minor_number "$(ours gpu.0.minor_number)" "$(qline 'Minor Number')"
56same gsp_firmware_version "$(ours gpu.0.gsp_firmware_version)" "$(qline 'GSP Firmware Version')"
57# Without --rm these are [N/A] by design; the RM values are NOT_RUN on the live device.
58row name "$(ours gpu.0.name)" "$(theirs 17)" RM_NOT_RUN
59row temperature.gpu "$(ours gpu.0.temperature.gpu)" "$(theirs 18)" RM_NOT_RUN
60row pstate "$(ours gpu.0.pstate)" "$(theirs 19)" RM_NOT_RUN
61row utilization.gpu "$(ours gpu.0.utilization.gpu)" "$(theirs 20)" RM_NOT_RUN
62row utilization.memory "$(ours gpu.0.utilization.memory)" "$(theirs 21)" RM_NOT_RUN
63# Holders are every process with an open /dev/nvidia* node: a superset of nvidia-smi compute apps.
64while IFS=', ' read -r pid pname mem; do
65 [ -n "$pid" ] || continue
66 k=$(grep -x "gpu\.0\.holder\.[0-9]*\.pid=$pid" "$o/cudapp-smi.txt" | sed 's/^gpu\.0\.holder\.\([0-9]*\)\.pid=.*/\1/')
67 if [ -z "$k" ]; then row "compute_app.pid=$pid" '' "$pid" DIFF; continue; fi
68 row "compute_app.pid=$pid" "holder.$k" "$pid" MATCH
69 same "compute_app.$pid.process_name" "$(ours "gpu.0.holder.$k.process_name")" "$pname"
70 row "compute_app.$pid.used_memory" '[rm]' "$mem" RM_NOT_RUN
71done < "$o/nvidia-smi-apps.csv"
72sed -i "s#$HOME#~#g" "$o/cudapp-smi.txt" "$o/nvidia-smi-apps.csv" "$o/nvidia-smi-q.txt" "$o/compare.tsv"
73# Comparator negative control: an altered uuid and an altered sub-device id must both be DIFF.
74u="$(ours gpu.0.uuid)x"; tu=$(theirs 7); ts=$(theirs 10)
75nc=$(nb=$bad; o=$(mktemp -d); same uuid "$u" "$tu"; num pci.sub_device_id 0x10DF "$ts"; echo $((bad - nb)))
76if [ "$nc" -ne 2 ]; then echo "CUDAPP-SMI LIVE FAIL (comparator negative control $nc/2)"; exit 1; fi
77echo 'PASS comparator negative control (2/2 altered fields rejected)'
78cat "$o/compare.tsv"
79if [ "$bad" -eq 0 ]; then echo "CUDAPP-SMI LIVE PASS ($n fields)"; else echo "CUDAPP-SMI LIVE FAIL ($bad)"; exit 1; fi