Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-architecture-mv/blob/main/tools/ops/spark-calibrate # aien-architecture-mv Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-architecture-mv / tools / ops / spark-calibrate` 98 lines ยท 5542 bytes Raw Blame History 1 #!/bin/sh 2 # spark-calibrate: the one calibration file of a measurement window. 3 # 4 # Run inside an open window (spark-window run spark-calibrate, or with 5 # SPARK_WINDOW set). It holds the GPU lock (default /tmp/aien-gb10.lock; 6 # SPARK_GB10_LOCK overrides it, for tests only (see spark-window:63)), waits 7 # for it, and prints the holders every 60 s. It measures: 8 # 1. CPU memory bandwidth with the omega#583 memcpy probe (pinned source 9 # omega research/cost-sim-583@`3bd56731` tools/dagsim/memcpy_probe.c), the 10 # same call research/583 used: nice -n 10 memcpy_probe 1 K 10, K = 1 and 8. 11 # Skipped (and said so) when MemAvailable is under 14.5 GiB (12 GiB 12 # headroom rule plus the probe's 2 GB). 13 # 2. Idle power at the wall: 30 s of nothing, through spark-receipt. 14 # Writes ~/yardsticks/windows//calibration.json (raw CSVs and the idle 15 # receipt beside it). Every receipt taken later in the window links that file. 16 set -u 17 WR=${SPARK_WINDOWS_ROOT:-$HOME/yardsticks/windows} 18 id=${SPARK_WINDOW:-$(spark-window id)} || { echo "spark-calibrate: no open window; run spark-window open NAME first" >&2; exit 1; } 19 [ "$(cat "$WR/OPEN" 2>/dev/null)" = "$id" ] && [ -f "$WR/$id/held" ] || { echo "spark-calibrate: window $id is not the open, held window" >&2; exit 1; } 20 held() { [ "$(cat "$WR/OPEN" 2>/dev/null)" = "$id" ] && [ -f "$WR/$id/held" ] && [ ! -f "$WR/$id/expired" ] && kill -0 "$(cat "$WR/$id/holder.pid" 2>/dev/null)" 2>/dev/null; } 21 d=$WR/$id; mkdir -p "$d/calibration" 22 export SPARK_WINDOW=$id SPARK_WINDOW_DIR=$d 23 G=${SPARK_GB10_LOCK:-/tmp/aien-gb10.lock} # SPARK_GB10_LOCK is for tests only (see spark-window:63) 24 25 # the probe, built once per source blob + flags 26 REPO=${OMEGA_REPO:-$HOME/workspace/omega}; PIN=`3bd56731c5517e2a9c8f195955c71e73dc6f9269`; SRC=tools/dagsim/memcpy_probe.c 27 CFLAGS="-O2 -pthread" 28 blob=$(git -C "$REPO" rev-parse "$PIN:$SRC" 2>/dev/null) || { echo "spark-calibrate: cannot read $SRC at $PIN in $REPO (git fetch origin research/cost-sim-583)" >&2; exit 1; } 29 P=$HOME/.cache/spark-shared/memcpy_probe-$(echo "$blob $CFLAGS" | sha256sum | cut -c1-12) 30 if [ ! -x "$P" ]; then 31 mkdir -p "${P%/*}" 32 git -C "$REPO" cat-file -p "$blob" > "$P.c" && cc $CFLAGS -o "$P.tmp.$$" "$P.c" && mv -f "$P.tmp.$$" "$P" || { echo "spark-calibrate: probe build failed" >&2; exit 1; } 33 fi 34 35 t0=$(date +%s) 36 # A window opened with --gb10 exclusive|shared already holds the GPU lock for us (spark-window, L154); 37 # taking it again here would wait on our own window forever. 38 gmode=$(cat "$WR/$id/gb10" 2>/dev/null || echo legacy) 39 case $gmode in 40 exclusive|shared) ;; 41 *) exec 9>"$G" 42 # Wait in the queue without stepping out of it (a timed retry loses the place to newer waiters); 43 # a separate ticker prints who holds the lock every 60 s. 44 ( exec 9>&-; while sleep 60; do echo "spark-calibrate: waiting $(( $(date +%s) - t0 )) s for the GB10 lock: $(spark-window locks gb10)" >&2; done ) & 45 tick=$! 46 flock 9 47 kill $tick 2>/dev/null ;; 48 esac 49 gwait=$(( $(date +%s) - t0 )) 50 held || { echo "spark-calibrate: window $id lapsed (lease ran out or closed) while waiting for the GB10 lock; nothing measured" >&2; exit 1; } 51 start=$(date -u +%FT%TZ) 52 53 stat_csv() { # median/min/max of column 5 (GB/s) in a probe CSV, as JSON 54 grep -v '^#' "$1" | grep -E '^[0-9]' | cut -d, -f5 | sort -n | awk ' 55 { v[NR] = $1 } END { if (!NR) { print "null"; exit } 56 m = (NR % 2) ? v[(NR+1)/2] : (v[NR/2] + v[NR/2+1]) / 2 57 printf "{\"reps\": %d, \"GBps_median\": %s, \"GBps_min\": %s, \"GBps_max\": %s}", NR, m, v[1], v[NR] }' 58 } 59 avail=$(awk '/MemAvailable/{print $2}' /proc/meminfo) 60 probe_json="" 61 for k in 1 8; do 62 f=$d/calibration/memcpy_k$k.csv 63 if [ "$avail" -lt `15204352` ]; then 64 echo "# SKIPPED k=$k: MemAvailable $avail kB under 14.5 GiB" > "$f"; s=null 65 else 66 nice -n 10 "$P" 1 $k 10 > "$f" 2>&1; s=$(stat_csv "$f") 67 fi 68 probe_json="$probe_json\"k$k\": $s, " 69 avail=$(awk '/MemAvailable/{print $2}' /proc/meminfo) 70 done 71 72 # 30 s idle at the wall; receipt name carries the window id so windows never overwrite each other 73 spark-receipt "calib-idle-$id" --idle 0 -- sleep 30 > "$d/calibration/idle.out" 2>&1 74 r=$(sed -n 's/^receipt: //p' "$d/calibration/idle.out") 75 cp "$r" "$d/calibration/idle-receipt.json" 76 jv() { sed -n "s/^ *\"$1\": \([^,]*\),\{0,1\}$/\1/p" "$d/calibration/idle-receipt.json"; } 77 held && wheld=true || wheld=false 78 flock -u 9 79 80 cat > "$d/calibration.json.tmp" <