Files
leleka/crates/experimental-ref/oracle/gen_stream_golden.sh
T
Pavlo RatushnyiandClaude Sonnet 5.5 1d1f5bfc14 feat(experimental-ref): KV streaming planner and CLOCK resolver oracle with golden and emulated-kernel checks
kv_plan/qsa_state_bytes/host copy sizing equal layer.cpp's own functions (extracted verbatim)
over 480 format x context x ring x --kv-resident cases. StreamMap::resolve models the
kernel's three phases sequentially; the miss-list order is the only device nondeterminism
and is supplied as input. The literal kv_stream.cu text, run with 1024 emulated threads,
reproduces the model state after each of 45 calls with constant eviction.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-14 15:24:37 +02:00

25 lines
1.6 KiB
Bash
Executable File

#!/bin/sh
# Regenerates tests/fixtures/stream_plan_golden.json from layer.cpp's own planner functions (extracted verbatim).
# crates/experimental-ref/oracle/gen_stream_golden.sh
set -eu
here=$(cd "$(dirname "$0")" && pwd)
strata="$here/../../../engine/strata"
out="$here/../tests/fixtures"
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
layer="$strata/src/core/layer.cpp"
grep -m1 '^namespace { bool g_without_key' "$layer" | sed 's/^namespace {//; s/}$//' > "$work/fragment_flags.inc"
grep -m1 '^QsaShapes qsa_shapes(const ModelGeometry& g) {' "$layer" > "$work/fragment_shapes.inc"
grep -m1 '^uint64_t align_up16(uint64_t n) {' "$layer" >> "$work/fragment_shapes.inc"
# the streaming chunk: from the globals to the end of kv_pool_bytes (the anonymous namespace closes after it)
awk '/^int64_t g_kv_resident = 0;/ {on=1} on && /^} \/\/ namespace/ {exit} on {print}' "$layer" > "$work/fragment_streaming.inc"
awk '/^uint64_t qsa_state_bytes\(const ModelGeometry& g, int64_t max_cells, bool with_rope, int64_t ring_cells\) \{/ {on=1} on {print} on && /^}/ {exit}' \
"$layer" > "$work/fragment_state_bytes.inc"
grep -m1 '^int64_t qsa_kv_resident_min()' "$layer" > "$work/fragment_resident_min.inc"
for f in fragment_flags fragment_shapes fragment_streaming fragment_state_bytes fragment_resident_min; do test -s "$work/$f.inc"; done
${CXX:-clang++} -std=c++17 -O1 -ffp-contract=off -Wno-unused-function -Wno-unused-variable -I"$strata/include" -I"$here/stub" -I"$work" \
"$here/gen_stream_golden.cpp" -o "$work/gen_stream"
mkdir -p "$out"
"$work/gen_stream" > "$out/stream_plan_golden.json"
echo "wrote $out/stream_plan_golden.json"