okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-own-2a-oracle 07df43732 (quant_parity golden reference leg, quant_golden_regen) into f-own-int67148809b

main
3.1 KiB48 linesraw
1#!/usr/bin/env bash
2# tests/quant/run_oracle.sh - build the quant layer's tests against ggml-cpu in its three x86 flavours and run them.
3#
4#   tests/quant/run_oracle.sh [flavour...]        flavours: avx2 (default portable build), avx (STRATA_ISA_FLOOR=avx), none (STRATA_ISA_FLOOR=none)
5#   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)
6#   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),
7#        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
8#        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)
9#
10# 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
11# 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.
12set -u
13cd "$(dirname "$0")/../.."
14ROOT=${BUILD_ROOT:-$PWD/build-quant}
15JOBS=${JOBS:-$(nproc)}
16mkdir -p "$ROOT"
17GEN=${QUANT_GENERATOR:-Ninja}   # QUANT_GENERATOR="Unix Makefiles" on a box without ninja
18FLAVOURS=("$@")
19if [ ${#FLAVOURS[@]} -eq 0 ]; then
20  case "$(uname -m)" in aarch64|arm64) FLAVOURS=(neon) ;; *) FLAVOURS=(avx2 avx none) ;; esac
21fi
22rc=0
23for f in "${FLAVOURS[@]}"; do
24  case "$f" in
25    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
26    avx) EXTRA=(-DSTRATA_ISA_FLOOR=avx) ;;
27    none) EXTRA=(-DSTRATA_ISA_FLOOR=none) ;;
28    native) EXTRA=() ;;
29    *) echo "unknown flavour $f"; exit 2 ;;
30  esac
31  B="$ROOT/$f"
32  echo "=== flavour $f: configure + build in $B"
33  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 \
34    || { tail -30 "$ROOT/cfg-$f.log"; rc=1; continue; }
35  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; }
36  echo "=== flavour $f: quant_selftest"
37  "$B/quant_selftest" || rc=1
38  echo "=== flavour $f: quant_parity ${QUANT_PARITY_ARGS:-}"
39  if [ -n "${QUANT_FORCE_ISA:-}" ]; then STRATA_FORCE_ISA=$QUANT_FORCE_ISA "$B/quant_parity" ${QUANT_PARITY_ARGS:-} || rc=1
40  else "$B/quant_parity" ${QUANT_PARITY_ARGS:-} || rc=1; fi
41  # 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)
42  if [ -f tests/quant/golden_x86.txt ] && [ -z "${QUANT_PARITY_ARGS:-}" ]; then
43    echo "=== flavour $f: quant_parity --regen-check"
44    "$B/quant_parity" --regen-check; r=$?
45    [ $r -ne 0 ] && [ $r -ne 77 ] && rc=1
46  fi
47done
48exit $rc