From a67287124d8879db7ab90a46aee787081e0bdfaf Mon Sep 17 00:00:00 2001 From: Andrew Moryakov Date: Mon, 4 May 2026 15:34:28 +0300 Subject: [PATCH] scripts : add build-zen.{sh,bat} helpers for AVX-512-capable CPUs (#1734) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds two thin one-liner-ish helpers that invoke `cmake` with the flag set documented in docs/build.md "CPU build flags for AVX-512", so that users on AMD Zen4 / Intel Sapphire Rapids+ hardware get the IQK HAVE_FANCY_SIMD path activated without having to remember the five relevant `GGML_AVX512_*=ON` options. scripts/build-zen.sh - Linux / macOS bash wrapper scripts/build-zen.bat - Windows MSVC wrapper (run from a "x64 Native Tools Command Prompt") Both default to a "build" output directory, both pass through to the same cmake invocation, and both work alongside the existing build options (no behavioural change to vanilla CMake builds). .gitignore: added `!scripts/build-*.sh` / `!scripts/build-*.bat` exceptions, in line with the existing `!build-info.sh` / `!build.zig` exceptions, so the scripts directory build helpers don't get caught by the broad `build*` artifact pattern. This is a follow-up to #1729 — the docs section explains why these flags matter, this PR makes them one command away. --- .gitignore | 2 ++ scripts/build-zen.bat | 27 +++++++++++++++++++++++++++ scripts/build-zen.sh | 29 +++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 scripts/build-zen.bat create mode 100644 scripts/build-zen.sh diff --git a/.gitignore b/.gitignore index df822228..81b0a7ef 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,8 @@ build* !build-info.sh !build.zig !docs/build.md +!scripts/build-*.sh +!scripts/build-*.bat /libllama.so /llama-* /vulkan-shaders-gen diff --git a/scripts/build-zen.bat b/scripts/build-zen.bat new file mode 100644 index 00000000..125bf307 --- /dev/null +++ b/scripts/build-zen.bat @@ -0,0 +1,27 @@ +@echo off +REM CPU-only build helper for AVX-512-capable CPUs (AMD Zen4 / Intel +REM Sapphire Rapids+) on Windows + MSVC. Enables the IQK GEMM kernels +REM gated by HAVE_FANCY_SIMD (see docs\build.md "CPU build flags for AVX-512"). +REM +REM Run from a Visual Studio "x64 Native Tools Command Prompt" so that +REM cl.exe and the rest of the MSVC toolchain are on PATH. +REM +REM Usage: +REM scripts\build-zen.bat [build-dir] +REM +REM Default build directory is "build". + +setlocal + +if "%~1"=="" (set BUILD_DIR=build) else (set BUILD_DIR=%~1) + +cmake -B "%BUILD_DIR%" -G "NMake Makefiles" ^ + -DCMAKE_BUILD_TYPE=Release ^ + -DGGML_NATIVE=ON ^ + -DGGML_AVX512=ON ^ + -DGGML_AVX512_VBMI=ON ^ + -DGGML_AVX512_VNNI=ON ^ + -DGGML_AVX512_BF16=ON +if errorlevel 1 exit /b 1 + +cmake --build "%BUILD_DIR%" --config Release diff --git a/scripts/build-zen.sh b/scripts/build-zen.sh new file mode 100644 index 00000000..eb88ee41 --- /dev/null +++ b/scripts/build-zen.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# CPU-only build helper for AVX-512-capable CPUs (AMD Zen4 / Intel +# Sapphire Rapids+). Enables the IQK GEMM kernels gated by HAVE_FANCY_SIMD +# (see docs/build.md "CPU build flags for AVX-512"). +# +# Usage: +# ./scripts/build-zen.sh [build-dir] +# +# Default build directory is "build". A subsequent +# +# objdump -d /bin/llama-cli | grep -c vpdpbusd +# +# should report a non-trivial count if VNNI was compiled in. The runtime +# banner of any built binary will print "HAVE_FANCY_SIMD is defined" when +# the AVX-512 quantized matmul path is active. + +set -e + +BUILD_DIR=${1:-build} + +cmake -B "$BUILD_DIR" \ + -DCMAKE_BUILD_TYPE=Release \ + -DGGML_NATIVE=ON \ + -DGGML_AVX512=ON \ + -DGGML_AVX512_VBMI=ON \ + -DGGML_AVX512_VNNI=ON \ + -DGGML_AVX512_BF16=ON + +cmake --build "$BUILD_DIR" --config Release -j