#!/usr/bin/env bash
# job_ev.sh: experiment arm gdnev (L2 evict_first policy on the committed-state stores instead of .cs) against main,
# c=4 and c=8 then c=1, interleaved, REPS captures each, rig's shared cache; its AOT binaries built on box 201's build slot.
cd ~/gdn-commit; SH=$HOME/small-row-main; pct() { df --output=pcent / | tail -1 | tr -dc 0-9; }
exec 9>/run/lock/arbi-gpu-0.lock; flock -w 43200 9 || exit 1
echo "lock held $(date -Is) root $(pct)%"
trim() { rm -rf $1/arbi-serve/flat-weights $1/pycache $1/arbi-serve/boot-store/dynamo $1/arbi-serve/boot-store/inductor $1/arbi-serve/boot-store/compile-bundles; }
mkdir -p $SH/cache-main/arbi-serve/aot && cp -n ${AOT:-aot_ev}/* $SH/cache-main/arbi-serve/aot/ 2>/dev/null
for r in $(seq 1 ${REPS:-1}); do for c in ${CONCS:-4 8 1}; do for arm in ${ARMS:-gdnmain gdnev}; do
  trim $SH/cache-main; CONC=$c bash scripts/serve.sh ${PFX:-ev}_${arm}_c${c}_r$r nsys $arm >> logs/ev.log 2>&1; echo "step $arm c$c r$r rc=$? $(date -Is) root $(pct)%"
done; done; done
trim $SH/cache-main; echo "job_ev done $(date -Is) root $(pct)%"
