hex/.github/release/check-x86-baseline.sh
Dax ab2e819f1a
x86_64: keep ggml on x86-64-v3; refuse older CPUs with a clear message (#592) (#614)
* x86_64: keep ggml on x86-64-v3 and refuse older CPUs with a clear message (#592)

Reverts #595's Ivy Bridge floor: it slowed CPU transcription for everyone. ggml goes back to its x86-64-v3 defaults (AVX2, BMI2, FMA, F16C). Hex's own Rust stays baseline x86-64, and the first thing main does on Linux and Windows x86_64 is check AVX2/BMI2/FMA/F16C with is_x86_feature_detected!. Without them Hex prints and shows "Hex needs a 2013 or newer processor (Intel Haswell / AMD Excavator or later) with AVX2. This PC's processor isn't supported." (a native MessageBox on Windows; stderr, which the journal logs, and zenity, kdialog or notify-send on Linux) and exits 1. Every command is covered except --version and --help, which installers and the updater run. ggml-cpu has no static constructors, so nothing runs v3 code before main.

The release guard now asserts the opposite: ggml's CPU libraries must hold AVX2 and FMA (the build targets v3) and no AVX-512 or AMX. Docs state the requirement.

* cpu_floor: harden DLL search first; no dialog under systemd, in a terminal or for hex service; guard rejects AVX-VNNI

* cpu_floor: always exit 1; Windows always shows the message box; Linux skips the dialog in a terminal, under NOTIFY_SOCKET, or for hex service
2026-10-31 13:20:56 -04:00

51 lines
2.5 KiB
Shell
Executable file

#!/usr/bin/env bash
# shellcheck disable=SC2034 # the patterns are read through ${!kind}
# check-x86-baseline.sh <executable> <ggml lib>...: checks that an x86_64
# release targets x86-64-v3 (Haswell and later; AVX2, BMI2, FMA, F16C) and
# nothing beyond it. Hex checks for v3 at startup (src/cpu_floor.rs), so
# its own code and everything before that check stay baseline.
#
# - ggml's static CPU libraries must use AVX2 and FMA (the build really
# targets v3) and may hold no AVX-512, AVX-VNNI or AMX instruction.
# - The executable is only checked to be disassemblable: Rust crates that
# detect AVX-512 at run time (blake3) use it behind that check.
#
# OBJDUMP names the disassembler (default objdump; llvm-objdump for COFF).
. "$(dirname "$0")/lib.sh"
objdump=${OBJDUMP:-objdump}
fma='\bv?f(n)?m(add|sub)(sub|add)?[0-9]{3}'
avx2='\bvp(add|sub|mul|and|or|xor|cmp|shuf|unpck|max|min|abs|sll|srl|sra|sign|madd|maddubs|hadd|blend|movmsk|alignr|pack|mov[sz]x|broadcast|gather|perm[dq]|maskmov|sllv|srlv|srav)[a-z0-9]*\b.*ymm|\bv(inserti128|extracti128|perm2i128|broadcasti128|gather|perm(ps|pd)\b)'
avx512='zmm|%k[0-7]\b'
avx_vnni='\bvpdp(busd|busds|wssd|wssds|bssd|bssds|bsud|bsuds|buud|buuds)\b'
amx='\b(tileloadd|tilestored|tdpb[a-z]+|tdpbf16ps|ldtilecfg|sttilecfg|tilerelease|tilezero)\b'
# disassemble <file>: refuses a missing file or an empty disassembly, so a
# wrong path or an unexpanded glob can never pass.
disassemble() {
[ -f "$1" ] || die "$1 does not exist."
"$objdump" -d --no-show-raw-insn "$1" > "$asm" || die "$objdump could not disassemble $1."
[ "$(wc -l < "$asm")" -gt 100 ] || die "$objdump printed no code for $1."
}
count() { grep -cE "$1" "$asm" || true; }
[ $# -ge 2 ] || die "Usage: check-x86-baseline.sh <executable> <ggml lib>..."
asm=$(mktemp)
trap 'rm -f "$asm"' EXIT
disassemble "$(posix "$1")"
shift
avx2_total=0 fma_total=0
for lib in "$@"; do
lib=$(posix "$lib")
disassemble "$lib"
for kind in avx512 avx_vnni amx; do
n=$(count "${!kind}")
[ "$n" = 0 ] || die "$(basename "$lib") holds $n ${kind^^} instructions; ggml must target x86-64-v3 and nothing beyond it."
done
avx2_total=$((avx2_total + $(count "$avx2")))
fma_total=$((fma_total + $(count "$fma")))
done
if [ "$avx2_total" = 0 ] || [ "$fma_total" = 0 ]; then
die "ggml holds no AVX2 or FMA code ($avx2_total AVX2, $fma_total FMA); the build no longer targets x86-64-v3."
fi
echo "ggml targets x86-64-v3: $avx2_total AVX2 and $fma_total FMA instructions, no AVX-512, AVX-VNNI or AMX."