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
CUDApp / tests / smi / live.sh
| 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>). |
| 10 | set -u |
| 11 | omc=${1:?usage: live.sh OMC OUTDIR} |
| 12 | o=${2:?usage: live.sh OMC OUTDIR} |
| 13 | here=$(cd "$(dirname "$0")/../.." && pwd) |
| 14 | pin=390629fd22590aaefca852045f8b0ace86c62cefb3b1bc203ce400773c8abc2f |
| 15 | got=$(sha256sum "$omc") || exit 74 |
| 16 | if [ "${got%% *}" != "$pin" ]; then echo "REFUSED: omc digest ${got%% *} is not the omega-mv#1048 candidate (e9b63587)" >&2; exit 69; fi |
| 17 | mkdir -p "$o" || exit 3 |
| 18 | bin=$(mktemp -d)/cudapp-smi |
| 19 | cat "$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; } |
| 21 | chmod +x "$bin" |
| 22 | "$bin" > "$o/cudapp-smi.txt"; rc=$? |
| 23 | q='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' |
| 24 | nvidia-smi --query-gpu="$q" --format=csv,noheader > "$o/nvidia-smi-gpu.csv" || { echo 'CUDAPP-SMI LIVE FAIL (nvidia-smi)'; exit 1; } |
| 25 | nvidia-smi --query-compute-apps=pid,process_name,used_memory --format=csv,noheader > "$o/nvidia-smi-apps.csv" || exit 1 |
| 26 | nvidia-smi -q > "$o/nvidia-smi-q.txt" || exit 1 |
| 27 | if [ "$rc" -ne 0 ]; then echo "CUDAPP-SMI LIVE FAIL (cudapp-smi rc=$rc)"; exit 1; fi |
| 28 | if [ "$(wc -l < "$o/nvidia-smi-gpu.csv")" -ne 1 ]; then echo 'CUDAPP-SMI LIVE FAIL (expects one GPU)'; exit 1; fi |
| 29 | |
| 30 | ours() { sed -n "s/^$1=//p" "$o/cudapp-smi.txt"; } |
| 31 | theirs() { awk -F', ' -v i="$1" '{print $i}' "$o/nvidia-smi-gpu.csv"; } |
| 32 | qline() { awk -F': ' -v k="$1" 'index($1, k) && !s {sub(/[ \t]+$/, "", $2); print $2; s=1}' "$o/nvidia-smi-q.txt"; } |
| 33 | bad=0; n=0 |
| 34 | printf 'field\tcudapp-smi\tnvidia-smi\tverdict\n' > "$o/compare.tsv" |
| 35 | row() { # 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 | } |
| 39 | same() { if [ "$2" = "$3" ]; then row "$1" "$2" "$3" MATCH; else row "$1" "$2" "$3" DIFF; fi; } |
| 40 | num() { if [ "$(printf '%d' "$2")" = "$(printf '%d' "$3")" ]; then row "$1" "$2" "$3" MATCH; else row "$1" "$2" "$3" DIFF; fi; } |
| 41 | |
| 42 | same driver_version "$(ours driver_version)" "$(theirs 1)" |
| 43 | same count "$(ours count)" "$(theirs 2)" |
| 44 | i=3 |
| 45 | for 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)) |
| 47 | done |
| 48 | num pci.sub_device_id "$(ours gpu.0.pci.sub_device_id)" "$(theirs 10)" |
| 49 | same pci.baseClass "$(ours gpu.0.pci.base_classcode)" "$(theirs 11)" |
| 50 | same pci.subClass "$(ours gpu.0.pci.sub_classcode)" "$(theirs 12)" |
| 51 | i=13 |
| 52 | for 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)) |
| 54 | done |
| 55 | same minor_number "$(ours gpu.0.minor_number)" "$(qline 'Minor Number')" |
| 56 | same 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. |
| 58 | row name "$(ours gpu.0.name)" "$(theirs 17)" RM_NOT_RUN |
| 59 | row temperature.gpu "$(ours gpu.0.temperature.gpu)" "$(theirs 18)" RM_NOT_RUN |
| 60 | row pstate "$(ours gpu.0.pstate)" "$(theirs 19)" RM_NOT_RUN |
| 61 | row utilization.gpu "$(ours gpu.0.utilization.gpu)" "$(theirs 20)" RM_NOT_RUN |
| 62 | row 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. |
| 64 | while 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 |
| 71 | done < "$o/nvidia-smi-apps.csv" |
| 72 | sed -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. |
| 74 | u="$(ours gpu.0.uuid)x"; tu=$(theirs 7); ts=$(theirs 10) |
| 75 | nc=$(nb=$bad; o=$(mktemp -d); same uuid "$u" "$tu"; num pci.sub_device_id 0x10DF "$ts"; echo $((bad - nb))) |
| 76 | if [ "$nc" -ne 2 ]; then echo "CUDAPP-SMI LIVE FAIL (comparator negative control $nc/2)"; exit 1; fi |
| 77 | echo 'PASS comparator negative control (2/2 altered fields rejected)' |
| 78 | cat "$o/compare.tsv" |
| 79 | if [ "$bad" -eq 0 ]; then echo "CUDAPP-SMI LIVE PASS ($n fields)"; else echo "CUDAPP-SMI LIVE FAIL ($bad)"; exit 1; fi |