Summary
Follow-up to the AVX-512 ISA-floor fix (see PR pinning GGML_NATIVE=OFF + GGML_AVX2=ON for x64; refs lloyal-ai/hdk#20).
After the AVX2 floor lands, x64 prebuilts run on any AVX2 CPU (Intel Haswell 2013+ / AMD Zen 2017+). But a CPU below the baseline (no AVX2) would still hit an uncatchable illegal instruction (0xC000001D) inside createContext() — a hard process kill with no JS .catch. This is defense-in-depth so any future over-baselining (or a genuinely ancient CPU) fails cleanly instead of crashing.
Proposal
- Add
src/CPUFeatureProbe.cpp exposing bool cpu_meets_baseline() using __builtin_cpu_supports (gcc/clang) / IsProcessorFeaturePresent or __cpuid (MSVC), comparing the host CPU against a compile-time baseline macro injected by the build (matching build.js's floor, i.e. AVX2 for x64).
- Call it in
BackendManager::ensureInitialized() (src/BackendManager.hpp) before llama_backend_init(); on failure throw a catchable Napi::Error so createContext rejects with a clear message.
Key subtlety
The probe TU must be compiled below the build's ISA baseline (e.g. -mno-avx2 -mno-avx / -march=x86-64-v1 on gcc/clang; default /arch on MSVC) via set_source_files_properties(... COMPILE_OPTIONS ...) in CMakeLists.txt — otherwise the probe itself executes baseline instructions and traps before it can report the failure. This per-file flag differs across compilers and could not be locally compile-verified on the dev machine (arm64 macOS); CI compiles it.
Priority
Defense-in-depth — not blocking the hdk#20 crash fix (the AVX2 floor already stops the reported crash). Verify the catchable-error behavior on a sub-baseline CPU (the reporter's Zen 2 box, or a QEMU -cpu mask).
Summary
Follow-up to the AVX-512 ISA-floor fix (see PR pinning
GGML_NATIVE=OFF+GGML_AVX2=ONfor x64; refs lloyal-ai/hdk#20).After the AVX2 floor lands, x64 prebuilts run on any AVX2 CPU (Intel Haswell 2013+ / AMD Zen 2017+). But a CPU below the baseline (no AVX2) would still hit an uncatchable illegal instruction (
0xC000001D) insidecreateContext()— a hard process kill with no JS.catch. This is defense-in-depth so any future over-baselining (or a genuinely ancient CPU) fails cleanly instead of crashing.Proposal
src/CPUFeatureProbe.cppexposingbool cpu_meets_baseline()using__builtin_cpu_supports(gcc/clang) /IsProcessorFeaturePresentor__cpuid(MSVC), comparing the host CPU against a compile-time baseline macro injected by the build (matchingbuild.js's floor, i.e. AVX2 for x64).BackendManager::ensureInitialized()(src/BackendManager.hpp) beforellama_backend_init(); on failure throw a catchableNapi::ErrorsocreateContextrejects with a clear message.Key subtlety
The probe TU must be compiled below the build's ISA baseline (e.g.
-mno-avx2 -mno-avx/-march=x86-64-v1on gcc/clang; default/archon MSVC) viaset_source_files_properties(... COMPILE_OPTIONS ...)inCMakeLists.txt— otherwise the probe itself executes baseline instructions and traps before it can report the failure. This per-file flag differs across compilers and could not be locally compile-verified on the dev machine (arm64 macOS); CI compiles it.Priority
Defense-in-depth — not blocking the hdk#20 crash fix (the AVX2 floor already stops the reported crash). Verify the catchable-error behavior on a sub-baseline CPU (the reporter's Zen 2 box, or a QEMU
-cpumask).