aien-train
AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.
Brought by drakestapleton
aien-train / tests / omegallm / efi-qemu.sh
| 1 | #!/bin/sh |
| 2 | # Boot a copy of an ollm UEFI image under QEMU (TCG) with OVMF as a USB stick, wait for the |
| 3 | # application to print `OLLM DONE`, press Enter for it (it waits for a key), and copy \OLLM back |
| 4 | # from the copy with mtools. EMULATED evidence only: this is not the iMac. |
| 5 | # Usage: sh tests/omegallm/efi-qemu.sh IMG OUTDIR [SECONDS] |
| 6 | # Env: CORES (taskset list, default 6), OVMF_CODE / OVMF_VARS (default /usr/share/OVMF/*_4M.fd), |
| 7 | # QEMU_MACHINE (default q35), QEMU_CPU (default max), QEMU_SMBIOS (when set, one `-smbios` argument, |
| 8 | # e.g. `file=t1.bin`; efi-ident.sh uses these three for the identity-line edge cases). |
| 9 | # Writes OUTDIR/serial.log (the console: OVMF copies ConOut to the serial port) and OUTDIR/vol/, a |
| 10 | # copy of every file in \OLLM after the run (OUT.TXT and what the jobs wrote, e.g. TR.BIN, S.CK), |
| 11 | # with one `vol: SHA256 NAME` line each. Prints `done=1 seconds=S` when OLLM DONE was seen, `done=0` |
| 12 | # when the deadline passed or QEMU ended first (an ollm refusal ends the application before OLLM |
| 13 | # DONE; OUT.TXT then stops at that job). Under TCG on one GB10 core (core 7, MIDR 0x410fd851) the |
| 14 | # efi-job.txt run took 1006 s (evidence/OMEGALLM/efi/main/qemu.txt), so SECONDS defaults to 2700. |
| 15 | # Exit 0 only if OLLM DONE was seen and OUT.TXT was read. |
| 16 | set -u |
| 17 | [ $# -ge 2 ] || { echo "usage: efi-qemu.sh IMG OUTDIR [SECONDS]" >&2; exit 2; } |
| 18 | IMG=$1 OUT=$2 LIM=${3:-2700} |
| 19 | CORES=${CORES:-6} |
| 20 | MACH=${QEMU_MACHINE:-q35} |
| 21 | CPU=${QEMU_CPU:-max} |
| 22 | CODE=${OVMF_CODE:-/usr/share/OVMF/OVMF_CODE_4M.fd} |
| 23 | VARS=${OVMF_VARS:-/usr/share/OVMF/OVMF_VARS_4M.fd} |
| 24 | mkdir -p "$OUT" |
| 25 | rm -f "$OUT/serial.log" "$OUT/mon" |
| 26 | cp "$IMG" "$OUT/disk.img" |
| 27 | cp "$VARS" "$OUT/vars.fd" |
| 28 | echo "qemu: $(qemu-system-x86_64 --version | head -1)" |
| 29 | echo "ovmf: $(sha256sum "$CODE" | cut -d' ' -f1) $(basename "$CODE")" |
| 30 | echo "image: $(sha256sum "$IMG" | cut -d' ' -f1)" |
| 31 | set -- -machine "$MACH" -cpu "$CPU" |
| 32 | [ -z "${QEMU_SMBIOS:-}" ] || set -- "$@" -smbios "$QEMU_SMBIOS" |
| 33 | taskset -c "$CORES" nice -n 19 qemu-system-x86_64 "$@" -m 2048 -smp 1 \ |
| 34 | -display none -vga std -nic none \ |
| 35 | -drive if=pflash,format=raw,readonly=on,file="$CODE" \ |
| 36 | -drive if=pflash,format=raw,file="$OUT/vars.fd" \ |
| 37 | -device qemu-xhci,id=xhci -drive if=none,id=stick,format=raw,file="$OUT/disk.img" \ |
| 38 | -device usb-storage,bus=xhci.0,drive=stick -device usb-kbd,bus=xhci.0 \ |
| 39 | -serial file:"$OUT/serial.log" -no-reboot -monitor unix:"$OUT/mon",server,nowait \ |
| 40 | > "$OUT/qemu.log" 2>&1 & |
| 41 | qp=$! |
| 42 | say() { printf '%s\n' "$1" | socat - unix-connect:"$OUT/mon" > /dev/null 2>&1 || true; } |
| 43 | t=0 done=0 |
| 44 | while [ "$t" -lt "$LIM" ]; do |
| 45 | sleep 1 |
| 46 | t=$((t + 1)) |
| 47 | if grep -aq 'OLLM DONE' "$OUT/serial.log" 2> /dev/null; then done=1; break; fi |
| 48 | # the application returned an error status (a refusal or a trap): OVMF reports it and moves on |
| 49 | grep -aq 'failed to start' "$OUT/serial.log" 2> /dev/null && break |
| 50 | kill -0 "$qp" 2> /dev/null || break |
| 51 | done |
| 52 | if [ "$done" = 1 ]; then |
| 53 | say "sendkey ret" |
| 54 | sleep 5 |
| 55 | fi |
| 56 | say quit |
| 57 | sleep 2 |
| 58 | kill "$qp" 2> /dev/null |
| 59 | wait "$qp" 2> /dev/null |
| 60 | echo "done=$done seconds=$t" |
| 61 | rm -rf "$OUT/vol" |
| 62 | mkdir "$OUT/vol" |
| 63 | mcopy -n -i "$OUT/disk.img@@1M" '::/OLLM/*' "$OUT/vol/" 2> /dev/null |
| 64 | rm -f "$OUT/disk.img" "$OUT/vars.fd" "$OUT/mon" |
| 65 | for f in "$OUT"/vol/*; do |
| 66 | [ -f "$f" ] && echo "vol: $(sha256sum "$f" | cut -d' ' -f1) $(basename "$f")" |
| 67 | done |
| 68 | [ -r "$OUT/vol/OUT.TXT" ] || { echo "OUT.TXT not readable"; exit 1; } |
| 69 | [ "$done" = 1 ] |