Skip to content

Fail loud: catchable error instead of 0xC000001D when CPU is below the prebuilt's ISA baseline #30

Description

@lloyal-research

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).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions