llama.cpp/ggml
Mattbusel 8197d9756e ggml-cpu: fix x86 SIMD detection — validate OS YMM/ZMM/AMX state via XCR0
The ggml_backend_cpu_x86_score() function contained a FIXME comment
admitting it did not check for OS support. All AVX/AVX2/AVX-512/AMX
feature checks were raw CPUID bit reads with no OSXSAVE or XGETBV
validation.

On CPUs where CPUID reports AVX2 support but the OS has not enabled
YMM register save/restore (e.g. certain hypervisors, containers with
restricted XSAVE, or Windows builds with disabled AVX context), ggml
would select an AVX2/AVX-512 backend that immediately faults with
SIGILL on the first vector instruction.

Fix: add xgetbv() (MSVC _xgetbv / GCC-Clang inline asm), then three
predicates that are now called by the affected feature methods:

  os_saves_ymm() — CPUID.1:ECX[27] (OSXSAVE) + XCR0[2:1] == 0b11
    gates: AVX, AVX2, FMA, F16C, AVX_VNNI

  os_saves_zmm() — os_saves_ymm() + XCR0[7:5] == 0b111
    gates: AVX512F/DQ/PF/ER/CD/BW/VL, AVX512_VBMI/VNNI/FP16/BF16

  os_saves_amx() — os_saves_zmm() + XCR0[18:17] == 0b11
    gates: AMX_TILE, AMX_INT8, AMX_FP16, AMX_BF16

No interface changes — all call sites continue to use is.AVX2() etc.
The fix is self-contained within cpuid_x86.

Resolves the FIXME in ggml_backend_cpu_x86_score().

Designed and implemented by Matthew Busel.
2026-03-11 04:34:42 -04:00
..
cmake ggml: Skip backend library linking code when GGML_BACKEND_DL=ON (#15094) 2025-08-07 13:45:41 +02:00
include ggml : bump RPC version (#20330) 2026-03-10 21:36:57 +02:00
src ggml-cpu: fix x86 SIMD detection — validate OS YMM/ZMM/AMX state via XCR0 2026-03-11 04:34:42 -04:00
.gitignore vulkan : cmake integration (#8119) 2024-07-13 18:12:39 +02:00
CMakeLists.txt ggml : bump version to 0.9.7 (ggml/1425) 2026-02-15 22:24:29 +02:00