New pure crate with the arithmetic of f16_bits.hpp, kv_q4.cu and kv_q8.cu, the cell layouts and byte sizes of fp16/INT8/rotated INT8/Q4_0/K8V4/keyless pools (identical per-cell figures to the memory planner: 2048/1056/576/816/528), and the generate.cpp format-selection rules. Golden fixtures are produced by the Original's own host code extracted verbatim with awk (FWHT, Q4_0 quantizer under separate and fused multiply-add, INT8 K, kv_pool_bytes, kv_block_bytes). Experimental formats are explicit; nothing is enabled by default. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
36 lines
2.3 KiB
Bash
Executable File
36 lines
2.3 KiB
Bash
Executable File
#!/bin/sh
|
|
# Regenerates tests/fixtures/kv_golden_{separate,fused}.json from the Original's host code (macOS or Linux, any
|
|
# C++17 compiler, no CUDA). The reference functions are extracted verbatim from engine/strata with awk.
|
|
# crates/experimental-ref/oracle/gen_kv_golden.sh
|
|
# `separate` is compiled with -ffp-contract=off (every x * id + 8.5f is a multiply then an add), `fused` with
|
|
# -ffp-contract=fast (-mfma on x86; arm64 fuses natively), which is how nvcc compiles the same expression.
|
|
set -eu
|
|
here=$(cd "$(dirname "$0")" && pwd)
|
|
strata="$here/../../../engine/strata"
|
|
out="$here/../tests/fixtures"
|
|
work=$(mktemp -d)
|
|
trap 'rm -rf "$work"' EXIT
|
|
# 1. fwht256_host_reference + quantize_block_q4_0_host, up to the end of the anonymous namespace
|
|
awk '/^void fwht256_host_reference\(float\* x\) \{/ {on=1} on && /^} \/\/ namespace/ {exit} on {print}' \
|
|
"$strata/src/kernels/kv_q4_parity.cpp" > "$work/fragment_fwht_q4.inc"
|
|
# 2. kv_pool_bytes of layer.cpp
|
|
awk '/^uint64_t kv_pool_bytes\(const QsaShapes& s, int64_t pages, bool hybrid, bool int8\) \{/ {on=1} on {print} on && /^}/ {exit}' \
|
|
"$strata/src/core/layer.cpp" > "$work/fragment_pool_bytes.inc"
|
|
# 3. kv_block_bytes of kv_stream.cu
|
|
awk '/^uint64_t kv_block_bytes\(const QsaShapes& s, int fmt\) \{/ {on=1} on {print} on && /^}/ {exit}' \
|
|
"$strata/src/kernels/cuda/kv_stream.cu" > "$work/fragment_block_bytes.inc"
|
|
# 4. the INT8 K host reference loop of kv_hybrid_parity.cpp (from after the rk_s declaration to Vrot's)
|
|
awk '/std::vector<uint16_t> rk_s\(/ {skip=1; next} skip && /std::vector<float> Vrot/ {exit} skip {print}' \
|
|
"$strata/src/kernels/kv_hybrid_parity.cpp" > "$work/fragment_q8_k.inc"
|
|
for f in fragment_fwht_q4 fragment_pool_bytes fragment_block_bytes fragment_q8_k; do test -s "$work/$f.inc"; done
|
|
CXX=${CXX:-clang++}
|
|
FMA=""
|
|
case $(uname -m) in x86_64|amd64) FMA="-mfma" ;; esac
|
|
common="-std=c++17 -O1 -Wno-unused-function -I$strata/include -I$here/stub -I$work"
|
|
$CXX $common -ffp-contract=off -o "$work/gen_separate" "$here/gen_kv_golden.cpp"
|
|
$CXX $common -ffp-contract=fast $FMA -o "$work/gen_fused" "$here/gen_kv_golden.cpp"
|
|
mkdir -p "$out"
|
|
"$work/gen_separate" separate > "$out/kv_golden_separate.json"
|
|
"$work/gen_fused" fused > "$out/kv_golden_fused.json"
|
|
echo "wrote $out/kv_golden_separate.json and kv_golden_fused.json"
|