interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / om / residency / run.sh

131 lines · 7488 bytes Raw Blame History
1#!/usr/bin/env bash
2# SPDX-License-Identifier: Apache-2.0
3# Host test of the seeded .om expert residency simulator (om/residency/residency.om).
4# Expected outputs in fixtures/*.want were computed by fixtures/oracle.wl, an independent LRU,
5# Belady (OPT) and hinted-LRU (hlru, hcold) implementation in the Wolfram Language, not by
6# residency.om:
7# real-p4-L4T64: first 64 decode steps and first 4 layers of
8# evidence/l355-w4/routes/forced-fp8-p4.json (Qwen3.6-35B-A3B FP8, top-8 of 256 experts).
9# syn-E40L3K4T200: SeedRandom[630]; RandomSample[Range[0,39],4] per step and layer, 200 steps.
10# syn-E40L3K4T200H3: the same trace with H=3 hints per row; SeedRandom[633] and per row r of the
11# trace {r[[1]], RandomInteger[39], r[[2]]}, so two hints are used and one is mostly wasted.
12# Also checks every refusal exit code, the L*E <= 65536 bound of the shared-cache (glru/gopt/hlru/
13# hcold) section, two hint invariants for each of hlru and hcold (H=0 replays glru; hints equal to
14# the trace prefetch every glru miss and leave no demand miss), the C >= K+H gate of hinted lines,
15# and that ten mutants are caught.
16# Usage: OMEGA_OMC=<seed omc> bash om/residency/run.sh [TRACE.txt ...]
17# Extra TRACE arguments are replayed after the checks and their output printed (not compared).
18set -u
19ROOT=$(cd "$(dirname "$0")/../.." && pwd)
20# omega-mv main 0b77e6ea294aa3d69ccbdb86b9c14d133abea689, seed/out/omc
21PIN=2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f
22OMC=${OMEGA_OMC:?set OMEGA_OMC to the seed compiler (omega-mv seed/out/omc)}
23D=$ROOT/om/residency
24O=$ROOT/target/om-residency
25got=$(sha256sum < "$OMC" | cut -d' ' -f1)
26[ "$got" = "$PIN" ] || { echo "FAIL omc sha256 $got, pinned $PIN"; exit 1; }
27rm -rf "$O"; mkdir -p "$O"
28fails=0
29pass() { echo "PASS $1"; }
30fail() { echo "FAIL $1"; fails=$((fails + 1)); }
31build() { "$OMC" < "$1" > "$2" 2> "$2.err" && chmod +x "$2"; }
32build "$D/residency.om" "$O/sim" || { echo "FAIL build residency.om: $(cat "$O/sim.err")"; exit 1; }
33
34for f in real-p4-L4T64 syn-E40L3K4T200 syn-E40L3K4T200H3; do
35 "$O/sim" < "$D/fixtures/$f.txt" > "$O/$f.out"; rc=$?
36 if [ $rc = 0 ] && cmp -s "$O/$f.out" "$D/fixtures/$f.want"; then pass "$f matches the Wolfram oracle"
37 else fail "$f (exit $rc)"; diff "$D/fixtures/$f.want" "$O/$f.out" | head -5; fi
38done
39
40refuse() {
41 printf '%b' "$2" | "$O/sim" > /dev/null; rc=$?
42 if [ $rc = "$3" ]; then pass "refuse $1 (exit $rc)"; else fail "refuse $1: exit $rc, want $3"; fi
43}
44refuse "id equal to E" '4 1 1 2\n0 4\n' 7
45refuse "repeated id in one step" '4 1 2 2\n0 0 1 2\n' 8
46refuse "K above 16" '64 1 17 2\n' 4
47refuse "E zero" '0 1 1 2\n' 4
48refuse "one step" '4 1 1 1\n0\n' 4
49refuse "missing ids" '4 1 1 3\n0 1\n' 5
50refuse "letter in a number" '4 1 1 2\n0 1x\n' 5
51refuse "trailing number" '4 1 1 2\n0 1\n0\n7\n' 6
52refuse "empty input" '' 5
53refuse "T*L above 1000000" '4 500001 1 2\n' 4
54refuse "H above 16" '4 1 1 2\n0 1\n17\n' 4
55refuse "hint id equal to E" '4 1 1 2\n0 1\n1 0 4\n' 7
56refuse "missing hint ids" '4 1 1 2\n0 1\n1 0\n' 5
57{ echo "1 1 1 524289"; yes 0 | head -n 524289; echo 16; } | "$O/sim" > /dev/null; rc=$?
58if [ $rc = 4 ]; then pass "refuse T*L*H above 8388608 (exit 4)"; else fail "T*L*H above 8388608: exit $rc, want 4"; fi
59
60# T*L = 1000000 rows: one for loop makes exactly 1000000 passes and must finish (no trap 4).
61{ echo "1 500000 1 2"; yes 0 | head -n 1000000; } | "$O/sim" > "$O/r.out"; rc=$?
62if [ $rc = 0 ] && [ "$(cat "$O/r.out")" = "trace E=1 L=500000 K=1 T=2" ]; then pass "T*L = 1000000 rows read"
63else fail "T*L = 1000000 rows: exit $rc"; fi
64
65# Shared-cache section boundary: L*E = 65536 is replayed (8 glru lines), L*E = 66560 is not.
66bound() {
67 { echo "1024 $1 1 2"; for i in $(seq 1 $((2 * $1))); do echo 0; done; } | "$O/sim" > "$O/b.out"; rc=$?
68 n=$(grep -c '^glru ' "$O/b.out")
69 if [ $rc = 0 ] && [ "$n" = "$2" ]; then pass "E=1024 L=$1: $n glru lines"
70 else fail "E=1024 L=$1: exit $rc, $n glru lines, want $2"; fi
71}
72bound 64 8
73bound 65 0
74{ echo "1024 65 1 2"; for i in $(seq 1 130); do echo 0; done; echo 0; } | "$O/sim" > /dev/null; rc=$?
75if [ $rc = 4 ]; then pass "refuse hints with L*E = 66560 (exit 4)"; else fail "hints with L*E = 66560: exit $rc, want 4"; fi
76
77# hlru lines need C >= K+H: E=4 L=1 K=2 gives 6 glru lines (C >= 2), 2 hlru lines with H=1 (C = 3)
78# and none with H=2.
79gate() {
80 printf "4 1 2 2\n0 1 2 3\n$1\n$2\n" | "$O/sim" > "$O/g.out"; rc=$?
81 n=$(grep -c '^hlru ' "$O/g.out")
82 if [ $rc = 0 ] && [ "$n" = "$3" ]; then pass "C >= K+H gate, H=$1: $n hlru lines"
83 else fail "C >= K+H gate, H=$1: exit $rc, $n hlru lines, want $3"; fi
84}
85gate 1 '0 1' 2
86gate 2 '0 1 2 3' 0
87
88# Hint invariants on the synthetic trace (T*L*K = 2400 demands), for both hint modes.
89syn=$D/fixtures/syn-E40L3K4T200.txt
90"$O/sim" < "$syn" | grep '^glru ' > "$O/glru.out"
91{ cat "$syn"; echo 0; } | "$O/sim" > "$O/h0all.out"
92{ cat "$syn"; echo 4; tail -n +2 "$syn"; } | "$O/sim" > "$O/hpall.out"
93for m in hlru hcold; do
94 grep "^$m " "$O/h0all.out" \
95 | sed "s/^$m \(.*\) hint=0 \(.*\) warm_pf=0 warm_used=0 warm_waste=0 /glru \1 \2 /" > "$O/h0.out"
96 if [ -s "$O/h0.out" ] && cmp -s "$O/h0.out" "$O/glru.out"; then pass "H=0 $m equals glru"
97 else fail "H=0 $m differs from glru"; diff "$O/glru.out" "$O/h0.out" | head -5; fi
98 grep "^$m " "$O/hpall.out" > "$O/hp.out"
99 sed "s/^glru \(cap=[0-9]* pct=[0-9]*\) hits=[0-9]* miss=[0-9]* warm_miss=\([0-9]*\) /$m \1 hint=4 hits=2400 miss=0 warm_miss=0 warm_pf=\2 warm_used=\2 warm_waste=0 /" \
100 "$O/glru.out" > "$O/hpw.out"
101 if [ -s "$O/hp.out" ] && cmp -s "$O/hp.out" "$O/hpw.out"; then pass "perfect $m hints prefetch every glru miss, no demand miss"
102 else fail "perfect $m hints"; diff "$O/hpw.out" "$O/hp.out" | head -5; fi
103done
104
105# Mutants: each must build, run to completion on its fixture and change its output.
106mutant() {
107 f=${3:-syn-E40L3K4T200}
108 sed "$2" "$D/residency.om" > "$O/m.om"
109 cmp -s "$O/m.om" "$D/residency.om" && { fail "mutant $1 did not change the source"; return; }
110 build "$O/m.om" "$O/m" || { fail "mutant $1 did not build"; return; }
111 "$O/m" < "$D/fixtures/$f.txt" > "$O/m.out"; rc=$?
112 if [ $rc != 0 ]; then fail "mutant $1 did not complete (exit $rc)"
113 elif cmp -s "$O/m.out" "$D/fixtures/$f.want"; then fail "mutant $1 not caught"
114 else pass "mutant $1 caught"; fi
115}
116mutant "LRU evicts most recent" 's/^ret sub add t 2 get stp e$/ret get stp e/'
117mutant "OPT evicts nearest next use" 's/^ret get nu e$/ret sub get hd 3 get nu e/'
118mutant "shared cache ignores the layer" 's/^globst s mul rem s l0 e0$/globst s 0/'
119mutant "hints ignored" 's/^pfstep t c cd$/put ac 7 0/' syn-E40L3K4T200H3
120mutant "hints ignore the layer" 's/^globh s mul rem s l0 e0$/globh s 0/' syn-E40L3K4T200H3
121mutant "prefetch evicts by next use" 's/^evict s 0$/evict s 1/' syn-E40L3K4T200H3
122mutant "wasted prefetch not counted" 's/^put ac 6 add get ac 6 1$/put ac 6 get ac 6/' syn-E40L3K4T200H3
123mutant "hcold prefetch inserted hot" 's/^put stp v 1$/put stp v add s 1/' syn-E40L3K4T200H3
124mutant "hcold hint marks use" 's/^if eq cd 0$/if eq cd cd/' syn-E40L3K4T200H3
125mutant "hint protection dropped" 's/^put prt v add s 1$/put prt v 0/' syn-E40L3K4T200H3
126
127echo "residency.om $(sha256sum < "$D/residency.om" | cut -d' ' -f1)"
128echo "sim binary $(sha256sum < "$O/sim" | cut -d' ' -f1)"
129echo "omc $got"
130for t in "$@"; do echo "== $t"; "$O/sim" < "$t"; echo "exit $?"; done
131[ $fails = 0 ] && echo "ALL PASS" || { echo "$fails FAILED"; exit 1; }