Files
Strata/tests/quant/make_golden.sh
T
Niko1221 a215f95d52 quant_parity: a gate leg against stored reference digests, the live ggml compare for information
ggml-cpu's own results move with the compiler that builds the oracle:
GCC 14.3 fuses the IQ4_NL odd-block tail into an FMA, GCC 15.2 that and
the generic Q2_0 dot, where GCC 13.3 does not (55 and 238 rows of the
oracle, 1-4 ulp). The layer's results are the same bytes under all
three. A live compare alone therefore fails on a newer GCC for a change
in ggml, not in the layer.

Leg 1, the gate: every group (flavour, section, type, n) of the layer's
results against tests/quant/golden_x86.txt, the digests of the
reference that GCC 13.3's ggml-cpu computes for the same inputs (input
digest checked too). A toolchain family can carry its own line for a
group (msvc: MSVC does not contract the intrinsics' add-of-mul).
Leg 2, information: the row-by-row compare with the ggml-cpu linked
here; its summary names the compiler and the groups where that ggml
differs from the golden reference. QUANT_PARITY_LIVE_STRICT=1 makes it
fail too. Without golden lines for a flavour (arm64, or --rows other
than 24) leg 2 stays the gate.

The digest is FNV-1a 64, written in the test, with its published test
vectors checked at start. --dump-group KEY prints every row of a group
(ours per kernel and ggml's) for a diff against a GCC 13 run;
--write-golden FILE writes a flavour's lines; --regen-check (ctest
quant_golden_regen, only when the golden file exists) regenerates the
stored lines byte for byte under GCC 13.x (family gcc) or MSVC 19.4x
(family msvc) and skips elsewhere. tests/quant/make_golden.sh and
golden_merge.py make the file.
2026-11-10 20:25:56 +01:00

26 lines
2.0 KiB
Bash

#!/usr/bin/env bash
# tests/quant/make_golden.sh - make tests/quant/golden_x86.txt, the reference digests of quant_parity's leg 1.
#
# tests/quant/make_golden.sh <folder with the MSVC fragments msvc-avx2.txt msvc-avx.txt msvc-none.txt>
#
# Run on x86 Linux with GCC 13.x as gcc / g++ (or CC / CXX): it builds the three flavours (tests/quant/run_oracle.sh, so the same flags) and writes
# each flavour's lines with `quant_parity --write-golden`, then merges them with the MSVC fragments (tests/quant/golden_merge.py).
# The MSVC fragments come from a Windows build of each flavour with MSVC 19.4x (the release toolchain): configure as the Windows oracle does
# (cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DSTRATA_BUILD_TESTS=ON -DSTRATA_ENABLE_CUDA=OFF -DSTRATA_ENABLE_HIP=OFF -DSTRATA_NATIVE_EXPERTS=ON
# plus -DSTRATA_PORTABLE=ON / -DSTRATA_ISA_FLOOR=avx / -DSTRATA_ISA_FLOOR=none), build quant_parity, run `quant_parity --write-golden msvc-<flavour>.txt`.
# Regenerate when the test's cases or the vendored ggml (third_party/strata-ggml) change; ctest quant_golden_regen checks the file under both toolchains.
set -u
cd "$(dirname "$0")/../.."
MSVC_DIR=${1:?usage: make_golden.sh <folder with msvc-avx2.txt msvc-avx.txt msvc-none.txt>}
CC_BIN=${CC:-gcc}
case "$($CC_BIN -dumpfullversion 2>/dev/null)" in 13.*) ;; *) echo "make_golden.sh: needs GCC 13.x (CC=$CC_BIN is $($CC_BIN -dumpfullversion 2>/dev/null))"; exit 2 ;; esac
case "$(uname -m)" in x86_64|i?86) ;; *) echo "make_golden.sh: x86 only"; exit 2 ;; esac
ROOT=${BUILD_ROOT:-$PWD/build-golden}
mkdir -p "$ROOT"
for f in avx2 avx none; do
BUILD_ROOT=$ROOT QUANT_PARITY_ARGS="--write-golden $ROOT/gcc-$f.txt" bash tests/quant/run_oracle.sh $f || { echo "make_golden.sh: flavour $f failed"; exit 1; }
done
PY=$(command -v python3 || command -v python)
"$PY" tests/quant/golden_merge.py --gcc "$ROOT/gcc-avx2.txt" "$ROOT/gcc-avx.txt" "$ROOT/gcc-none.txt" \
--msvc "$MSVC_DIR/msvc-avx2.txt" "$MSVC_DIR/msvc-avx.txt" "$MSVC_DIR/msvc-none.txt" -o tests/quant/golden_x86.txt