interplane.Get Omega
Read in your language

omega-gpu-driver

aien-dev/omega-gpu-driver

Brought by drakestapleton

branch main Branches Tags History

omega-gpu-driver / window / d2-restore.sh

124 lines · 6798 bytes Raw Blame History
1#!/bin/sh
2# window/d2-restore.sh --go -- R: bring the resident 35B back on 18091 under nvidia.ko and remove every window
3# file. Status: NOT_RUN. Runs from the boot unit after the reboot that W7 ends with, directly from W7
4# (RESTORE_PATH=rebind), or from the W1 abort path. Safe to run again: each part checks before it acts.
5# R0 hold-back file still present: remove it and reboot (the unit runs R again)
6# R1 nvidia.ko back: unbind vfio-pci, clear driver_override, modprobe, bind, nvidia-smi lists the GB10.
7# Whether nvidia.ko re-initialises GSP after the FLR/bus reset of the vfio-pci release is NOT_RUN on this
8# chip, so any failure takes the reboot fallback once (state stays "restore", the unit runs R again).
9# R2 nvidia-persistenced running; kernel.panic / panic_on_oops back to the values W1 saved
10# R3 the 35B restarted exactly as it was started (W0 checked window/live-35b.snapshot against this recipe),
11# /v1/models lists qwen, one greedy chat, exactly one aien-serve-http on the GPU
12# R4 boot unit removed, privilege state clean, markers removed, BOARD line
13set -eu
14R=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
15. "$R/window/common.sh"
16LOG=$LOGDIR/d2-$(date -u +%Y%m%dT%H%M%SZ)-restore.log
17[ "${1:-}" = --go ] || { echo "usage: $0 --go"; exit 2; }
18was=$(cat "$STATE" 2>/dev/null || true)
19is_identity=false
20if [ "${2:-}" = W0 ] || [ "$was" = "restore W0" ] || [ "$was" = "run W0" ] || [ -e "$IDENTITY" ] || [ -e "$W0SUM" ]; then
21 is_identity=true
22 echo "restore W0" > "$STATE"
23else
24 echo restore > "$STATE"
25fi
26# Any refusal leaves state "restore" and the unit in place (the next boot tries R again) and says so on BOARD.
27trap 'rc=$?; [ "$rc" -eq 0 ] || board "restore STOPPED rc=$rc, 18091 may be down, log $LOG (page Main; next boot retries R)"' EXIT
28
29# R0 -------------------------------------------------------------------------
30# Identity windows have a two-reboot budget. A failed restore leaves evidence for attended recovery.
31identity_state=
32if "$is_identity"; then
33 identity_state=$(cat "$IDENTITY") || die "identity service record unavailable"
34 case $identity_state in up | down) ;; *) die "invalid identity service record" ;; esac
35fi
36if [ -e "$HOLD" ]; then
37 sudo -n rm -f "$HOLD"
38 [ -z "$identity_state" ] || die "removed remaining hold-back. Attended recovery required"
39 log "R0 hold-back file was still present: removed; rebooting; the boot unit runs R again"
40 board "restore: hold-back file was still present, removed, rebooting"
41 sync
42 sudo -n systemctl reboot
43 exit 0
44fi
45
46# R1 -------------------------------------------------------------------------
47FALLBACK=$LOGDIR/reboot-fallback-used
48fallback() {
49 [ -z "$identity_state" ] || die "identity restore failed: $*. Attended recovery required"
50 if [ -e "$FALLBACK" ]; then
51 board "restore FAILED after the reboot fallback: $* (page Main and Drake; GPU state unknown; log $LOG)"
52 die "$* after the reboot fallback already ran"
53 fi
54 date -u > "$FALLBACK"
55 log "R1 reboot fallback: $*; the boot unit runs R again after the reboot"
56 board "restore: $*; reboot fallback, then R again from the boot unit"
57 sync
58 sudo -n systemctl reboot
59 exit 0
60}
61if [ "$(drv)" = vfio-pci ]; then echo "$BDF" | sudo -n tee "$PCI/drivers/vfio-pci/unbind" >/dev/null || true; fi
62echo | sudo -n tee "$DEV/driver_override" >/dev/null || true
63if [ "$(nv_modules)" -ne 4 ]; then
64 log "R1 nvidia modules loaded: $(nv_modules) of 4; modprobe nvidia_uvm nvidia_drm"
65 timeout 180 sudo -n modprobe nvidia_uvm || fallback "modprobe nvidia_uvm failed"
66 timeout 180 sudo -n modprobe nvidia_drm || fallback "modprobe nvidia_drm failed"
67 [ "$(nv_modules)" -eq 4 ] || fallback "nvidia modules: $(nv_modules) of 4"
68fi
69if [ "$(drv)" != nvidia ]; then
70 echo "$BDF" | sudo -n tee "$PCI/drivers_probe" >/dev/null || true
71fi
72[ "$(drv)" = nvidia ] || fallback "$BDF driver is $(drv), not nvidia"
73timeout 120 nvidia-smi -L | tee -a "$LOG" | grep -q GB10 || fallback "nvidia-smi does not list the GB10"
74log "R1 PASS: nvidia.ko back, 4 modules, driver bound, nvidia-smi lists the GB10"
75
76# R2 -------------------------------------------------------------------------
77systemctl is-active --quiet nvidia-persistenced || sudo -n systemctl start nvidia-persistenced || log "R2 nvidia-persistenced did not start"
78if [ -s "$SAVED" ]; then
79 sudo -n sysctl -q -p "$SAVED" || die "could not restore sysctl from $SAVED"
80fi
81log "R2 persistenced $(systemctl is-active nvidia-persistenced); kernel.panic=$(sysctl -n kernel.panic) panic_on_oops=$(sysctl -n kernel.panic_on_oops)"
82
83# R3 -------------------------------------------------------------------------
84if [ "$identity_state" = down ]; then
85 listeners=$(ss -Hltn 'sport = :18091') || die "could not inspect restored port"
86 [ -z "$listeners" ] && [ -z "$(live_pid)" ] || die "unexpected service on port 18091"
87 apps="port 18091 was and remains idle"
88 log "R3 $apps"
89else
90if [ -z "$(live_pid)" ]; then
91 K=$(cat "$Q36_KEY")
92 Q36_BATCH_BIN=$Q36_BIN AIEN_Q36_STROKE=1 AIEN_SERVE_GPU_LOCK=/tmp/aien-serve-18091.lock AIEN_COORD_KEY="$K" \
93 "$Q36/start-35b-batch.sh" | tee -a "$LOG"
94fi
95i=0
96until curl -fsS --max-time 5 http://127.0.0.1:18091/v1/models 2>/dev/null | grep -qi qwen; do
97 i=$((i + 5)); [ "$i" -le 900 ] || { board "restore: 18091 did not come up in 900 s (page Main; $Q36/serve.log)"; die "18091 did not list qwen within 900 s"; }
98 sleep 5
99done
100log "R3 18091 /v1/models lists qwen after ~${i} s"
101out=$(curl -fsS --max-time 120 http://127.0.0.1:18091/v1/chat/completions -H 'Content-Type: application/json' \
102 -d '{"messages":[{"role":"user","content":"Reply with the single word: ready"}],"max_tokens":8,"temperature":0}') ||
103 die "greedy chat failed"
104log "R3 greedy chat: $out"
105p=$(live_pid)
106snap35b "$p" > "$SNAP.restored"
107if ! snap_expected | cmp -s - "$SNAP.restored"; then
108 [ "$identity_state" != up ] || die "running service differs from its pre-window snapshot"
109 log "R3 WARNING: restarted 35B launch record differs from the recipe (see $SNAP.restored)"
110fi
111apps=$(nvidia-smi --query-compute-apps=process_name,used_memory --format=csv,noheader)
112log "R3 compute apps: $apps"
113[ "$(printf '%s\n' "$apps" | grep -c aien-serve-http)" -eq 1 ] || die "expected exactly one aien-serve-http on the GPU"
114
115fi
116
117# R4 -------------------------------------------------------------------------
118sudo -n systemctl disable aien-owndriver-window.service >/dev/null 2>&1 || true
119sudo -n rm -f "$UNIT"
120sudo -n systemctl daemon-reload
121privcheck || { board "PRIVILEGE PERSISTED after the window, see $LOG (page Main)"; die "privilege state not clean"; }
122rm -f "$LIVE_MARKER" "$APPROVAL" "$FALLBACK" "$SAVED" "$IDENTITY" "$W0SUM" "$RPATH" "$LOGDIR/d3-cmd" "$STATE"
123board "WINDOW CLOSED (own driver), 18091 restored ($(printf '%s' "$apps" | tr '\n' ' ')). Log $LOG"
124log "R PASS"