mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-06 00:08:52 +00:00
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.
49 lines
3.1 KiB
Bash
49 lines
3.1 KiB
Bash
#!/usr/bin/env bash
|
|
# tests/quant/run_oracle.sh - build the quant layer's tests against ggml-cpu in its three x86 flavours and run them.
|
|
#
|
|
# tests/quant/run_oracle.sh [flavour...] flavours: avx2 (default portable build), avx (STRATA_ISA_FLOOR=avx), none (STRATA_ISA_FLOOR=none)
|
|
# arm64: neon (default, the contract) and native (the build host's own ggml-cpu flavour: GCC on the Spark gives plain armv8-a, no dot product, which quant_parity skips; Apple's gives the Mac's)
|
|
# env: QUANT_GENERATOR (default Ninja), BUILD_ROOT (default ./build-quant), JOBS, QUANT_PARITY_ARGS (e.g. "--rows 64"), QUANT_FORCE_ISA (runs the binary under STRATA_FORCE_ISA),
|
|
# QUANT_PARITY_LIVE_STRICT=1 (quant_parity's leg 2, ours against the ggml-cpu built here, fails too: right only where this compiler builds ggml as
|
|
# GCC 13 does; by default it is information and the gate is leg 1, ours against tests/quant/golden_x86.txt), CC / CXX (the compiler)
|
|
#
|
|
# The flavour decides which ggml-cpu is linked into quant_parity and so which arithmetic contract is checked (isa.hpp). Any CPU with at least that
|
|
# flavour's instructions can run it: the AVX and generic flavours run fine on an AVX2 or AVX-512 machine. Exit status is non-zero on the first failure.
|
|
set -u
|
|
cd "$(dirname "$0")/../.."
|
|
ROOT=${BUILD_ROOT:-$PWD/build-quant}
|
|
JOBS=${JOBS:-$(nproc)}
|
|
mkdir -p "$ROOT"
|
|
GEN=${QUANT_GENERATOR:-Ninja} # QUANT_GENERATOR="Unix Makefiles" on a box without ninja
|
|
FLAVOURS=("$@")
|
|
if [ ${#FLAVOURS[@]} -eq 0 ]; then
|
|
case "$(uname -m)" in aarch64|arm64) FLAVOURS=(neon) ;; *) FLAVOURS=(avx2 avx none) ;; esac
|
|
fi
|
|
rc=0
|
|
for f in "${FLAVOURS[@]}"; do
|
|
case "$f" in
|
|
avx2|neon) EXTRA=(-DSTRATA_PORTABLE=ON) ;; # neon: the arm64 portable build (armv8.2-a+dotprod+fp16+i8mm, no SVE); native on arm64 is the host's flavour
|
|
avx) EXTRA=(-DSTRATA_ISA_FLOOR=avx) ;;
|
|
none) EXTRA=(-DSTRATA_ISA_FLOOR=none) ;;
|
|
native) EXTRA=() ;;
|
|
*) echo "unknown flavour $f"; exit 2 ;;
|
|
esac
|
|
B="$ROOT/$f"
|
|
echo "=== flavour $f: configure + build in $B"
|
|
cmake -G "$GEN" -S . -B "$B" -DCMAKE_BUILD_TYPE=Release -DSTRATA_BUILD_TESTS=ON -DSTRATA_ENABLE_CUDA=OFF -DSTRATA_ENABLE_HIP=OFF ${EXTRA[@]+"${EXTRA[@]}"} ${QUANT_CMAKE_ARGS:-} > "$ROOT/cfg-$f.log" 2>&1 \
|
|
|| { tail -30 "$ROOT/cfg-$f.log"; rc=1; continue; }
|
|
cmake --build "$B" -j "$JOBS" --target quant_selftest quant_parity > "$ROOT/build-$f.log" 2>&1 || { grep -E "error|Error" "$ROOT/build-$f.log" | head -40; rc=1; continue; }
|
|
echo "=== flavour $f: quant_selftest"
|
|
"$B/quant_selftest" || rc=1
|
|
echo "=== flavour $f: quant_parity ${QUANT_PARITY_ARGS:-}"
|
|
if [ -n "${QUANT_FORCE_ISA:-}" ]; then STRATA_FORCE_ISA=$QUANT_FORCE_ISA "$B/quant_parity" ${QUANT_PARITY_ARGS:-} || rc=1
|
|
else "$B/quant_parity" ${QUANT_PARITY_ARGS:-} || rc=1; fi
|
|
# the golden file's own check: GCC 13.x and MSVC 19.4x regenerate their lines byte for byte; any other compiler skips it (exit 77)
|
|
if [ -f tests/quant/golden_x86.txt ] && [ -z "${QUANT_PARITY_ARGS:-}" ]; then
|
|
echo "=== flavour $f: quant_parity --regen-check"
|
|
"$B/quant_parity" --regen-check; r=$?
|
|
[ $r -ne 0 ] && [ $r -ne 77 ] && rc=1
|
|
fi
|
|
done
|
|
exit $rc
|