#!/usr/bin/env bash # P6 S1 launcher: waits for GPU headroom on the shared H200s, then starts the S1 drivers in tmux. # Two disjoint regime groups (the runner does not claim jobs, so drivers must not overlap): # A = R10 Rm5 R0 (protocol priority), B = R0h R10tb (cut first if late). # A slot starts on a card only when free memory stays >= 2500 MiB + 2 workers x 1600 MiB on two # readings one minute apart; workers = min(4, (free - 2500) / 1600). Never touches other jobs. set -u cd "$(dirname "$0")/.." groups=("R10 Rm5 R0" "R0h R10tb"); names=(p6_s1a p6_s1b); next=0 log() { echo "$(date -u +%FT%TZ) $*"; } free_mib() { nvidia-smi --query-gpu=memory.free --format=csv,noheader,nounits -i "$1" | tr -d ' '; } log "watcher start" while (( next < ${#groups[@]} )); do for g in 0 1; do (( next < ${#groups[@]} )) || break f1=$(free_mib $g); (( f1 >= 5700 )) || continue sleep 60; f2=$(free_mib $g); f=$(( f1 < f2 ? f1 : f2 )); (( f >= 5700 )) || continue w=$(( (f - 2500) / 1600 )); (( w > 4 )) && w=4 n=${names[$next]}; r=${groups[$next]} tmux new-session -d -s "$n" -c "$PWD" \ "env STUDIES=S1 REGIMES='$r' DEVICE=cuda:$g WORKERS=$w MEM_GB=2 scripts/run_bench.sh posterior train >> logs/bench_${n}_cuda$g.out 2>&1" log "launched $n regimes=[$r] cuda:$g workers=$w (free ${f1}/${f2} MiB)" next=$(( next + 1 )); sleep 300 # let the new workers allocate before the next reading done sleep 300 done log "all S1 groups launched; watcher exits"