From b3ddc1db370806ad22a5954bc2f6e83e9ea10807 Mon Sep 17 00:00:00 2001 From: Chandan Kumar Date: Sun, 6 Sep 2026 15:42:12 +0530 Subject: [PATCH 1/3] Disable SSE4.2 in noavx native builds. ggml still enables SSE4.2 on a non-cross compile even with GGML_NATIVE=OFF, so the current noavx binaries SIGILL on SSSE3-only CPUs. --- .github/workflows/compile.yml | 10 ++++++---- LLama/Native/Load/NativeLibraryMetadata.cs | 2 +- docs/FAQ.md | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index 3e7c9ecce..8da78d4a2 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -27,8 +27,10 @@ jobs: fail-fast: true matrix: include: + # SSE4.2 stays on unless we disable it; that SIGILLs pre-Nehalem CPUs (#1422). + # -march=x86-64 stops gcc from emitting SSE4 via auto-vectorization. - build: 'noavx' - defines: '-DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DGGML_F16C=OFF -DGGML_BMI2=OFF' + defines: '-DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DGGML_F16C=OFF -DGGML_BMI2=OFF -DGGML_SSE42=OFF -DCMAKE_C_FLAGS=-march=x86-64 -DCMAKE_CXX_FLAGS=-march=x86-64' os: ubuntu-22.04 arch: x64 - build: 'avx2' @@ -95,7 +97,7 @@ jobs: matrix: include: - build: 'noavx' - defines: '-DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DGGML_F16C=OFF -DGGML_BMI2=OFF' + defines: '-DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DGGML_F16C=OFF -DGGML_BMI2=OFF -DGGML_SSE42=OFF -DCMAKE_C_FLAGS=-march=x86-64 -DCMAKE_CXX_FLAGS=-march=x86-64' - build: 'avx2' defines: '' - build: 'avx' @@ -160,7 +162,7 @@ jobs: matrix: include: - build: 'noavx' - defines: '-DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DGGML_F16C=OFF -DGGML_BMI2=OFF' + defines: '-DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DGGML_F16C=OFF -DGGML_BMI2=OFF -DGGML_SSE42=OFF' - build: 'avx2' defines: '' - build: 'avx' @@ -535,7 +537,7 @@ jobs: defines: '-DCMAKE_OSX_ARCHITECTURES=x86_64 -DGGML_METAL=OFF -DGGML_AVX=ON -DGGML_AVX2=ON' targets: '--target ggml ggml-base ggml-cpu ggml-blas llama mtmd' - build: 'x64-rosetta2' - defines: '-DCMAKE_OSX_ARCHITECTURES=x86_64 -DGGML_METAL=OFF -DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_F16C=OFF -DGGML_BMI2=OFF' + defines: '-DCMAKE_OSX_ARCHITECTURES=x86_64 -DGGML_METAL=OFF -DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_F16C=OFF -DGGML_BMI2=OFF -DGGML_SSE42=OFF -DCMAKE_C_FLAGS=-march=x86-64 -DCMAKE_CXX_FLAGS=-march=x86-64' targets: '--target ggml ggml-base ggml-cpu ggml-blas llama mtmd' env: MACOS_RPATH_DEFINE: "-DCMAKE_INSTALL_RPATH='@loader_path' -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON" diff --git a/LLama/Native/Load/NativeLibraryMetadata.cs b/LLama/Native/Load/NativeLibraryMetadata.cs index e07d40986..05c88a9df 100644 --- a/LLama/Native/Load/NativeLibraryMetadata.cs +++ b/LLama/Native/Load/NativeLibraryMetadata.cs @@ -23,7 +23,7 @@ public override string ToString() public enum AvxLevel { /// - /// No AVX + /// No AVX or SSE4.2. For x86_64 CPUs that only provide SSSE3 / SSE2. /// None, diff --git a/docs/FAQ.md b/docs/FAQ.md index 03ceab536..95dc327b6 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -24,6 +24,22 @@ Generally, there are two possible cases for this problem: 1. The native library (backend) you are using is not compatible with the LLamaSharp version. If you compiled the native library yourself, please make sure you have checkouted llama.cpp to the corresponding commit of LLamaSharp, which could be found at the bottom of README. 2. The model file you are using is not compatible with the backend. If you are using a GGUF file downloaded from huggingface, please check its publishing time. +### Illegal instruction (core dumped) on an older CPU + +`LLamaSharp.Backend.Cpu` ships several x86_64 binaries. The loader picks `noavx` when the CPU has no AVX. Those binaries must also be free of SSE4.2. A CPU that only has SSSE3 (no `sse4_1` / `sse4_2` in `lscpu`) will SIGILL if the `noavx` build still contains SSE4.2 kernels. + +Until a backend package built with `-DGGML_SSE42=OFF` is published, compile llama.cpp yourself and load it before any other LLamaSharp call: + +```bash +cmake -B build -DGGML_NATIVE=OFF -DGGML_AVX=OFF -DGGML_AVX2=OFF -DGGML_FMA=OFF -DGGML_F16C=OFF -DGGML_BMI2=OFF -DGGML_SSE42=OFF -DCMAKE_C_FLAGS=-march=x86-64 -DCMAKE_CXX_FLAGS=-march=x86-64 -DBUILD_SHARED_LIBS=ON +``` + +```cs +NativeLibraryConfig.All.WithLibrary("", null); +``` + +You can also add `NativeLibraryConfig.All.WithLogCallback(...)` at startup to confirm which runtime folder was loaded (`noavx`, `avx`, `avx2`, ...). + ## Why my model is generating output infinitely From e0d51e080f32ae242fdcb2fd8a761ac896cc2ba7 Mon Sep 17 00:00:00 2001 From: Chandan Kumar Date: Sat, 12 Sep 2026 08:24:48 +0530 Subject: [PATCH 2/3] Pin Windows ARM64 ClangCL builds to windows-2022. windows-latest is VS 18, where ClangCL rebuilds ggml-cpu against a C17 PCH with C17 disabled, so llama.dll is never produced and artifact upload fails. --- .github/workflows/compile.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index 8da78d4a2..adfa82457 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -225,7 +225,9 @@ jobs: include: - build: 'arm64' defines: '-T ClangCL -DCMAKE_GENERATOR_PLATFORM=ARM64 -DGGML_NATIVE=OFF' - runs-on: windows-latest + # windows-latest is VS 18; ClangCL there rebuilds ggml-cpu with C17 off after a + # C17 PCH, so llama.dll is never produced. Pin VS 2022 like compile-cublas. + runs-on: windows-2022 steps: - uses: actions/checkout@v6 with: From 2d7d6761a554c460cab33ecb8f5c539f3658a538 Mon Sep 17 00:00:00 2001 From: Chandan Kumar Date: Sat, 12 Sep 2026 08:45:11 +0530 Subject: [PATCH 3/3] Disable ClangCL PCH on Windows ARM64 native builds. ggml-cpu fails with a C17 PCH mismatch on both windows-latest and windows-2022, so llama.dll is never produced. Also fail the job when cmake --build fails instead of hiding it behind tree. --- .github/workflows/compile.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index adfa82457..51691dfc4 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -224,9 +224,8 @@ jobs: matrix: include: - build: 'arm64' - defines: '-T ClangCL -DCMAKE_GENERATOR_PLATFORM=ARM64 -DGGML_NATIVE=OFF' - # windows-latest is VS 18; ClangCL there rebuilds ggml-cpu with C17 off after a - # C17 PCH, so llama.dll is never produced. Pin VS 2022 like compile-cublas. + # ClangCL + CMake PCH disagrees on C17 for ggml-cpu, so llama.dll is never built. + defines: '-T ClangCL -DCMAKE_GENERATOR_PLATFORM=ARM64 -DGGML_NATIVE=OFF -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON' runs-on: windows-2022 steps: - uses: actions/checkout@v6 @@ -242,6 +241,7 @@ jobs: cd build cmake .. ${{ env.COMMON_DEFINE }} ${{ matrix.defines }} cmake --build . --config Release -j ${env:NUMBER_OF_PROCESSORS} --target ggml ggml-base ggml-cpu llama mtmd + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } tree /f - name: Upload artifacts (llama)