Files
leleka/scripts/gpu-bringup/run_gpu_smokes.sh
T

253 lines
12 KiB
Bash
Executable File

#!/usr/bin/env bash
# Run the #[ignore]d Root-only GPU smokes of leleka-cuda-driver / leleka-engine-qwen35-cuda on the RTX 5090 host.
#
# run_gpu_smokes.sh --list # table of every smoke, its group, env flags, needs
# run_gpu_smokes.sh --plan [--groups a,b] # print the cargo commands, run nothing (works on macOS)
# run_gpu_smokes.sh --run [--groups a,b] # run them (Linux + NVIDIA driver only)
#
# Semantics
# * groups run in dependency order (scripts/gpu-bringup/smoke-groups.json); selecting a group also selects the
# groups it depends on;
# * inside a group the first failure stops that group (later tests are NOT RUN); groups that depend on a failed
# group are SKIPPED, independent groups still run;
# * a test passes only if cargo exits 0 AND the number of passed tests equals the number the inventory expects
# (a cargo filter that matches nothing is a failure, not a pass);
# * every test gets its own log under the run dir; nvidia-smi is recorded before and after the whole run and
# around every group;
# * nothing here starts a model run: the model-assets group (tests that read shard/pack/oracle paths) runs only
# with --allow-model-runs AND only when the caller already exported every variable it needs;
# * it refuses to start if the driver is older than the highest PTX ISA in the tree (9.0 needs >= 580.65.06);
# * the script never kills a process and refuses to start while another process holds the GPU
# (--allow-busy-gpu overrides, e.g. for a deliberately shared card).
#
# Environment: SMOKE_TIMEOUT (seconds per test, default 900), CARGO_PROFILE_FLAG (default empty = debug; use
# --release only if remote_sync.sh built with it), RUN_DIR via --run-dir.
# SMOKE_SM86=1 adds the `sm86` cargo feature (sm_86 companions of the sealed PTX, docs/sm86-assets.md) to the
# leleka-cuda-driver and leleka-engine-qwen35-cuda test builds: for an RTX 30-series card such as the laptop RTX 3080 (cc 8.6).
set -euo pipefail
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
repo="$(cd "$here/../.." && pwd)"
inv=(python3 "$here/smoke_inventory.py" --root "$repo")
mode=""
groups=""
skip_groups=""
run_dir=""
allow_assets=0
allow_busy=0
name_filter=""
min_free_mib="${MIN_FREE_MIB:-8192}"
profile_flag="${CARGO_PROFILE_FLAG:-}"
test_timeout="${SMOKE_TIMEOUT:-900}"
sm86="${SMOKE_SM86:-0}"
# features for a package: the inventory's, plus `sm86` for the packages that have it when SMOKE_SM86=1
features_for() { # pkg features -> features string, or "-" for none
local pkg="$1" f="$2"
if [[ "$sm86" == 1 && ( "$pkg" == leleka-cuda-driver || "$pkg" == leleka-engine-qwen35-cuda ) ]]; then
if [[ "$f" == "-" ]]; then f="sm86"; else f="$f,sm86"; fi
fi
printf '%s' "$f"
}
usage() { sed -n '2,24p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; }
while [[ $# -gt 0 ]]; do
case "$1" in
--list|--plan|--run) mode="${1#--}"; shift ;;
--dry-run) mode="plan"; shift ;;
--groups) groups="$2"; shift 2 ;;
--skip-groups) skip_groups="$2"; shift 2 ;;
--run-dir) run_dir="$2"; shift 2 ;;
--filter) name_filter="$2"; shift 2 ;;
--allow-model-runs) allow_assets=1; shift ;;
--allow-busy-gpu) allow_busy=1; shift ;;
--release) profile_flag="--release"; shift ;;
-h|--help) usage; exit 0 ;;
*) echo "unknown argument: $1" >&2; usage >&2; exit 2 ;;
esac
done
[[ -n "$mode" ]] || { usage >&2; exit 2; }
sel=()
[[ -n "$groups" ]] && sel+=(--select "$groups")
[[ -n "$skip_groups" ]] && sel+=(--skip-groups "$skip_groups")
if [[ "$allow_assets" == 1 || ( "$mode" == plan && ",$groups," == *",model-assets,"* ) ]]; then sel+=(--with-assets); fi
if [[ "$mode" == "list" ]]; then
"${inv[@]}" --emit table
echo
echo "groups (name, depends_on, kind, description):"
"${inv[@]}" --emit groups | column -t -s $'\t' || "${inv[@]}" --emit groups
exit 0
fi
order="$("${inv[@]}" --emit order ${sel[@]+"${sel[@]}"})"
plan="$("${inv[@]}" --emit plan ${sel[@]+"${sel[@]}"})"
group_info="$("${inv[@]}" --emit groups)"
group_deps() { printf '%s\n' "$group_info" | awk -F'\t' -v g="$1" '$1==g {print $2}'; }
group_kind() { printf '%s\n' "$group_info" | awk -F'\t' -v g="$1" '$1==g {print $3}'; }
command_for() { # pkg features target name env -> prints the command line
local pkg="$1" features="$2" target="$3" name="$4" env_kv="$5" cmd="" kv
features="$(features_for "$pkg" "$features")"
[[ "$env_kv" != "-" ]] && for kv in $env_kv; do cmd+="$kv "; done
cmd+="cargo test --locked ${profile_flag:+$profile_flag }-p $pkg"
[[ "$features" != "-" ]] && cmd+=" --features $features"
if [[ "$target" == "lib" ]]; then cmd+=" --lib"; else cmd+=" --test ${target#test:}"; fi
cmd+=" -- --ignored --test-threads=1 --nocapture $name"
printf '%s' "$cmd"
}
if [[ "$mode" == "plan" ]]; then
echo "# dependency order: $(echo "$order" | tr '\n' ' ')"
for g in $order; do
echo "## group $g (depends on: $(group_deps "$g"); kind: $(group_kind "$g"))"
printf '%s\n' "$plan" | awk -F'\t' -v g="$g" '$1==g' | while IFS=$'\t' read -r grp idx pkg features target name expected env_kv klass needs src; do
[[ -n "$name_filter" && "$name" != *"$name_filter"* ]] && continue
echo "# $src expects $expected passed; needs: $needs"
command_for "$pkg" "$features" "$target" "$name" "$env_kv"
echo
done
done
exit 0
fi
# ------------------------------------------------------------------------------------------ real run
[[ "$(uname -s)" == "Linux" || -n "${SMOKES_ALLOW_NON_LINUX:-}" ]] || { echo "--run needs the Linux GPU host (uname: $(uname -s)); use --plan here" >&2; exit 2; }
command -v nvidia-smi >/dev/null || { echo "nvidia-smi not found: no NVIDIA driver on this machine" >&2; exit 2; }
command -v cargo >/dev/null || { echo "cargo not on PATH (source ~/.cargo/env)" >&2; exit 2; }
# the tree mixes CUDA 13.0 PTX (ISA 9.0) with 12.8 PTX (ISA 8.7): the driver must be able to JIT the highest ISA
if ! python3 "$here/compile_assets.py" --root "$repo" --isa-inventory --driver-check; then
echo "refusing to start: the installed NVIDIA driver cannot load the PTX in this tree (see above)" >&2
exit 3
fi
busy="$(nvidia-smi --query-compute-apps=pid,process_name,used_memory --format=csv,noheader 2>/dev/null || true)"
if [[ -n "${busy//[[:space:]]/}" && "$allow_busy" != 1 ]]; then
echo "refusing to start: other processes hold the GPU (not touching them):" >&2
echo "$busy" >&2
echo "stop them yourself or pass --allow-busy-gpu if sharing is intended" >&2
exit 3
fi
free_mib="$(nvidia-smi --query-gpu=memory.free --format=csv,noheader,nounits | head -1 | tr -d ' ')"
if (( free_mib < min_free_mib )); then
echo "refusing to start: only ${free_mib} MiB VRAM free (< MIN_FREE_MIB=${min_free_mib})" >&2
exit 3
fi
[[ -n "$run_dir" ]] || run_dir="$repo/target/gpu-bringup/smokes-$(date -u +%Y%m%dT%H%M%SZ)"
[[ ! -e "$run_dir" ]] || { echo "run dir $run_dir already exists" >&2; exit 2; }
mkdir -p "$run_dir/status"
smi_csv="timestamp,name,driver_version,memory.used,memory.total,temperature.gpu,power.draw,clocks.sm,clocks.mem,utilization.gpu"
smi_mark() { { echo "# $1"; nvidia-smi --query-gpu="$smi_csv" --format=csv,noheader; } >> "$run_dir/gpu-timeline.csv" 2>&1 || true; }
{
echo "run_dir=$run_dir"; echo "start_utc=$(date -u +%FT%TZ)"; echo "host=$(hostname)"; echo "user=$(id -un)"
echo "kernel=$(uname -sr)"; echo "git_head=$(git -C "$repo" rev-parse HEAD 2>/dev/null || echo unknown)"
echo "rustc=$(rustc --version 2>/dev/null || true)"; echo "cargo=$(cargo --version 2>/dev/null || true)"
echo "groups=$(echo "$order" | tr '\n' ' ')"; echo "profile_flag=$profile_flag"; echo "timeout=$test_timeout"
echo "allow_model_runs=$allow_assets"; echo "sm86_feature=$sm86"
env | grep -E '^(LELEKA_|CUDA_|STRATA_)' | sed -E 's/(TOKEN|KEY|SECRET)=.*/\1=<redacted>/' || true
} > "$run_dir/run-info.txt"
nvidia-smi -q > "$run_dir/nvidia-smi.before.txt" 2>&1 || true
smi_mark "run start"
printf 'group\tidx\ttest\tresult\tseconds\tpassed\texpected\tlog\n' > "$run_dir/results.tsv"
timeout_cmd=()
if command -v timeout >/dev/null; then timeout_cmd=(timeout --signal=TERM --kill-after=30 "$test_timeout"); fi
any_fail=0
for g in $order; do
kind="$(group_kind "$g")"
deps="$(group_deps "$g")"
blocked=""
if [[ "$deps" != "-" ]]; then
for d in ${deps//,/ }; do
if [[ "$(cat "$run_dir/status/$d" 2>/dev/null || echo NOT-RUN)" != PASS ]]; then blocked="$d"; fi
done
fi
mkdir -p "$run_dir/$g"
if [[ -n "$blocked" ]]; then
echo "SKIPPED $g (dependency $blocked did not pass)"
echo "SKIPPED-DEP" > "$run_dir/status/$g"
printf '%s\t-\t-\tSKIPPED-DEP(%s)\t0\t-\t-\t-\n' "$g" "$blocked" >> "$run_dir/results.tsv"
continue
fi
echo "== group $g (kind $kind, depends on $deps)"
smi_mark "group $g start"
group_status=PASS
stopped=0
while IFS=$'\t' read -r grp idx pkg features target name expected env_kv klass needs src; do
[[ -n "$grp" ]] || continue
[[ -n "$name_filter" && "$name" != *"$name_filter"* ]] && continue
log="$run_dir/$g/$(printf '%03d' "$idx")-$name.log"
if [[ "$stopped" == 1 ]]; then
printf '%s\t%s\t%s\tNOT-RUN(earlier failure in group)\t0\t-\t%s\t-\n' "$g" "$idx" "$name" "$expected" >> "$run_dir/results.tsv"
echo " not run $name"
continue
fi
if [[ "$klass" == assets ]]; then
missing=""
if [[ "$needs" != "-" ]]; then
for v in ${needs//,/ }; do
[[ "$v" == \(* ]] && { missing="$needs"; break; }
[[ -n "${!v:-}" ]] || missing="$missing $v"
done
fi
if [[ -n "$missing" ]]; then
echo " skipped $name (needs:${missing})"
printf '%s\t%s\t%s\tSKIPPED(missing env:%s)\t0\t-\t%s\t-\n' "$g" "$idx" "$name" "${missing// /,}" "$expected" >> "$run_dir/results.tsv"
[[ "$group_status" == PASS ]] && group_status=INCOMPLETE
continue
fi
fi
env_args=()
[[ "$env_kv" != "-" ]] && for kv in $env_kv; do env_args+=("$kv"); done
features="$(features_for "$pkg" "$features")"
cargo_args=(test --locked)
[[ -n "$profile_flag" ]] && cargo_args+=("$profile_flag")
cargo_args+=(-p "$pkg")
[[ "$features" != "-" ]] && cargo_args+=(--features "$features")
if [[ "$target" == "lib" ]]; then cargo_args+=(--lib); else cargo_args+=(--test "${target#test:}"); fi
cargo_args+=(-- --ignored --test-threads=1 --nocapture "$name")
{ echo "# $src"; echo "# $(command_for "$pkg" "$features" "$target" "$name" "$env_kv")"; echo "# start $(date -u +%FT%TZ)"; } > "$log"
start=$SECONDS
set +e
( cd "$repo" && env ${env_args[@]+"${env_args[@]}"} ${timeout_cmd[@]+"${timeout_cmd[@]}"} cargo "${cargo_args[@]}" ) >> "$log" 2>&1
rc=$?
set -e
secs=$((SECONDS - start))
passed="$(grep -E '^test result: ' "$log" | sed -E 's/.* ([0-9]+) passed;.*/\1/' | awk '{s+=$1} END {print s+0}')"
failed="$(grep -E '^test result: ' "$log" | sed -E 's/.*; ([0-9]+) failed;.*/\1/' | awk '{s+=$1} END {print s+0}')"
result=PASS
if (( rc != 0 )); then result="FAIL(exit $rc)"
elif (( failed != 0 )); then result="FAIL($failed failed)"
elif (( passed != expected )); then result="FAIL(ran $passed, expected $expected: filter matched nothing / cfg-gated?)"
fi
printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n' "$g" "$idx" "$name" "$result" "$secs" "$passed" "$expected" "${log#"$run_dir"/}" >> "$run_dir/results.tsv"
if [[ "$result" == PASS ]]; then
echo " ok $name (${secs}s)"
else
echo " FAIL $name: $result -> $log"
group_status=FAIL; any_fail=1; stopped=1
fi
done < <(printf '%s\n' "$plan" | awk -F'\t' -v g="$g" '$1==g')
echo "$group_status" > "$run_dir/status/$g"
smi_mark "group $g end ($group_status)"
done
nvidia-smi -q > "$run_dir/nvidia-smi.after.txt" 2>&1 || true
smi_mark "run end"
{
echo "end_utc=$(date -u +%FT%TZ)"
echo "any_fail=$any_fail"
} >> "$run_dir/run-info.txt"
echo
echo "group status:"
for g in $order; do printf ' %-14s %s\n' "$g" "$(cat "$run_dir/status/$g" 2>/dev/null || echo NOT-RUN)"; done
echo "results: $run_dir/results.tsv logs: $run_dir/<group>/ gpu: $run_dir/gpu-timeline.csv"
exit "$any_fail"