interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / scripts / l6_host_receipt.sh

91 lines · 5243 bytes Raw Blame History
1#!/usr/bin/env bash
2# SPDX-License-Identifier: Apache-2.0
3# Copyright 2026 Drake Stapleton (AIEN / aien-dev)
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# L6-A: host-side tokens-per-second receipt (aienos#34 lane 6).
18# Runs the l6_host example pinned to cores 0 and 19 (core types are read from /proc/cpuinfo, not assumed;
19# on this machine they interleave: cpu0=0xd87 A725, cpu19=0xd85 X925),
20# runs llama.cpp single-thread on the same model, writes evidence/l6_host_<sha12>.json.
21# Reproduce: scripts/l6_host_receipt.sh (env: AIENOS_MODEL, AIENOS_N, LLAMA_BENCH)
22set -euo pipefail
23cd "$(dirname "$0")/.."
24MODEL="${AIENOS_MODEL:-$HOME/models/aien-mail/Llama-3.2-1B-Instruct-Q4_K_M.gguf}"
25N="${AIENOS_N:-64}"
26LB="${LLAMA_BENCH:-$HOME/llama.cpp-build/bin/llama-bench}"
27[ -x "$LB" ] || LB="$HOME/llama.cpp-build/build/bin/llama-bench"
28COMMIT="$(git rev-parse HEAD)"
29TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT
30export AIENOS_MODEL="$MODEL" AIENOS_N="$N" AIENOS_COMMIT="$COMMIT"
31
32GOV="$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 2>/dev/null || echo unknown)"
33NPROC="$(nproc)"
34PARTS="$(grep -E '^CPU part' /proc/cpuinfo | awk '{print $4}' | sort | uniq -c | awk '{print $2 "x" $1}' | paste -sd, -)"
35HOST="$(hostname)"; KERNEL="$(uname -r)"
36echo "commit=$COMMIT governor=$GOV nproc=$NPROC cpu_part=$PARTS host=$HOST kernel=$KERNEL"
37
38CMD="cargo run --release -p aienos-infer --example l6_host"
39cargo build --release -p aienos-infer --example l6_host
40for core in 0 19; do
41 echo "RUN: AIENOS_MODEL=$MODEL AIENOS_N=$N taskset -c $core $CMD"
42 rc=0; taskset -c "$core" $CMD >"$TMP/run$core.txt" || rc=$?
43 echo "exit=$rc"; echo "$rc" >"$TMP/rc$core"
44 grep -E '^(prefill_us|decode_tokens|mean_tok_us|tok_per_s|PARITY):' "$TMP/run$core.txt"
45done
46
47LLAMA_BUILD="NOT_RUN"; LLAMA_TPS="null"; LLAMA_TPS19="null"
48LLCMD="taskset -c 0 $LB -m $MODEL -ngl 0 -t 1 -p 0 -n 64 -r 3 -o json"
49if [ -x "$LB" ]; then
50 echo "RUN: $LLCMD"
51 taskset -c 0 "$LB" -m "$MODEL" -ngl 0 -t 1 -p 0 -n 64 -r 3 -o json >"$TMP/ll0.json" 2>"$TMP/ll0.err" || true
52 LLAMA_TPS="$(jq '[.[]|select(.n_gen==64)|.avg_ts][0] // null' "$TMP/ll0.json")"
53 LLAMA_BUILD="$(jq -r '.[0]|"\(.build_commit) \(.build_number)"' "$TMP/ll0.json")"
54 echo "RUN: ${LLCMD/taskset -c 0/taskset -c 19}"
55 taskset -c 19 "$LB" -m "$MODEL" -ngl 0 -t 1 -p 0 -n 64 -r 3 -o json >"$TMP/ll19.json" 2>/dev/null || true
56 LLAMA_TPS19="$(jq '[.[]|select(.n_gen==64)|.avg_ts][0] // null' "$TMP/ll19.json")"
57else
58 echo "llama-bench not found: NOT_RUN"
59fi
60
61cpart() { awk -v c="$1" '/^processor/{p=$3} /^CPU part/{if(p==c)print $4}' /proc/cpuinfo; } # 0xd85=Cortex-X925, 0xd87=Cortex-A725
62val() { sed -n "s/^$2: //p" "$TMP/run$1.txt"; }
63leg() { # core -> JSON object
64 jq -n --arg core "$1" --arg parity "$(val "$1" PARITY)" --arg ids "$(val "$1" tokens)" \
65 --arg us "$(val "$1" tok_us)" --arg text "$(val "$1" text)" \
66 --argjson prefill "$(val "$1" prefill_us)" --argjson dt "$(val "$1" decode_tokens)" \
67 --argjson mean "$(val "$1" mean_tok_us)" --argjson tps "$(val "$1" tok_per_s)" \
68 --argjson rc "$(cat "$TMP/rc$1")" --arg part "$(cpart "$1")" \
69 '{core_pinned:($core|tonumber), cpu_part:$part, exit_code:$rc, parity:$parity, prefill_us:$prefill, decode_tokens:$dt,
70 tokens:($ids|split(" ")|map(tonumber)), tok_us:($us|split(" ")|map(tonumber)),
71 mean_tok_us:$mean, tok_per_s:$tps, text:$text}'
72}
73SHA="$(val 0 model_sha256)"
74OUT="evidence/l6_host_${SHA:0:12}.json"
75jq -n --arg commit "$COMMIT" --arg path "$MODEL" --arg sha "$SHA" --argjson size "$(val 0 model_size_bytes)" \
76 --arg prompt "$(val 0 prompt)" --arg golden "$(val 0 golden_ids)" \
77 --argjson c0 "$(leg 0)" --argjson c19 "$(leg 19)" \
78 --arg cpu_part "$PARTS" --arg gov "$GOV" --arg host "$HOST" --arg kernel "$KERNEL" --argjson nproc "$NPROC" \
79 --arg lb "$LLAMA_BUILD" --arg llcmd "$LLCMD" --argjson lt0 "$LLAMA_TPS" --argjson lt19 "$LLAMA_TPS19" \
80 --arg now "$(date -u +%Y-%m-%dT%H:%M:%SZ)" --arg cmd "AIENOS_N=$N taskset -c <core> $CMD" \
81 '{commit:$commit, model:{path:$path, sha256:$sha, size_bytes:$size}, prompt:$prompt,
82 golden_ids:($golden|split(" ")|map(tonumber)), parity:($c0.parity),
83 prefill_us:$c0.prefill_us, decode_tokens:$c0.decode_tokens, tok_us:$c0.tok_us,
84 mean_tok_us:$c0.mean_tok_us, tok_per_s:$c0.tok_per_s, core_pinned:0,
85 cpu_part:$cpu_part, nproc:$nproc, governor:$gov, host:$host, kernel:$kernel,
86 legs:{core0:$c0, core19:$c19},
87 harness_command:$cmd, threads:1,
88 llama_cpp:{build:$lb, threads:1, tok_per_s:$lt0, tok_per_s_core19:$lt19, command:$llcmd},
89 reference:{file:"evidence/config_a_reference_bundle.json", tok_per_s:54.2, note:"20 threads, server; not like for like"},
90 generated_at_utc:$now}' | jq -S . >"$OUT"
91echo "wrote $OUT"