interplane.Get Omega
Read in your language

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

branch main Branches Tags History

aien-train / tests / omegallm / efi-qemu.sh

69 lines · 3371 bytes Raw Blame History
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.
16set -u
17[ $# -ge 2 ] || { echo "usage: efi-qemu.sh IMG OUTDIR [SECONDS]" >&2; exit 2; }
18IMG=$1 OUT=$2 LIM=${3:-2700}
19CORES=${CORES:-6}
20MACH=${QEMU_MACHINE:-q35}
21CPU=${QEMU_CPU:-max}
22CODE=${OVMF_CODE:-/usr/share/OVMF/OVMF_CODE_4M.fd}
23VARS=${OVMF_VARS:-/usr/share/OVMF/OVMF_VARS_4M.fd}
24mkdir -p "$OUT"
25rm -f "$OUT/serial.log" "$OUT/mon"
26cp "$IMG" "$OUT/disk.img"
27cp "$VARS" "$OUT/vars.fd"
28echo "qemu: $(qemu-system-x86_64 --version | head -1)"
29echo "ovmf: $(sha256sum "$CODE" | cut -d' ' -f1) $(basename "$CODE")"
30echo "image: $(sha256sum "$IMG" | cut -d' ' -f1)"
31set -- -machine "$MACH" -cpu "$CPU"
32[ -z "${QEMU_SMBIOS:-}" ] || set -- "$@" -smbios "$QEMU_SMBIOS"
33taskset -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 &
41qp=$!
42say() { printf '%s\n' "$1" | socat - unix-connect:"$OUT/mon" > /dev/null 2>&1 || true; }
43t=0 done=0
44while [ "$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
51done
52if [ "$done" = 1 ]; then
53 say "sendkey ret"
54 sleep 5
55fi
56say quit
57sleep 2
58kill "$qp" 2> /dev/null
59wait "$qp" 2> /dev/null
60echo "done=$done seconds=$t"
61rm -rf "$OUT/vol"
62mkdir "$OUT/vol"
63mcopy -n -i "$OUT/disk.img@@1M" '::/OLLM/*' "$OUT/vol/" 2> /dev/null
64rm -f "$OUT/disk.img" "$OUT/vars.fd" "$OUT/mon"
65for f in "$OUT"/vol/*; do
66 [ -f "$f" ] && echo "vol: $(sha256sum "$f" | cut -d' ' -f1) $(basename "$f")"
67done
68[ -r "$OUT/vol/OUT.TXT" ] || { echo "OUT.TXT not readable"; exit 1; }
69[ "$done" = 1 ]