Skip to content

Distribute and run LLMs with a single file.

Update llama.cpp to b9747 (d6d8995) (#1000)

Davide Eynard8586c63a8c6a
diff --git a/llama.cpp b/llama.cpp
index dbe9c0c8..d6d89958 160000
--- a/llama.cpp
+++ b/llama.cpp
@@ -1 +1 @@
-Subproject commit dbe9c0c8ce65354c372f5d4ab507e5424a755e9f
+Subproject commit d6d899580dcf0e50a3d14453d3d082f6ed050450
diff --git a/llama.cpp.patches/README.md b/llama.cpp.patches/README.md
index 54341f27..17cdc695 100644
--- a/llama.cpp.patches/README.md
+++ b/llama.cpp.patches/README.md
@@ -8,6 +8,7 @@ This directory contains patches that adapt llama.cpp for use with Llamafile and
llama.cpp.patches/
├── README.md # This file
├── apply-patches.sh # Script to apply all patches to llama.cpp submodule
+├── fetch-ui-assets.sh # Downloads + validates the prebuilt web UI (see Server Integration)
├── renames.sh # Script for file renames/moves (if any)
├── llamafile-files/ # Additional files to copy into llama.cpp
│ ├── BUILD.mk # Makefile for building llama.cpp with cosmocc
@@ -75,7 +76,6 @@ These patches address compatibility issues when building with Cosmopolitan libc
| `common_arg.cpp.patch` | Adds `COSMOCC` platform detection for `PATH_MAX` (includes `linux/limits.h`) |
| `common_common.cpp.patch` | Adds platform-aware cache directory detection for Cosmopolitan (checks `LOCALAPPDATA`, `XDG_CACHE_HOME`, falls back to `~/.cache/`); also adds mmproj model size estimation to GPU fit params so the fit algorithm reserves enough VRAM for multimodal projectors |
| `common_download.cpp.patch` | Adds `COSMOCC` platform detection for `PATH_MAX` |
-| `common_ngram-mod.cpp.patch` | Adds missing `#include <algorithm>` (needed for `std::min`/`std::max`) |
### Threading and Signal Handling
@@ -84,7 +84,7 @@ Cosmopolitan libc has specific behaviors with condition variables and signals th
| Patch | Description |
|-------|-------------|
| `common_log.cpp.patch` | Adds `#include <csignal>`; blocks `SIGINT`/`SIGTERM` on logger thread via `pthread_sigmask` to prevent `EINTR` exceptions; replaces `cv.wait()` with `wait_for(30s)` loop to work around XNU futex timeout bug (~72 minute expiry) |
-| `tools_server_server-models.cpp.patch` | Adds `#include <csignal>`; blocks `SIGINT`/`SIGTERM` on stopping thread; replaces `cv.wait()` with `wait_for(30s)` loops in `unload_lru`, `stopping_thread`, and `wait_until_loading_finished` |
+| `tools_server_server-models.cpp.patch` | Adds `#include <csignal>`; blocks signals on the stopping thread via `pthread_sigmask`; replaces untimed `cv.wait()` with `wait_for(30s)` loops on every model-lifecycle wait (`unload_lru`, the reload-drain wait, `stopping_thread`, the `is_reloading` guard in `load`, and the generic `wait()` predicate helper) to work around the XNU futex timeout bug |
| `tools_server_server-queue.cpp.patch` | Adds missing includes (`<cerrno>`, `<system_error>`, `<csignal>`); blocks `SIGINT`/`SIGTERM` on queue thread; replaces `wait()` with `wait_for()` loops in three locations (`wait_until_no_sleep`, main loop, `recv`) |
| `vendor_cpp-httplib_httplib.cpp.patch` | Fixes httplib thread pool with `wait_for()` instead of `wait()` for XNU futex compatibility |
@@ -137,19 +137,43 @@ These patches integrate llamafile's file handling APIs for loading models from b
| `tools_server_server.cpp.patch` | Renames upstream's `llama_server()` to `server_main()` and adds `on_ready`/`on_shutdown_available` callbacks for combined TUI+server mode; adds Metal/GPU backend trigger before `common_init()`; adds Cosmopolitan-specific standalone `main()` with `cosmo_args`, verbose flag handling, and GPU pre-initialization; handles `LLAMAFILE_TUI` exit to avoid Metal cleanup crashes |
The web UI moved upstream from prebuilt `tools/server/public/*` assets to
-a Svelte project under `tools/ui/`, embedded at CMake time via
-`tools/ui/embed.cpp`. cosmocc has no JS toolchain, so `apply-patches.sh`
-(run by `make setup`) downloads the prebuilt Svelte bundle from the
-`ggml-org/llama-ui` Hugging Face bucket into `llama.cpp/tools/ui/dist/`.
+a Svelte/PWA project under `tools/ui/`, embedded at CMake time via
+`tools/ui/embed.cpp`. cosmocc has no JS toolchain, so `fetch-ui-assets.sh`
+(run by `apply-patches.sh` / `make setup`) downloads the prebuilt site
+**tarball** `dist.tar.gz` (plus its `.sha256`) from the `ggml-org/llama-ui`
+Hugging Face bucket — picking the newest `bNNNN` tag `<=` our pinned build —
+verifies it, and extracts the whole static site into
+`llama.cpp/tools/ui/dist/`. The modern site is no longer four flat files
+(`bundle.css`/`bundle.js`/`index.html`/`loading.html`) but a hashed tree
+(`_app/immutable/bundle.HASH.js`, a service worker, manifest, icons, splash
+screens). To keep the embedded payload small, the script also builds a
+`dist/_gzip/` mirror with every file gzip-compressed under its original name.
+
At build time, `llama.cpp/BUILD.mk` compiles `tools/ui/embed.cpp` with
-`cosmoc++` (its APE output runs on the host) and runs it against the
-downloaded assets to emit `o/$(MODE)/llama.cpp/tools/ui/ui.{cpp,h}`,
-which is then compiled like any other C++ source and linked into
-`llama-server` and `llamafile`. If the download fails (offline, version
-not yet on HF) `apply-patches.sh` warns and continues with `dist/`
-empty — `embed.cpp` then emits a no-op `llama_ui_find_asset`, and
-`server-http.cpp` skips UI route registration via its
-`LLAMA_UI_HAS_ASSETS` guard so the API still works.
+`cosmoc++` (its APE output runs on the host) and runs it against the `dist/`
+**directory** (the new `embed <out_cpp> <out_h> [<asset_dir>]` interface):
+`embed.cpp` recursively bakes every file — auto-detecting `dist/_gzip/` and
+emitting gzip-encoded assets keyed by relative path — into
+`o/$(MODE)/llama.cpp/tools/ui/ui.{cpp,h}`, which is compiled like any other
+C++ source and linked into `llama-server` and `llamafile`. Upstream's
+`server-http.cpp` (unpatched) registers a route per embedded asset
+(`index.html` at `/`) and serves gzip assets with `Content-Encoding: gzip`.
+If the download fails (offline, version not yet on HF) the script leaves
+`dist/` empty — `embed.cpp` then emits a no-op `llama_ui_find_asset` and the
+`LLAMA_UI_HAS_ASSETS` guard keeps the UI routes unregistered, so the REST
+API still works.
+
+Note that `embed.cpp` only takes that graceful no-asset path when `dist/` is
+*empty*: once the directory is non-empty it enforces a required-asset set
+(its `required_check[]` table — `index.html`, `loading.html`,
+`manifest.webmanifest`, `sw.js`, `build.json`, `version.json`, and the hashed
+`bundle*.js`/`bundle*.css`/`workbox*.js`) and returns a hard error if any is
+missing. So `fetch-ui-assets.sh` validates the *same* set after extracting
+(`ui_missing_assets`); if a downloaded tarball is partial or has drifted, it
+clears `dist/` and falls back to a UI-less build rather than letting the embed
+step abort the whole build. Because `embed.cpp` is an upstream file, that list
+can change on a llama.cpp bump — when it does, the asset list in
+`ui_missing_assets` must be updated to match.
### Bug Fixes
@@ -158,6 +182,7 @@ empty — `embed.cpp` then emits a no-op `llama_ui_find_asset`, and
| `ggml_src_ggml-backend-reg.cpp.patch` | Suppresses debug log noise for non-existent backend search paths (irrelevant for llamafile's DSO loading approach) |
| `ggml_src_ggml-vulkan_ggml-vulkan.cpp.patch` | Fixes unsigned integer underflow in `ggml_backend_vk_get_device_memory` where Vulkan's `heapUsage` can exceed `heapBudget` (clamps to zero instead of wrapping) |
| `src_models_t5.cpp.patch` | Forward-declares the `graph<false>`/`graph<true>` explicit specializations before `build_arch_graph` so clang's `-std=gnu++23` doesn't reject them as specializations after implicit instantiation |
+| `src_models_eagle3.cpp.patch` | Moves `build_arch_graph` to the end of the file, after the `graph<true>`/`graph<false>` constructor specializations, so clang's `-std=gnu++23` doesn't reject them as explicit specializations appearing after the `make_unique<graph<...>>` implicit instantiation point |
## Creating New Patches
diff --git a/llama.cpp.patches/fetch-ui-assets.sh b/llama.cpp.patches/fetch-ui-assets.sh
index e0d80561..c77bada1 100755
--- a/llama.cpp.patches/fetch-ui-assets.sh
+++ b/llama.cpp.patches/fetch-ui-assets.sh
@@ -1,12 +1,21 @@
#!/bin/bash
# Fetch the prebuilt llama.cpp web UI assets from Hugging Face.
#
-# Upstream's tools/ui/scripts/ui-assets.cmake pulls the Svelte build outputs
-# from the ggml-org/llama-ui HF bucket. We do the same here so the cosmocc
-# build never has to run a JS toolchain. If the fetch fails (no network,
-# version not yet published, HF down) we leave tools/ui/dist empty; BUILD.mk's
-# embed step then generates a no-asset ui.cpp and the server still works, just
-# without the web UI.
+# Upstream ships the Svelte/PWA web UI as a `dist.tar.gz` tarball (plus a
+# matching `dist.tar.gz.sha256`) in the ggml-org/llama-ui HF bucket, one
+# directory per bNNNN build. We download the tarball for the build matching our
+# pinned llama.cpp, verify it, and extract the full static site into
+# llama.cpp/tools/ui/dist/. BUILD.mk then runs tools/ui/embed.cpp over that
+# directory to bake every file into ui.cpp/ui.h.
+#
+# To keep the embedded payload (and the final binaries) small, we also build a
+# dist/_gzip/ mirror with every file gzip-compressed under its original name;
+# embed.cpp auto-detects _gzip and emits gzip-encoded assets, which
+# server-http.cpp serves with Content-Encoding: gzip.
+#
+# If anything fails (no network, version not yet published, HF down) we leave
+# tools/ui/dist empty; BUILD.mk's embed step then generates a no-asset ui.cpp
+# and the server still works, just without the web UI.
#
# Run by apply-patches.sh (i.e. `make setup`); also safe to run standalone to
# re-fetch the UI without re-applying patches.
@@ -20,7 +29,6 @@ HF_BUCKET="${LLAMAFILE_UI_HF_BUCKET:-llama-ui}"
HF_BASE="https://huggingface.co/buckets/ggml-org/${HF_BUCKET}/resolve"
HF_TREE_API="https://huggingface.co/api/buckets/ggml-org/${HF_BUCKET}/tree"
UI_DIST="$LLAMA_DIR/tools/ui/dist"
-UI_ASSETS=(bundle.css bundle.js index.html loading.html)
# Echo the highest bNNNN tag in the bucket whose build number is <= $1, or
# nothing. The tree API returns directories in ascending order, 100 per page,
@@ -56,6 +64,53 @@ pick_ui_tag() {
[ -n "$best" ] && printf 'b%s' "$best"
}
+# Build the dist/_gzip/ mirror: every regular file under dist/, gzip-compressed
+# under its original relative path. embed.cpp prefers _gzip when present.
+build_gzip_mirror() {
+ ( cd "$UI_DIST" && find . -type f ! -path './_gzip/*' -print0 \
+ | while IFS= read -r -d '' f; do
+ mkdir -p "_gzip/$(dirname "$f")"
+ gzip -9 -c "$f" > "_gzip/$f"
+ done )
+}
+
+# Echo (one per line) any asset embed.cpp requires that is absent from the tree.
+#
+# !!! KEEP IN SYNC WITH UPSTREAM tools/ui/embed.cpp !!!
+# The list below mirrors the required_check[] table in llama.cpp/tools/ui/embed.cpp.
+# Once dist/ is non-empty, embed.cpp hard-fails the build (return 1) if any of
+# those assets is missing. If we only checked index.html here, a partial/drifted
+# tarball would pass our check but then abort the *entire* build at the embed
+# step instead of falling back to a UI-less build. So we validate the same set
+# embed.cpp does and, when it's incomplete, clear dist/ to take the UI-less path.
+#
+# embed.cpp is an UPSTREAM file, so it can change on a llama.cpp bump. When it
+# does (a new required asset, a renamed one), this list must be updated to match
+# -- otherwise the two checks disagree again and the build-failure bug returns.
+ui_missing_assets() {
+ local root="$1" f b
+ local -a bases=()
+ while IFS= read -r f; do
+ bases+=("$(basename "$f")")
+ done < <(find "$root" -type f ! -path '*/_gzip/*' 2>/dev/null)
+
+ _have() { # _have <case-glob> : true if any basename matches
+ for b in "${bases[@]}"; do
+ case "$b" in $1) return 0 ;; esac
+ done
+ return 1
+ }
+ _have 'index.html' || echo 'index.html'
+ _have 'loading.html' || echo 'loading.html'
+ _have 'manifest.webmanifest' || echo 'manifest.webmanifest'
+ _have 'sw.js' || echo 'sw.js'
+ _have 'build.json' || echo 'build.json'
+ _have 'version.json' || echo 'version.json'
+ _have 'bundle*.js' || echo 'bundle[hash].js'
+ _have 'bundle*.css' || echo 'bundle[hash].css'
+ _have 'workbox*.js' || echo 'workbox[hash].js'
+}
+
echo ""
echo "Fetching prebuilt web UI assets from Hugging Face..."
@@ -83,53 +138,76 @@ if [ -n "$UI_CUR_BUILD" ]; then
fi
UI_CANDIDATES+=("latest")
+# Pick a sha256 tool (verification is preferred but best-effort).
+if command -v shasum >/dev/null 2>&1; then
+ sha_cmd="shasum -a 256"
+elif command -v sha256sum >/dev/null 2>&1; then
+ sha_cmd="sha256sum"
+else
+ sha_cmd=""
+fi
+
mkdir -p "$UI_DIST"
ui_ok=false
for v in "${UI_CANDIDATES[@]}"; do
- echo " trying $HF_BASE/$v ..."
- fail=false
- for asset in "${UI_ASSETS[@]}" checksums.txt; do
- if ! curl -fsSL --max-time 60 -o "$UI_DIST/$asset" \
- "$HF_BASE/$v/$asset?download=true"; then
- fail=true
- break
- fi
- done
- if $fail; then
+ echo " trying $HF_BASE/$v/dist.tar.gz ..."
+ tmp="$(mktemp -d)"
+
+ if ! curl -fsSL --max-time 120 -o "$tmp/dist.tar.gz" \
+ "$HF_BASE/$v/dist.tar.gz?download=true"; then
+ rm -rf "$tmp"
continue
fi
- # Best-effort sha256 verification against checksums.txt (one "<hash> <name>"
- # line per asset). Skip if shasum/sha256sum isn't around.
- if command -v shasum >/dev/null 2>&1; then
- sha_cmd="shasum -a 256"
- elif command -v sha256sum >/dev/null 2>&1; then
- sha_cmd="sha256sum"
- else
- sha_cmd=""
- fi
- if [ -n "$sha_cmd" ] && [ -f "$UI_DIST/checksums.txt" ]; then
- bad=false
- for asset in "${UI_ASSETS[@]}"; do
- want=$(awk -v a="$asset" '$2 == a { print $1 }' "$UI_DIST/checksums.txt")
- got=$($sha_cmd "$UI_DIST/$asset" | awk '{print $1}')
- if [ -z "$want" ] || [ "$want" != "$got" ]; then
- echo " checksum mismatch for $asset (want=$want got=$got)"
- bad=true
- break
- fi
- done
- if $bad; then
+ # Verify the tarball against its published checksum when we can.
+ if [ -n "$sha_cmd" ] && curl -fsSL --max-time 30 -o "$tmp/dist.tar.gz.sha256" \
+ "$HF_BASE/$v/dist.tar.gz.sha256?download=true"; then
+ want=$(awk '{print $1}' "$tmp/dist.tar.gz.sha256")
+ got=$($sha_cmd "$tmp/dist.tar.gz" | awk '{print $1}')
+ if [ -n "$want" ] && [ "$want" != "$got" ]; then
+ echo " checksum mismatch for dist.tar.gz (want=$want got=$got)"
+ rm -rf "$tmp"
continue
fi
fi
- echo " fetched UI assets from $v"
+ # Replace dist/ atomically-ish: clear it, then extract the new tree. Use
+ # -m so extracted files get the current mtime instead of the archive's
+ # (otherwise an incremental build sees the assets as older than a stale
+ # generated ui.cpp and skips regenerating it).
+ rm -rf "$UI_DIST"
+ mkdir -p "$UI_DIST"
+ if ! tar xzmf "$tmp/dist.tar.gz" -C "$UI_DIST" 2>/dev/null; then
+ echo " failed to extract dist.tar.gz"
+ rm -rf "$tmp" "$UI_DIST"
+ mkdir -p "$UI_DIST"
+ continue
+ fi
+ rm -rf "$tmp"
+
+ # Reject a partial/drifted tree: embed.cpp requires the full asset set once
+ # dist/ is non-empty and would otherwise abort the entire build. Clearing
+ # dist/ here lets the embed step generate the no-asset stub instead, so the
+ # server still builds (just without the web UI).
+ missing="$(ui_missing_assets "$UI_DIST")"
+ if [ -n "$missing" ]; then
+ echo " extracted tree is missing required asset(s); ignoring:"
+ printf ' %s\n' $missing
+ rm -rf "$UI_DIST"
+ mkdir -p "$UI_DIST"
+ continue
+ fi
+
+ build_gzip_mirror
+
+ nfiles=$(find "$UI_DIST" -type f ! -path '*/_gzip/*' | wc -l | tr -d ' ')
+ echo " fetched + extracted UI assets from $v ($nfiles files, gzip-embedded)"
ui_ok=true
break
done
if ! $ui_ok; then
echo " warning: could not download UI assets; server will build without the web UI"
- rm -f "$UI_DIST"/*
+ rm -rf "$UI_DIST"
+ mkdir -p "$UI_DIST"
fi
diff --git a/llama.cpp.patches/llamafile-files/BUILD.mk b/llama.cpp.patches/llamafile-files/BUILD.mk
index 84e02c33..32ab1470 100644
--- a/llama.cpp.patches/llamafile-files/BUILD.mk
+++ b/llama.cpp.patches/llamafile-files/BUILD.mk
@@ -68,15 +68,18 @@ LLAMA_SRCS_CPP := \
llama.cpp/src/models/codeshell.cpp \
llama.cpp/src/models/cogvlm.cpp \
llama.cpp/src/models/cohere2.cpp \
+ llama.cpp/src/models/cohere2moe.cpp \
llama.cpp/src/models/command-r.cpp \
llama.cpp/src/models/dbrx.cpp \
llama.cpp/src/models/deci.cpp \
llama.cpp/src/models/deepseek.cpp \
llama.cpp/src/models/deepseek2.cpp \
llama.cpp/src/models/deepseek2ocr.cpp \
+ llama.cpp/src/models/deepseek32.cpp \
llama.cpp/src/models/delta-net-base.cpp \
llama.cpp/src/models/dots1.cpp \
llama.cpp/src/models/dream.cpp \
+ llama.cpp/src/models/eagle3.cpp \
llama.cpp/src/models/ernie4-5-moe.cpp \
llama.cpp/src/models/ernie4-5.cpp \
llama.cpp/src/models/eurobert.cpp \
@@ -90,6 +93,7 @@ LLAMA_SRCS_CPP := \
llama.cpp/src/models/gemma2.cpp \
llama.cpp/src/models/gemma3.cpp \
llama.cpp/src/models/gemma3n.cpp \
+ llama.cpp/src/models/gemma4-assistant.cpp \
llama.cpp/src/models/gemma4.cpp \
llama.cpp/src/models/glm-dsa.cpp \
llama.cpp/src/models/glm4-moe.cpp \
@@ -122,6 +126,7 @@ LLAMA_SRCS_CPP := \
llama.cpp/src/models/maincoder.cpp \
llama.cpp/src/models/mamba.cpp \
llama.cpp/src/models/mamba2.cpp \
+ llama.cpp/src/models/mellum.cpp \
llama.cpp/src/models/mimo2.cpp \
llama.cpp/src/models/minicpm.cpp \
llama.cpp/src/models/minicpm3.cpp \
@@ -192,6 +197,7 @@ LLAMA_SRCS_CPP := \
llama.cpp/src/llama-hparams.cpp \
llama.cpp/src/llama-impl.cpp \
llama.cpp/src/llama-io.cpp \
+ llama.cpp/src/llama-kv-cache-dsa.cpp \
llama.cpp/src/llama-kv-cache-iswa.cpp \
llama.cpp/src/llama-kv-cache.cpp \
llama.cpp/src/llama-memory-hybrid.cpp \
@@ -227,6 +233,7 @@ COMMON_SRCS_CPP := \
llama.cpp/common/download.cpp \
llama.cpp/common/fit.cpp \
llama.cpp/common/hf-cache.cpp \
+ llama.cpp/common/imatrix-loader.cpp \
llama.cpp/common/jinja/caps.cpp \
llama.cpp/common/jinja/lexer.cpp \
llama.cpp/common/jinja/parser.cpp \
@@ -302,12 +309,17 @@ MTMD_SRCS_CPP := \
llama.cpp/tools/mtmd/mtmd-image.cpp \
llama.cpp/tools/mtmd/models/cogvlm.cpp \
llama.cpp/tools/mtmd/models/deepseekocr.cpp \
+ llama.cpp/tools/mtmd/models/deepseekocr2.cpp \
llama.cpp/tools/mtmd/models/conformer.cpp \
llama.cpp/tools/mtmd/models/dotsocr.cpp \
+ llama.cpp/tools/mtmd/models/exaone4_5.cpp \
llama.cpp/tools/mtmd/models/gemma4a.cpp \
+ llama.cpp/tools/mtmd/models/gemma4ua.cpp \
+ llama.cpp/tools/mtmd/models/gemma4uv.cpp \
llama.cpp/tools/mtmd/models/gemma4v.cpp \
llama.cpp/tools/mtmd/models/glm4v.cpp \
llama.cpp/tools/mtmd/models/granite-speech.cpp \
+ llama.cpp/tools/mtmd/models/granite4-vision.cpp \
llama.cpp/tools/mtmd/models/hunyuanvl.cpp \
llama.cpp/tools/mtmd/models/internvl.cpp \
llama.cpp/tools/mtmd/models/kimik25.cpp \
@@ -343,16 +355,20 @@ HTTPLIB_OBJS := $(HTTPLIB_SRCS:%.cpp=o/$(MODE)/%.cpp.o)
# ==============================================================================
#
# Upstream switched from prebuilt bundles in tools/server/public/ to a
-# Svelte project under tools/ui/, embedded at CMake time by
+# Svelte/PWA project under tools/ui/, embedded at CMake time by
# tools/ui/embed.cpp into a generated ui.cpp + ui.h. cosmocc has no JS
# toolchain, so apply-patches.sh (run by `make setup`) downloads the
-# prebuilt Svelte bundle from the ggml-org/llama-ui Hugging Face bucket
-# into llama.cpp/tools/ui/dist/. Here we compile embed.cpp with cosmocc
-# (its APE output runs on the host) and run it against whatever's in
-# dist/ to emit ui.cpp/ui.h. With assets present, ui.h defines
-# LLAMA_UI_HAS_ASSETS and server-http.cpp wires up /, /bundle.js,
-# /bundle.css; without them, embed.cpp emits a no-op llama_ui_find_asset
-# and the routes stay unregistered.
+# prebuilt site tarball (dist.tar.gz) from the ggml-org/llama-ui Hugging
+# Face bucket and extracts the whole static site into
+# llama.cpp/tools/ui/dist/ (see fetch-ui-assets.sh). embed.cpp then
+# recursively embeds every file under that directory, keyed by its
+# relative path (e.g. "_app/immutable/bundle.HASH.js"). fetch-ui-assets.sh
+# also builds a dist/_gzip/ mirror of gzip-compressed files; embed.cpp
+# auto-detects it and emits gzip-encoded assets (keeping the embedded
+# payload small), which server-http.cpp serves with Content-Encoding: gzip.
+# With assets present, ui.h defines LLAMA_UI_HAS_ASSETS and server-http.cpp
+# registers a route per asset (index.html at /); without them, embed.cpp
+# emits a no-op llama_ui_find_asset and the UI routes stay unregistered.
UI_DIST := llama.cpp/tools/ui/dist
UI_GEN_DIR := o/$(MODE)/llama.cpp/tools/ui
@@ -361,37 +377,29 @@ UI_EMBED_TOOL := $(UI_GEN_DIR)/llama-ui-embed
UI_CPP_GEN := $(UI_GEN_DIR)/ui.cpp
UI_H_GEN := $(UI_GEN_DIR)/ui.h
-# Assets we ask embed to bundle if they exist. wildcard returns "" for
-# missing files, which lets the build proceed UI-less when offline.
-UI_ASSETS_BUNDLE_CSS := $(wildcard $(UI_DIST)/bundle.css)
-UI_ASSETS_BUNDLE_JS := $(wildcard $(UI_DIST)/bundle.js)
+# index.html exists iff fetch-ui-assets.sh successfully populated dist/. It
+# serves both as the "do we have a UI?" gate and as the rebuild trigger: it is
+# rewritten on every fetch and references the hashed bundle names, so it
+# changes whenever the embedded assets do. wildcard returns "" when absent,
+# letting the build proceed UI-less (offline / asset build not yet published).
UI_ASSETS_INDEX_HTML := $(wildcard $(UI_DIST)/index.html)
-UI_ASSETS_LOADING_HTML := $(wildcard $(UI_DIST)/loading.html)
-UI_ASSETS_FILES := \
- $(UI_ASSETS_BUNDLE_CSS) \
- $(UI_ASSETS_BUNDLE_JS) \
- $(UI_ASSETS_INDEX_HTML) \
- $(UI_ASSETS_LOADING_HTML)
# Build embed.cpp standalone (no llamafile flags, no llama.cpp includes).
# cosmoc++ produces an APE that runs on the build host, so we don't need
-# a separate system compiler. Compiled with stock C++17 so the source
-# isn't entangled with -DCOSMOCC or the GGML defines.
+# a separate system compiler. Compiled with stock C++17 (embed.cpp uses
+# <filesystem>) so the source isn't entangled with -DCOSMOCC or GGML defines.
$(UI_EMBED_TOOL): $(UI_EMBED_SRC) $(COSMOCC)
@mkdir -p $(@D)
$(CXX) -O2 -std=gnu++17 -o $@ $<
-# Generate ui.cpp/ui.h. Re-run whenever the embed tool or any dist asset
-# changes. The recipe passes <name> <path> pairs only for assets that
-# actually exist on disk; missing files are silently skipped, matching
-# the behaviour of embed.cpp's "no assets -> stub" mode.
-$(UI_CPP_GEN) $(UI_H_GEN) &: $(UI_EMBED_TOOL) $(UI_ASSETS_FILES)
+# Generate ui.cpp/ui.h. Re-run when the embed tool or the fetched UI changes.
+# When dist/ has assets, pass the directory: embed.cpp recurses it (auto-using
+# dist/_gzip when present). When dist/ is empty, pass no directory so embed
+# emits its no-asset stub.
+$(UI_CPP_GEN) $(UI_H_GEN) &: $(UI_EMBED_TOOL) $(UI_ASSETS_INDEX_HTML)
@mkdir -p $(UI_GEN_DIR)
$(UI_EMBED_TOOL) $(UI_CPP_GEN) $(UI_H_GEN) \
- $(if $(UI_ASSETS_BUNDLE_CSS),bundle.css $(UI_ASSETS_BUNDLE_CSS)) \
- $(if $(UI_ASSETS_BUNDLE_JS),bundle.js $(UI_ASSETS_BUNDLE_JS)) \
- $(if $(UI_ASSETS_INDEX_HTML),index.html $(UI_ASSETS_INDEX_HTML)) \
- $(if $(UI_ASSETS_LOADING_HTML),loading.html $(UI_ASSETS_LOADING_HTML))
+ $(if $(UI_ASSETS_INDEX_HTML),$(UI_DIST))
# ==============================================================================
# Tools (in tools/ directory)
@@ -411,6 +419,7 @@ TOOL_SERVER_SRCS := \
llama.cpp/tools/server/server-http.cpp \
llama.cpp/tools/server/server-models.cpp \
llama.cpp/tools/server/server-queue.cpp \
+ llama.cpp/tools/server/server-schema.cpp \
llama.cpp/tools/server/server-task.cpp \
llama.cpp/tools/server/server-tools.cpp
diff --git a/llama.cpp.patches/patches/common_arg.cpp.patch b/llama.cpp.patches/patches/common_arg.cpp.patch
index 4626cffa..153f0ac0 100644
--- a/llama.cpp.patches/patches/common_arg.cpp.patch
+++ b/llama.cpp.patches/patches/common_arg.cpp.patch
@@ -1,7 +1,7 @@
diff --git a/common/arg.cpp b/common/arg.cpp
--- a/llama.cpp/common/arg.cpp
+++ b/llama.cpp/common/arg.cpp
-@@ -37,6 +37,8 @@
+@@ -38,6 +38,8 @@
#ifndef __EMSCRIPTEN__
#ifdef __linux__
#include <linux/limits.h>
diff --git a/llama.cpp.patches/patches/common_common.cpp.patch b/llama.cpp.patches/patches/common_common.cpp.patch
index 33e2cae0..91d50635 100644
--- a/llama.cpp.patches/patches/common_common.cpp.patch
+++ b/llama.cpp.patches/patches/common_common.cpp.patch
@@ -69,7 +69,7 @@ diff --git a/common/common.cpp b/common/common.cpp
#elif defined(__EMSCRIPTEN__)
GGML_ABORT("not implemented on this platform");
#else
-@@ -1189,10 +1234,31 @@ common_init_result::common_init_result(common_params & params, bool model_only)
+@@ -1201,10 +1246,31 @@ common_init_result::common_init_result(common_params & params, bool model_only)
if (params.fit_params) {
LOG_INF("%s: fitting params to device memory ...\n", __func__);
LOG_INF("%s: (for bugs during this step try to reproduce them with -fit off, or provide --verbose logs if the bug only occurs with -fit on)\n", __func__);
diff --git a/llama.cpp.patches/patches/common_log.cpp.patch b/llama.cpp.patches/patches/common_log.cpp.patch
index 99499705..5b7215cc 100644
--- a/llama.cpp.patches/patches/common_log.cpp.patch
+++ b/llama.cpp.patches/patches/common_log.cpp.patch
@@ -1,7 +1,7 @@
diff --git a/common/log.cpp b/common/log.cpp
--- a/llama.cpp/common/log.cpp
+++ b/llama.cpp/common/log.cpp
-@@ -19,6 +19,7 @@
+@@ -24,6 +24,7 @@
# define fileno _fileno
#else
# include <unistd.h>
@@ -9,12 +9,12 @@ diff --git a/common/log.cpp b/common/log.cpp
#endif // defined(_WIN32)
int common_log_verbosity_thold = LOG_DEFAULT_LLAMA;
-@@ -260,10 +261,33 @@ public:
+@@ -265,9 +266,32 @@ public:
running = true;
thrd = std::thread([this]() {
+#if !defined(_WIN32)
-+ // Block every signal on this thread so pthread_cond_timedwait()
++ // Block every signal on this thread so the condition-variable wait
+ // can't be interrupted with EINTR (libcxx rethrows EINTR as
+ // std::system_error which would std::terminate the process).
+ // Keep synchronous fault signals deliverable so real crashes
@@ -31,16 +31,15 @@ diff --git a/common/log.cpp b/common/log.cpp
+ pthread_sigmask(SIG_BLOCK, &block_mask, nullptr);
+#endif
while (true) {
- {
- std::unique_lock<std::mutex> lock(mtx);
-- cv.wait(lock, [this]() { return head != tail; });
-+ // Use wait_for() instead of wait() to work around a
-+ // Cosmopolitan libc bug where untimed futex waits on
-+ // XNU (macOS) expire after ~72 minutes, causing
-+ // condition_variable::wait() to throw ETIMEDOUT.
-+ while (head == tail) {
-+ cv.wait_for(lock, std::chrono::seconds(30));
-+ }
- cur = entries[head];
+ std::unique_lock<std::mutex> lock(mtx);
+- cv_new.wait(lock, [this]() { return !is_empty(); });
++ // Use wait_for() instead of an untimed wait to work around a
++ // Cosmopolitan libc bug where untimed futex waits on XNU
++ // (macOS) expire after ~72 minutes, causing
++ // condition_variable::wait() to throw ETIMEDOUT.
++ while (is_empty()) {
++ cv_new.wait_for(lock, std::chrono::seconds(30));
++ }
- head = (head + 1) % entries.size();
+ size_t cached_head = head;
+ size_t cached_tail = tail;
diff --git a/llama.cpp.patches/patches/common_ngram-mod.cpp.patch b/llama.cpp.patches/patches/common_ngram-mod.cpp.patch
deleted file mode 100644
index fe4026e0..00000000
--- a/llama.cpp.patches/patches/common_ngram-mod.cpp.patch
+++ /dev/null
@@ -1,11 +0,0 @@
-diff --git a/common/ngram-mod.cpp b/common/ngram-mod.cpp
---- a/llama.cpp/common/ngram-mod.cpp
-+++ b/llama.cpp/common/ngram-mod.cpp
-@@ -1,5 +1,7 @@
- #include "ngram-mod.h"
-
-+#include <algorithm>
-+
- //
- // common_ngram_mod
- //
diff --git a/llama.cpp.patches/patches/ggml_src_ggml-backend-meta.cpp.patch b/llama.cpp.patches/patches/ggml_src_ggml-backend-meta.cpp.patch
index e780df58..ef308ea0 100644
--- a/llama.cpp.patches/patches/ggml_src_ggml-backend-meta.cpp.patch
+++ b/llama.cpp.patches/patches/ggml_src_ggml-backend-meta.cpp.patch
@@ -141,7 +141,7 @@ diff --git a/ggml/src/ggml-backend-meta.cpp b/ggml/src/ggml-backend-meta.cpp
GGML_ASSERT(ggml_backend_buffer_is_meta(buffer));
ggml_backend_meta_buffer_context * buf_ctx = (ggml_backend_meta_buffer_context *) buffer->context;
delete buf_ctx;
-@@ -1122,7 +1122,7 @@ static struct ggml_backend_meta_split_state ggml_backend_meta_get_split_state(co
+@@ -1116,7 +1116,7 @@ static struct ggml_backend_meta_split_state ggml_backend_meta_get_split_state(co
return ggml_backend_meta_get_split_state(buf_ctx->get_simple_tensor_container(tensor), tensor, assume_sync);
}
@@ -150,7 +150,7 @@ diff --git a/ggml/src/ggml-backend-meta.cpp b/ggml/src/ggml-backend-meta.cpp
GGML_UNUSED(buffer);
return (void *) 0x1000000000000000; // FIXME
}
-@@ -1242,14 +1242,14 @@ static enum ggml_status ggml_backend_meta_buffer_init_tensor_impl(ggml_backend_m
+@@ -1236,14 +1236,14 @@ static enum ggml_status ggml_backend_meta_buffer_init_tensor_impl(ggml_backend_m
return GGML_STATUS_SUCCESS;
}
@@ -167,7 +167,7 @@ diff --git a/ggml/src/ggml-backend-meta.cpp b/ggml/src/ggml-backend-meta.cpp
const size_t n_bufs = ggml_backend_meta_buffer_n_bufs(buffer);
GGML_ASSERT(ggml_is_contiguous(tensor));
-@@ -1359,7 +1359,7 @@ static void ggml_backend_meta_buffer_set_tensor(ggml_backend_buffer_t buffer, gg
+@@ -1358,7 +1358,7 @@ static void ggml_backend_meta_buffer_set_tensor(ggml_backend_buffer_t buffer, gg
}
}
@@ -176,7 +176,7 @@ diff --git a/ggml/src/ggml-backend-meta.cpp b/ggml/src/ggml-backend-meta.cpp
const size_t n_bufs = ggml_backend_meta_buffer_n_bufs(buffer);
GGML_ASSERT(ggml_is_contiguous(tensor));
-@@ -1455,14 +1455,14 @@ static void ggml_backend_meta_buffer_get_tensor(ggml_backend_buffer_t buffer, co
+@@ -1459,14 +1459,14 @@ static void ggml_backend_meta_buffer_get_tensor(ggml_backend_buffer_t buffer, co
}
}
@@ -193,7 +193,7 @@ diff --git a/ggml/src/ggml-backend-meta.cpp b/ggml/src/ggml-backend-meta.cpp
GGML_ASSERT(ggml_backend_buffer_is_meta(buffer));
ggml_backend_meta_buffer_context * buf_ctx = (ggml_backend_meta_buffer_context *) buffer->context;
for (size_t i = 0; i < buf_ctx->bufs.size(); i++) {
-@@ -1488,7 +1488,7 @@ bool ggml_backend_buffer_is_meta(ggml_backend_buffer_t buf) {
+@@ -1492,7 +1492,7 @@ bool ggml_backend_buffer_is_meta(ggml_backend_buffer_t buf) {
return buf != nullptr && buf->iface.free_buffer == ggml_backend_meta_buffer_iface.free_buffer;
}
@@ -202,7 +202,7 @@ diff --git a/ggml/src/ggml-backend-meta.cpp b/ggml/src/ggml-backend-meta.cpp
const size_t n_simple_bufts = ggml_backend_meta_buft_n_bufts(buft);
const ggml_init_params params = {
-@@ -1655,20 +1655,20 @@ struct ggml_backend_meta_context {
+@@ -1659,20 +1659,20 @@ struct ggml_backend_meta_context {
}
};
@@ -226,7 +226,7 @@ diff --git a/ggml/src/ggml-backend-meta.cpp b/ggml/src/ggml-backend-meta.cpp
const size_t n_backends = ggml_backend_meta_n_backends(backend);
GGML_ASSERT(offset == 0);
GGML_ASSERT(ggml_is_contiguous(tensor));
-@@ -1712,7 +1712,7 @@ static void ggml_backend_meta_set_tensor_async(ggml_backend_t backend, ggml_tens
+@@ -1717,7 +1717,7 @@ static void ggml_backend_meta_set_tensor_async(ggml_backend_t backend, ggml_tens
}
}
@@ -235,7 +235,7 @@ diff --git a/ggml/src/ggml-backend-meta.cpp b/ggml/src/ggml-backend-meta.cpp
const size_t n_backends = ggml_backend_meta_n_backends(backend);
GGML_ASSERT(offset == 0);
GGML_ASSERT(ggml_is_contiguous(tensor));
-@@ -1756,14 +1756,14 @@ static void ggml_backend_meta_get_tensor_async(ggml_backend_t backend, const ggm
+@@ -1762,14 +1762,14 @@ static void ggml_backend_meta_get_tensor_async(ggml_backend_t backend, const ggm
}
}
@@ -252,7 +252,7 @@ diff --git a/ggml/src/ggml-backend-meta.cpp b/ggml/src/ggml-backend-meta.cpp
GGML_ASSERT(cgraph->grads == nullptr);
const size_t n_backends = ggml_backend_meta_n_backends(backend);
ggml_backend_meta_context * backend_ctx = (ggml_backend_meta_context *) backend->context;
-@@ -2232,7 +2232,7 @@ bool ggml_backend_is_meta(ggml_backend_t backend) {
+@@ -2239,7 +2239,7 @@ bool ggml_backend_is_meta(ggml_backend_t backend) {
return backend != nullptr && backend->iface.get_name == ggml_backend_meta_i.get_name;
}
diff --git a/llama.cpp.patches/patches/ggml_src_ggml-cpu_ggml-cpu.c.patch b/llama.cpp.patches/patches/ggml_src_ggml-cpu_ggml-cpu.c.patch
index 878666c4..4a720231 100644
--- a/llama.cpp.patches/patches/ggml_src_ggml-cpu_ggml-cpu.c.patch
+++ b/llama.cpp.patches/patches/ggml_src_ggml-cpu_ggml-cpu.c.patch
@@ -53,7 +53,7 @@ diff --git a/ggml/src/ggml-cpu/ggml-cpu.c b/ggml/src/ggml-cpu/ggml-cpu.c
int chunk_size = 16;
if (nr0 == 1 || nr1 == 1) {
chunk_size = 64;
-@@ -2837,6 +2875,19 @@ struct ggml_cplan ggml_graph_plan(
+@@ -2842,6 +2880,19 @@ struct ggml_cplan ggml_graph_plan(
cur += n_as*ids->ne[0]*ids->ne[1]*sizeof(struct mmid_row_mapping) + sizeof(int64_t);
// atomic_current_chunk
cur += CACHE_LINE_SIZE*n_as + CACHE_LINE_SIZE;
diff --git a/llama.cpp.patches/patches/ggml_src_ggml-cpu_ops.cpp.patch b/llama.cpp.patches/patches/ggml_src_ggml-cpu_ops.cpp.patch
index 95080b18..a8b1a737 100644
--- a/llama.cpp.patches/patches/ggml_src_ggml-cpu_ops.cpp.patch
+++ b/llama.cpp.patches/patches/ggml_src_ggml-cpu_ops.cpp.patch
@@ -20,7 +20,7 @@ diff --git a/ggml/src/ggml-cpu/ops.cpp b/ggml/src/ggml-cpu/ops.cpp
// ggml_compute_forward_dup
static void ggml_compute_forward_dup_same_cont(
-@@ -8293,6 +8305,15 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(
+@@ -8399,6 +8411,15 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(
GGML_ASSERT(( q_to_vec_dot) && "fattn: unsupported K-type");
GGML_ASSERT((v->type == GGML_TYPE_F32 || v_to_float ) && "fattn: unsupported V-type");
@@ -36,7 +36,7 @@ diff --git a/ggml/src/ggml-cpu/ops.cpp b/ggml/src/ggml-cpu/ops.cpp
int ith = params->ith;
for (int ir = ir0; ir < ir1; ++ir) {
-@@ -8312,10 +8333,22 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(
+@@ -8418,10 +8439,22 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(
ggml_fp16_t * VKQ16 = (ggml_fp16_t *) (VKQ32 + 1*DV); // (temporary) FP16 VKQ accumulator
ggml_fp16_t * Q_q = (ggml_fp16_t *) (VKQ32 + 2*DV); // (temporary) buffer for Q converted to quantized/FP16
@@ -62,7 +62,7 @@ diff --git a/ggml/src/ggml-cpu/ops.cpp b/ggml/src/ggml-cpu/ops.cpp
}
const ggml_fp16_t * mp = mask ? (ggml_fp16_t *)((char *) mask->data + iq1*mask->nb[1] + (iq2%mask->ne[2])*mask->nb[2] + (iq3%mask->ne[3])*mask->nb[3]) : NULL;
-@@ -8344,7 +8377,13 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(
+@@ -8450,7 +8483,13 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(
float s; // KQ value
const char * k_data = (const char *) k->data + ( ic*nbk1 + ik2*nbk2 + ik3*nbk3);
@@ -76,7 +76,7 @@ diff --git a/ggml/src/ggml-cpu/ops.cpp b/ggml/src/ggml-cpu/ops.cpp
s = s*scale; // scale KQ value
-@@ -8361,21 +8400,36 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(
+@@ -8467,21 +8506,36 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(
const char * v_data = ((const char *) v->data + (ic*nbv1 + iv2*nbv2 + iv3*nbv3));
@@ -116,7 +116,7 @@ diff --git a/ggml/src/ggml-cpu/ops.cpp b/ggml/src/ggml-cpu/ops.cpp
} else {
if (s > M) {
// s is new maximum, ms < 1.0f, vs == expf(s - s) == 1.0f
-@@ -8383,26 +8437,20 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(
+@@ -8489,26 +8543,20 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(
ms = expf(Mold - M);
// V = V*expf(Mold - M)
@@ -146,7 +146,7 @@ diff --git a/ggml/src/ggml-cpu/ops.cpp b/ggml/src/ggml-cpu/ops.cpp
for (int64_t d = 0; d < DV; ++d) {
VKQ32[d] = GGML_CPU_FP16_TO_FP32(VKQ16[d]);
}
-@@ -8623,8 +8671,24 @@ static void ggml_compute_forward_flash_attn_ext_tiled(
+@@ -8729,8 +8777,24 @@ static void ggml_compute_forward_flash_attn_ext_tiled(
const char * k_data = (const char *)k->data + (ic + tk)*nbk1 + ik2*nbk2 + ik3*nbk3;
if (kv_type == GGML_TYPE_F16) {
const ggml_fp16_t * k_f16 = (const ggml_fp16_t *)k_data;
@@ -173,7 +173,7 @@ diff --git a/ggml/src/ggml-cpu/ops.cpp b/ggml/src/ggml-cpu/ops.cpp
}
} else {
const float * k_f32_src = (const float *)k_data;
-@@ -8634,7 +8698,18 @@ static void ggml_compute_forward_flash_attn_ext_tiled(
+@@ -8740,7 +8804,18 @@ static void ggml_compute_forward_flash_attn_ext_tiled(
}
}
memset(KQ, 0, Q_TILE_SZ * KV_TILE_SZ * sizeof(float));
@@ -192,7 +192,7 @@ diff --git a/ggml/src/ggml-cpu/ops.cpp b/ggml/src/ggml-cpu/ops.cpp
ggml_vec_scale_f32(Q_TILE_SZ * KV_TILE_SZ, KQ, scale);
// Set padded KQ entries to -inf so softmax gives them zero weight
-@@ -8687,7 +8762,15 @@ static void ggml_compute_forward_flash_attn_ext_tiled(
+@@ -8793,7 +8868,15 @@ static void ggml_compute_forward_flash_attn_ext_tiled(
for (int tk = 0; tk < kv_tile; tk++) {
const char * v_data = (const char *)v->data + (ic + tk)*nbv1 + iv2*nbv2 + iv3*nbv3;
if (kv_type == GGML_TYPE_F16) {
@@ -208,7 +208,7 @@ diff --git a/ggml/src/ggml-cpu/ops.cpp b/ggml/src/ggml-cpu/ops.cpp
} else {
memcpy(V32 + tk * DV, v_data, DV * sizeof(float));
}
-@@ -8697,7 +8780,16 @@ static void ggml_compute_forward_flash_attn_ext_tiled(
+@@ -8803,7 +8886,16 @@ static void ggml_compute_forward_flash_attn_ext_tiled(
memset(KQ + tq * KV_TILE_SZ, 0, KV_TILE_SZ * sizeof(float));
}
}
diff --git a/llama.cpp.patches/patches/ggml_src_ggml-cuda_common.cuh.patch b/llama.cpp.patches/patches/ggml_src_ggml-cuda_common.cuh.patch
index a3d3bec0..c80a874f 100644
--- a/llama.cpp.patches/patches/ggml_src_ggml-cuda_common.cuh.patch
+++ b/llama.cpp.patches/patches/ggml_src_ggml-cuda_common.cuh.patch
@@ -1,7 +1,7 @@
diff --git a/ggml/src/ggml-cuda/common.cuh b/ggml/src/ggml-cuda/common.cuh
--- a/llama.cpp/ggml/src/ggml-cuda/common.cuh
+++ b/llama.cpp/ggml/src/ggml-cuda/common.cuh
-@@ -316,9 +316,15 @@ static bool fp16_mma_hardware_available(const int cc) {
+@@ -320,9 +320,15 @@ static bool fp16_mma_hardware_available(const int cc) {
}
static bool bf16_mma_hardware_available(const int cc) {
diff --git a/llama.cpp.patches/patches/ggml_src_ggml-cuda_ggml-cuda.cu.patch b/llama.cpp.patches/patches/ggml_src_ggml-cuda_ggml-cuda.cu.patch
index 989a89e5..ba96fc63 100644
--- a/llama.cpp.patches/patches/ggml_src_ggml-cuda_ggml-cuda.cu.patch
+++ b/llama.cpp.patches/patches/ggml_src_ggml-cuda_ggml-cuda.cu.patch
@@ -1,7 +1,7 @@
diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
--- a/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu
+++ b/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu
-@@ -637,7 +637,7 @@ struct ggml_backend_cuda_buffer_context {
+@@ -638,7 +638,7 @@ struct ggml_backend_cuda_buffer_context {
}
};
@@ -10,7 +10,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
ggml_backend_cuda_buffer_context * ctx = (ggml_backend_cuda_buffer_context *)buffer->context;
delete ctx;
}
-@@ -646,12 +646,12 @@ static bool ggml_backend_buffer_is_cuda(ggml_backend_buffer_t buffer) {
+@@ -647,12 +647,12 @@ static bool ggml_backend_buffer_is_cuda(ggml_backend_buffer_t buffer) {
return buffer->iface.free_buffer == ggml_backend_cuda_buffer_free_buffer;
}
@@ -25,7 +25,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
ggml_backend_cuda_buffer_context * ctx = (ggml_backend_cuda_buffer_context *)buffer->context;
if (tensor->view_src != NULL) {
-@@ -672,7 +672,7 @@ static enum ggml_status ggml_backend_cuda_buffer_init_tensor(ggml_backend_buffer
+@@ -673,7 +673,7 @@ static enum ggml_status ggml_backend_cuda_buffer_init_tensor(ggml_backend_buffer
return GGML_STATUS_SUCCESS;
}
@@ -34,7 +34,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
ggml_backend_cuda_buffer_context * ctx = (ggml_backend_cuda_buffer_context *) buffer->context;
ggml_cuda_set_device(ctx->device);
-@@ -680,7 +680,7 @@ static void ggml_backend_cuda_buffer_memset_tensor(ggml_backend_buffer_t buffer,
+@@ -681,7 +681,7 @@ static void ggml_backend_cuda_buffer_memset_tensor(ggml_backend_buffer_t buffer,
CUDA_CHECK(cudaStreamSynchronize(cudaStreamPerThread));
}
@@ -43,7 +43,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
ggml_backend_cuda_buffer_context * ctx = (ggml_backend_cuda_buffer_context *) buffer->context;
ggml_cuda_set_device(ctx->device);
-@@ -688,7 +688,7 @@ static void ggml_backend_cuda_buffer_set_tensor(ggml_backend_buffer_t buffer, gg
+@@ -689,7 +689,7 @@ static void ggml_backend_cuda_buffer_set_tensor(ggml_backend_buffer_t buffer, gg
CUDA_CHECK(cudaStreamSynchronize(cudaStreamPerThread));
}
@@ -52,7 +52,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
ggml_backend_cuda_buffer_context * ctx = (ggml_backend_cuda_buffer_context *) buffer->context;
ggml_cuda_set_device(ctx->device);
-@@ -696,7 +696,7 @@ static void ggml_backend_cuda_buffer_get_tensor(ggml_backend_buffer_t buffer, co
+@@ -697,7 +697,7 @@ static void ggml_backend_cuda_buffer_get_tensor(ggml_backend_buffer_t buffer, co
CUDA_CHECK(cudaStreamSynchronize(cudaStreamPerThread));
}
@@ -61,7 +61,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
size_t offset, size_t size, size_t n_copies, size_t stride_tensor, size_t stride_data) {
ggml_backend_cuda_buffer_context * ctx = (ggml_backend_cuda_buffer_context *) buffer->context;
-@@ -706,7 +706,7 @@ static void ggml_backend_cuda_buffer_set_tensor_2d(ggml_backend_buffer_t buffer,
+@@ -707,7 +707,7 @@ static void ggml_backend_cuda_buffer_set_tensor_2d(ggml_backend_buffer_t buffer,
CUDA_CHECK(cudaStreamSynchronize(cudaStreamPerThread));
}
@@ -70,7 +70,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
size_t offset, size_t size, size_t n_copies, size_t stride_tensor, size_t stride_data) {
ggml_backend_cuda_buffer_context * ctx = (ggml_backend_cuda_buffer_context *)buffer->context;
-@@ -716,7 +716,7 @@ static void ggml_backend_cuda_buffer_get_tensor_2d(ggml_backend_buffer_t buffer,
+@@ -717,7 +717,7 @@ static void ggml_backend_cuda_buffer_get_tensor_2d(ggml_backend_buffer_t buffer,
CUDA_CHECK(cudaStreamSynchronize(cudaStreamPerThread));
}
@@ -79,7 +79,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
if (ggml_backend_buffer_is_cuda(src->buffer)) {
ggml_backend_cuda_buffer_context * src_ctx = (ggml_backend_cuda_buffer_context *)src->buffer->context;
ggml_backend_cuda_buffer_context * dst_ctx = (ggml_backend_cuda_buffer_context *)dst->buffer->context;
-@@ -737,7 +737,7 @@ static bool ggml_backend_cuda_buffer_cpy_tensor(ggml_backend_buffer_t buffer, co
+@@ -738,7 +738,7 @@ static bool ggml_backend_cuda_buffer_cpy_tensor(ggml_backend_buffer_t buffer, co
GGML_UNUSED(buffer);
}
@@ -88,7 +88,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
ggml_backend_cuda_buffer_context * ctx = (ggml_backend_cuda_buffer_context *)buffer->context;
ggml_cuda_set_device(ctx->device);
-@@ -745,6 +745,14 @@ static void ggml_backend_cuda_buffer_clear(ggml_backend_buffer_t buffer, uint8_t
+@@ -746,6 +746,14 @@ static void ggml_backend_cuda_buffer_clear(ggml_backend_buffer_t buffer, uint8_t
CUDA_CHECK(cudaStreamSynchronize(cudaStreamPerThread));
}
@@ -103,7 +103,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
static const ggml_backend_buffer_i ggml_backend_cuda_buffer_interface = {
/* .free_buffer = */ ggml_backend_cuda_buffer_free_buffer,
/* .get_base = */ ggml_backend_cuda_buffer_get_base,
-@@ -757,6 +765,7 @@ static const ggml_backend_buffer_i ggml_backend_cuda_buffer_interface = {
+@@ -758,6 +766,7 @@ static const ggml_backend_buffer_i ggml_backend_cuda_buffer_interface = {
/* .cpy_tensor = */ ggml_backend_cuda_buffer_cpy_tensor,
/* .clear = */ ggml_backend_cuda_buffer_clear,
/* .reset = */ NULL,
@@ -111,7 +111,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
};
// cuda buffer type
-@@ -765,7 +774,7 @@ struct ggml_backend_cuda_buffer_type_context {
+@@ -766,7 +775,7 @@ struct ggml_backend_cuda_buffer_type_context {
std::string name;
};
@@ -120,7 +120,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
ggml_backend_cuda_buffer_type_context * ctx = (ggml_backend_cuda_buffer_type_context *)buft->context;
return ctx->name.c_str();
-@@ -775,7 +784,7 @@ static bool ggml_backend_buft_is_cuda(ggml_backend_buffer_type_t buft) {
+@@ -776,7 +785,7 @@ static bool ggml_backend_buft_is_cuda(ggml_backend_buffer_type_t buft) {
return buft->iface.get_name == ggml_backend_cuda_buffer_type_get_name;
}
@@ -129,7 +129,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
ggml_backend_cuda_buffer_type_context * buft_ctx = (ggml_backend_cuda_buffer_type_context *)buft->context;
ggml_cuda_set_device(buft_ctx->device);
-@@ -794,13 +803,13 @@ static ggml_backend_buffer_t ggml_backend_cuda_buffer_type_alloc_buffer(ggml_bac
+@@ -795,13 +804,13 @@ static ggml_backend_buffer_t ggml_backend_cuda_buffer_type_alloc_buffer(ggml_bac
return ggml_backend_buffer_init(buft, ggml_backend_cuda_buffer_interface, ctx, size);
}
@@ -142,10 +142,10 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
-static size_t ggml_backend_cuda_buffer_type_get_alloc_size(ggml_backend_buffer_type_t buft, const ggml_tensor * tensor) {
+static size_t GGML_CALL ggml_backend_cuda_buffer_type_get_alloc_size(ggml_backend_buffer_type_t buft, const ggml_tensor * tensor) {
- size_t size = ggml_nbytes(tensor);
- int64_t ne0 = tensor->ne[0];
+ ggml_backend_cuda_buffer_type_context * buft_ctx = (ggml_backend_cuda_buffer_type_context *) buft->context;
-@@ -914,19 +923,19 @@ struct ggml_backend_cuda_split_buffer_context {
+ size_t size = tensor->op == GGML_OP_FLASH_ATTN_EXT
+@@ -917,19 +926,19 @@ struct ggml_backend_cuda_split_buffer_context {
};
@@ -168,7 +168,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
GGML_ASSERT(tensor->view_src == nullptr); // views of split tensors are not supported
GGML_ASSERT(ggml_is_contiguous(tensor) && "split buffers only supported for contiguous tensors");
-@@ -976,7 +985,7 @@ static enum ggml_status ggml_backend_cuda_split_buffer_init_tensor(ggml_backend_
+@@ -979,7 +988,7 @@ static enum ggml_status ggml_backend_cuda_split_buffer_init_tensor(ggml_backend_
return GGML_STATUS_SUCCESS;
}
@@ -177,7 +177,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
// split tensors must always be set in their entirety at once
GGML_ASSERT(offset == 0);
GGML_ASSERT(size == ggml_nbytes(tensor));
-@@ -1015,7 +1024,7 @@ static void ggml_backend_cuda_split_buffer_set_tensor(ggml_backend_buffer_t buff
+@@ -1018,7 +1027,7 @@ static void ggml_backend_cuda_split_buffer_set_tensor(ggml_backend_buffer_t buff
}
}
@@ -186,7 +186,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
// split tensors must always be set in their entirety at once
GGML_ASSERT(offset == 0);
GGML_ASSERT(size == ggml_nbytes(tensor));
-@@ -1054,7 +1063,7 @@ static void ggml_backend_cuda_split_buffer_get_tensor(ggml_backend_buffer_t buff
+@@ -1057,7 +1066,7 @@ static void ggml_backend_cuda_split_buffer_get_tensor(ggml_backend_buffer_t buff
}
}
@@ -195,7 +195,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
GGML_UNUSED(buffer);
GGML_UNUSED(value);
}
-@@ -1071,11 +1080,12 @@ static const ggml_backend_buffer_i ggml_backend_cuda_split_buffer_interface = {
+@@ -1074,11 +1083,12 @@ static const ggml_backend_buffer_i ggml_backend_cuda_split_buffer_interface = {
/* .cpy_tensor = */ NULL,
/* .clear = */ ggml_backend_cuda_split_buffer_clear,
/* .reset = */ NULL,
@@ -209,7 +209,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
ggml_backend_cuda_split_buffer_type_context * ctx = (ggml_backend_cuda_split_buffer_type_context *)buft->context;
return ctx->name.c_str();
-@@ -1085,7 +1095,7 @@ static bool ggml_backend_buft_is_cuda_split(ggml_backend_buffer_type_t buft) {
+@@ -1088,7 +1098,7 @@ static bool ggml_backend_buft_is_cuda_split(ggml_backend_buffer_type_t buft) {
return buft->iface.get_name == ggml_backend_cuda_split_buffer_type_get_name;
}
@@ -218,7 +218,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
// since we don't know the exact split after rounding, we cannot allocate the device buffers at this point
// instead, we allocate them for each tensor separately in init_tensor
// however, the size still represents the maximum cumulative size of all the device buffers after the tensors are allocated,
-@@ -1095,13 +1105,13 @@ static ggml_backend_buffer_t ggml_backend_cuda_split_buffer_type_alloc_buffer(gg
+@@ -1098,13 +1108,13 @@ static ggml_backend_buffer_t ggml_backend_cuda_split_buffer_type_alloc_buffer(gg
return ggml_backend_buffer_init(buft, ggml_backend_cuda_split_buffer_interface, ctx, size);
}
@@ -234,7 +234,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
ggml_backend_cuda_split_buffer_type_context * ctx = (ggml_backend_cuda_split_buffer_type_context *)buft->context;
GGML_ASSERT(ggml_is_contiguous(tensor) && "split buffers only supported for contiguous tensors");
-@@ -1129,7 +1139,7 @@ static size_t ggml_backend_cuda_split_buffer_type_get_alloc_size(ggml_backend_bu
+@@ -1132,7 +1142,7 @@ static size_t ggml_backend_cuda_split_buffer_type_get_alloc_size(ggml_backend_bu
return total_size;
}
@@ -243,7 +243,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
return false;
GGML_UNUSED(buft);
-@@ -1433,7 +1443,7 @@ static bool ggml_backend_cuda_comm_allreduce_tensor(void * comm_ctx_v, struct gg
+@@ -1436,7 +1446,7 @@ static bool ggml_backend_cuda_comm_allreduce_tensor(void * comm_ctx_v, struct gg
return comm_ctx->try_allreduce(comm_ctx, tensors);
}
@@ -252,7 +252,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
static std::mutex mutex;
std::lock_guard<std::mutex> lock(mutex);
-@@ -1477,7 +1487,7 @@ ggml_backend_buffer_type_t ggml_backend_cuda_split_buffer_type(int main_device,
+@@ -1480,7 +1490,7 @@ ggml_backend_buffer_type_t ggml_backend_cuda_split_buffer_type(int main_device,
// host buffer type
@@ -261,7 +261,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
return GGML_CUDA_NAME "_Host";
GGML_UNUSED(buft);
-@@ -1487,7 +1497,7 @@ static bool ggml_backend_buft_is_cuda_host(ggml_backend_buffer_type_t buft) {
+@@ -1490,7 +1500,7 @@ static bool ggml_backend_buft_is_cuda_host(ggml_backend_buffer_type_t buft) {
return buft->iface.get_name == ggml_backend_cuda_host_buffer_type_name;
}
@@ -270,7 +270,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
CUDA_CHECK(cudaFreeHost(buffer->context));
}
-@@ -1509,17 +1519,25 @@ static void * ggml_cuda_host_malloc(size_t size) {
+@@ -1512,17 +1522,25 @@ static void * ggml_cuda_host_malloc(size_t size) {
return ptr;
}
@@ -298,7 +298,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
return buffer;
}
-@@ -1647,8 +1665,13 @@ static void ggml_cuda_op_mul_mat_cublas(
+@@ -1650,8 +1668,13 @@ static void ggml_cuda_op_mul_mat_cublas(
const int cc = ggml_cuda_info().devices[id].cc;
@@ -312,7 +312,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
const bool use_fp16 =
src0->type != GGML_TYPE_NVFP4 &&
-@@ -3127,20 +3150,20 @@ static bool ggml_cuda_compute_forward(ggml_backend_cuda_context & ctx, struct gg
+@@ -3135,20 +3158,20 @@ static bool ggml_cuda_compute_forward(ggml_backend_cuda_context & ctx, struct gg
// backend
@@ -336,7 +336,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
ggml_backend_cuda_context * cuda_ctx = (ggml_backend_cuda_context *) backend->context;
ggml_backend_buffer_t buf = tensor->view_src ? tensor->view_src->buffer : tensor->buffer;
-@@ -3149,7 +3172,7 @@ static void ggml_backend_cuda_set_tensor_async(ggml_backend_t backend, ggml_tens
+@@ -3157,7 +3180,7 @@ static void ggml_backend_cuda_set_tensor_async(ggml_backend_t backend, ggml_tens
CUDA_CHECK(cudaMemcpyAsync((char *) tensor->data + offset, data, size, cudaMemcpyHostToDevice, cuda_ctx->stream()));
}
@@ -345,7 +345,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
ggml_backend_cuda_context * cuda_ctx = (ggml_backend_cuda_context *) backend->context;
ggml_backend_buffer_t buf = tensor->view_src ? tensor->view_src->buffer : tensor->buffer;
-@@ -3158,7 +3181,7 @@ static void ggml_backend_cuda_get_tensor_async(ggml_backend_t backend, const ggm
+@@ -3166,7 +3189,7 @@ static void ggml_backend_cuda_get_tensor_async(ggml_backend_t backend, const ggm
CUDA_CHECK(cudaMemcpyAsync(data, (const char *) tensor->data + offset, size, cudaMemcpyDeviceToHost, cuda_ctx->stream()));
}
@@ -354,7 +354,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
size_t offset, size_t size, size_t n_copies, size_t stride_tensor, size_t stride_data) {
ggml_backend_cuda_context * cuda_ctx = (ggml_backend_cuda_context *) backend->context;
ggml_backend_buffer_t buf = tensor->view_src ? tensor->view_src->buffer : tensor->buffer;
-@@ -3169,7 +3192,7 @@ static void ggml_backend_cuda_set_tensor_2d_async(ggml_backend_t backend, struct
+@@ -3177,7 +3200,7 @@ static void ggml_backend_cuda_set_tensor_2d_async(ggml_backend_t backend, struct
(char *) tensor->data + offset, stride_tensor, data, stride_data, size, n_copies, cudaMemcpyHostToDevice, cuda_ctx->stream()));
}
@@ -363,7 +363,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
size_t offset, size_t size, size_t n_copies, size_t stride_tensor, size_t stride_data) {
ggml_backend_cuda_context * cuda_ctx = (ggml_backend_cuda_context *) backend->context;
ggml_backend_buffer_t buf = tensor->view_src ? tensor->view_src->buffer : tensor->buffer;
-@@ -3180,7 +3203,7 @@ static void ggml_backend_cuda_get_tensor_2d_async(ggml_backend_t backend, const
+@@ -3188,7 +3211,7 @@ static void ggml_backend_cuda_get_tensor_2d_async(ggml_backend_t backend, const
data, stride_data, (const char *) tensor->data + offset, stride_tensor, size, n_copies, cudaMemcpyDeviceToHost, cuda_ctx->stream()));
}
@@ -372,7 +372,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
ggml_backend_buffer_t buf_src = src->view_src ? src->view_src->buffer : src->buffer;
ggml_backend_buffer_t buf_dst = dst->view_src ? dst->view_src->buffer : dst->buffer;
-@@ -3235,7 +3258,7 @@ static bool ggml_backend_cuda_cpy_tensor_async(ggml_backend_t backend_src, ggml_
+@@ -3243,7 +3266,7 @@ static bool ggml_backend_cuda_cpy_tensor_async(ggml_backend_t backend_src, ggml_
return true;
}
@@ -381,7 +381,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
ggml_backend_cuda_context * cuda_ctx = (ggml_backend_cuda_context *)backend->context;
CUDA_CHECK(cudaStreamSynchronize(cuda_ctx->stream()));
-@@ -4457,7 +4480,7 @@ static bool ggml_cuda_graph_set_enabled(ggml_backend_cuda_context * cuda_ctx, co
+@@ -4465,7 +4488,7 @@ static bool ggml_cuda_graph_set_enabled(ggml_backend_cuda_context * cuda_ctx, co
}
#endif // USE_CUDA_GRAPH
@@ -390,7 +390,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
ggml_backend_cuda_context * cuda_ctx = (ggml_backend_cuda_context *) backend->context;
ggml_cuda_set_device(cuda_ctx->device);
-@@ -4516,13 +4539,13 @@ static enum ggml_status ggml_backend_cuda_graph_compute(ggml_backend_t backend,
+@@ -4524,13 +4547,13 @@ static enum ggml_status ggml_backend_cuda_graph_compute(ggml_backend_t backend,
return GGML_STATUS_SUCCESS;
}
@@ -406,7 +406,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
ggml_backend_cuda_context * cuda_ctx = (ggml_backend_cuda_context *)backend->context;
if (ggml_backend_is_cuda(backend)) {
-@@ -4541,7 +4564,7 @@ static void ggml_backend_cuda_event_wait(ggml_backend_t backend, ggml_backend_ev
+@@ -4549,7 +4572,7 @@ static void ggml_backend_cuda_event_wait(ggml_backend_t backend, ggml_backend_ev
}
}
@@ -415,7 +415,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
ggml_backend_cuda_context * cuda_ctx = (ggml_backend_cuda_context *) backend->context;
#ifdef USE_CUDA_GRAPH
-@@ -4829,7 +4852,7 @@ void ggml_backend_cuda_get_device_memory(int device, size_t * free, size_t * tot
+@@ -4837,7 +4860,7 @@ void ggml_backend_cuda_get_device_memory(int device, size_t * free, size_t * tot
CUDA_CHECK(cudaMemGetInfo(free, total));
}
@@ -424,7 +424,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
if (getenv("GGML_CUDA_REGISTER_HOST") == nullptr) {
return false;
}
-@@ -4852,7 +4875,7 @@ bool ggml_backend_cuda_register_host_buffer(void * buffer, size_t size) {
+@@ -4860,7 +4883,7 @@ bool ggml_backend_cuda_register_host_buffer(void * buffer, size_t size) {
#endif // CUDART_VERSION >= 11010 || defined(GGML_USE_MUSA)
}
@@ -433,7 +433,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
if (getenv("GGML_CUDA_REGISTER_HOST") == nullptr) {
return;
}
-@@ -4875,12 +4898,12 @@ struct ggml_backend_cuda_device_context {
+@@ -4883,12 +4906,12 @@ struct ggml_backend_cuda_device_context {
int op_offload_min_batch_size;
};
@@ -448,7 +448,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
ggml_backend_cuda_device_context * ctx = (ggml_backend_cuda_device_context *)dev->context;
return ctx->description.c_str();
}
-@@ -4961,7 +4984,7 @@ static bool ggml_backend_cuda_get_available_uma_memory(long * available_memory_k
+@@ -4969,7 +4992,7 @@ static bool ggml_backend_cuda_get_available_uma_memory(long * available_memory_k
}
#endif // defined(__linux__)
@@ -457,14 +457,17 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
ggml_backend_cuda_device_context * ctx = (ggml_backend_cuda_device_context *)dev->context;
ggml_cuda_set_device(ctx->device);
CUDA_CHECK(cudaMemGetInfo(free, total));
-@@ -4991,12 +5014,12 @@ static void ggml_backend_cuda_device_get_memory(ggml_backend_dev_t dev, size_t *
+@@ -4999,7 +5022,7 @@ static void ggml_backend_cuda_device_get_memory(ggml_backend_dev_t dev, size_t *
}
-static enum ggml_backend_dev_type ggml_backend_cuda_device_get_type(ggml_backend_dev_t dev) {
+static enum ggml_backend_dev_type GGML_CALL ggml_backend_cuda_device_get_type(ggml_backend_dev_t dev) {
- GGML_UNUSED(dev);
- return GGML_BACKEND_DEVICE_TYPE_GPU;
+ ggml_backend_cuda_device_context * ctx = (ggml_backend_cuda_device_context *) dev->context;
+
+ cudaDeviceProp prop;
+@@ -5010,7 +5033,7 @@ static enum ggml_backend_dev_type ggml_backend_cuda_device_get_type(ggml_backend
+ : GGML_BACKEND_DEVICE_TYPE_GPU;
}
-static void ggml_backend_cuda_device_get_props(ggml_backend_dev_t dev, ggml_backend_dev_props * props) {
@@ -472,7 +475,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
ggml_backend_cuda_device_context * ctx = (ggml_backend_cuda_device_context *)dev->context;
props->name = ggml_backend_cuda_device_get_name(dev);
-@@ -5020,24 +5043,24 @@ static void ggml_backend_cuda_device_get_props(ggml_backend_dev_t dev, ggml_back
+@@ -5034,24 +5057,24 @@ static void ggml_backend_cuda_device_get_props(ggml_backend_dev_t dev, ggml_back
};
}
@@ -501,7 +504,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
ggml_backend_cuda_device_context * dev_ctx = (ggml_backend_cuda_device_context *) dev->context;
// split buffers can only be used with GGML_OP_MUL_MAT
-@@ -5424,7 +5447,7 @@ static bool ggml_backend_cuda_device_supports_op(ggml_backend_dev_t dev, const g
+@@ -5455,7 +5478,7 @@ static bool ggml_backend_cuda_device_supports_op(ggml_backend_dev_t dev, const g
}
}
@@ -510,7 +513,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
ggml_backend_cuda_device_context * dev_ctx = (ggml_backend_cuda_device_context *) dev->context;
const bool integrated = ggml_cuda_info().devices[dev_ctx->device].integrated;
return (((ggml_backend_buft_is_cuda(buft) || ggml_backend_buft_is_cuda_split(buft)) && buft->device == dev) || (integrated && ggml_backend_buft_is_cuda_host(buft)));
-@@ -5445,13 +5468,13 @@ static int64_t get_op_batch_size(const ggml_tensor * op) {
+@@ -5476,13 +5499,13 @@ static int64_t get_op_batch_size(const ggml_tensor * op) {
}
}
@@ -526,7 +529,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
#ifdef GGML_CUDA_NO_PEER_COPY
return nullptr;
#else
-@@ -5469,14 +5492,14 @@ static ggml_backend_event_t ggml_backend_cuda_device_event_new(ggml_backend_dev_
+@@ -5500,14 +5523,14 @@ static ggml_backend_event_t ggml_backend_cuda_device_event_new(ggml_backend_dev_
#endif
}
@@ -543,7 +546,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
GGML_UNUSED(dev);
CUDA_CHECK(cudaEventSynchronize((cudaEvent_t)event->context));
}
-@@ -5505,23 +5528,23 @@ struct ggml_backend_cuda_reg_context {
+@@ -5536,23 +5559,23 @@ struct ggml_backend_cuda_reg_context {
std::vector<ggml_backend_dev_t> devices;
};
@@ -571,7 +574,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
static std::vector<ggml_backend_feature> features = []() {
std::vector<ggml_backend_feature> features;
#define _STRINGIFY(...) #__VA_ARGS__
-@@ -5582,7 +5605,7 @@ static ggml_backend_feature * ggml_backend_cuda_get_features(ggml_backend_reg_t
+@@ -5613,7 +5636,7 @@ static ggml_backend_feature * ggml_backend_cuda_get_features(ggml_backend_reg_t
GGML_UNUSED(reg);
}
diff --git a/llama.cpp.patches/patches/ggml_src_ggml-vulkan_ggml-vulkan.cpp.patch b/llama.cpp.patches/patches/ggml_src_ggml-vulkan_ggml-vulkan.cpp.patch
index 0ae19742..a15c2cd9 100644
--- a/llama.cpp.patches/patches/ggml_src_ggml-vulkan_ggml-vulkan.cpp.patch
+++ b/llama.cpp.patches/patches/ggml_src_ggml-vulkan_ggml-vulkan.cpp.patch
@@ -1,7 +1,7 @@
diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vulkan.cpp
--- a/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp
+++ b/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp
-@@ -249,11 +249,11 @@ struct vk_queue {
+@@ -280,11 +280,11 @@ struct vk_queue {
}
};
@@ -18,7 +18,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
static ggml_backend_buffer_type_i ggml_backend_vk_buffer_type_interface = {
/* .get_name = */ ggml_backend_vk_buffer_type_name,
/* .alloc_buffer = */ ggml_backend_vk_buffer_type_alloc_buffer,
-@@ -2116,7 +2116,7 @@ static void ggml_vk_check_results_1(ggml_backend_vk_context * ctx, ggml_cgraph *
+@@ -2224,7 +2224,7 @@ static void ggml_vk_check_results_1(ggml_backend_vk_context * ctx, ggml_cgraph *
typedef void (*ggml_vk_func_t)(ggml_backend_vk_context * ctx, vk_context& subctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst);
@@ -27,34 +27,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
static VkDeviceSize ggml_vk_get_max_buffer_range(const ggml_backend_vk_context * ctx, const vk_buffer &buf, const VkDeviceSize offset) {
const VkDeviceSize range = std::min(VkDeviceSize{buf->size - offset},
-@@ -3634,20 +3634,15 @@ static void ggml_vk_load_shaders(vk_device& device) {
- if (!pipeline->needed || pipeline->compiled) {
- continue;
- }
-- // TODO: We're no longer benefitting from the async compiles (shaders are
-- // compiled individually, as needed) and this complexity can be removed.
-+ // Compile synchronously to avoid threading issues in cross-module DLL loading.
-+ // ggml_vk_create_pipeline_func asserts compile_count > 0 and decrements it
-+ // on completion, so we still need to increment it here.
- {
-- // wait until fewer than N compiles are in progress
-- uint32_t N = std::max(1u, std::thread::hardware_concurrency());
-- std::unique_lock<std::mutex> guard(compile_count_mutex);
-- while (compile_count >= N) {
-- compile_count_cond.wait(guard);
-- }
-+ std::lock_guard<std::mutex> guard(compile_count_mutex);
- compile_count++;
- }
--
-- compiles.push_back(std::async(ggml_vk_create_pipeline_func, std::ref(device), std::ref(pipeline), spv_size, spv_data, entrypoint,
-- parameter_count, wg_denoms, specialization_constants, disable_robustness, require_full_subgroups, required_subgroup_size));
-+ ggml_vk_create_pipeline_func(device, pipeline, spv_size, spv_data, entrypoint,
-+ parameter_count, wg_denoms, specialization_constants, disable_robustness, require_full_subgroups, required_subgroup_size);
- }
- };
-
-@@ -13871,20 +13866,28 @@ static bool ggml_backend_buffer_is_vk(ggml_backend_buffer_t buffer) {
+@@ -14765,20 +14765,28 @@ static bool ggml_backend_buffer_is_vk(ggml_backend_buffer_t buffer) {
return buffer->buft->iface.get_name == ggml_backend_vk_buffer_type_name;
}
@@ -86,7 +59,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
VK_LOG_DEBUG("ggml_backend_vk_buffer_init_tensor(" << buffer << " (" << buffer->context << "), " << tensor << ")");
if (tensor->view_src != nullptr) {
GGML_ASSERT(tensor->view_src->buffer->buft == buffer->buft);
-@@ -13892,7 +13895,7 @@ static enum ggml_status ggml_backend_vk_buffer_init_tensor(ggml_backend_buffer_t
+@@ -14786,7 +14794,7 @@ static enum ggml_status ggml_backend_vk_buffer_init_tensor(ggml_backend_buffer_t
return GGML_STATUS_SUCCESS;
}
@@ -95,7 +68,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
VK_LOG_DEBUG("ggml_backend_vk_buffer_memset_tensor(" << buffer << ", " << tensor << ", " << value << ", " << offset << ", " << size << ")");
ggml_backend_vk_buffer_context * buf_ctx = (ggml_backend_vk_buffer_context *)buffer->context;
vk_buffer buf = buf_ctx->dev_buffer;
-@@ -13905,7 +13908,7 @@ static void ggml_backend_vk_buffer_memset_tensor(ggml_backend_buffer_t buffer, g
+@@ -14799,7 +14807,7 @@ static void ggml_backend_vk_buffer_memset_tensor(ggml_backend_buffer_t buffer, g
ggml_vk_buffer_memset(buf, vk_tensor_offset(tensor) + tensor->view_offs + offset, val32, size);
}
@@ -104,7 +77,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
VK_LOG_DEBUG("ggml_backend_vk_buffer_set_tensor(" << buffer << ", " << tensor << ", " << data << ", " << offset << ", " << size << ")");
ggml_backend_vk_buffer_context * buf_ctx = (ggml_backend_vk_buffer_context *)buffer->context;
vk_buffer buf = buf_ctx->dev_buffer;
-@@ -13917,7 +13920,7 @@ static void ggml_backend_vk_buffer_set_tensor(ggml_backend_buffer_t buffer, ggml
+@@ -14811,7 +14819,7 @@ static void ggml_backend_vk_buffer_set_tensor(ggml_backend_buffer_t buffer, ggml
ggml_vk_buffer_write(buf, vk_tensor_offset(tensor) + tensor->view_offs + offset, data, size);
}
@@ -113,7 +86,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
size_t size, size_t n_copies, size_t stride_tensor, size_t stride_data) {
VK_LOG_DEBUG("ggml_backend_vk_buffer_set_tensor_2d(" << buffer << ", " << tensor << ", " << data << ", " << offset << ", " << size << ", " <<
n_copies << ", " << stride_tensor << ", " << stride_data << ")");
-@@ -13931,7 +13934,7 @@ static void ggml_backend_vk_buffer_set_tensor_2d(ggml_backend_buffer_t buffer, g
+@@ -14825,7 +14833,7 @@ static void ggml_backend_vk_buffer_set_tensor_2d(ggml_backend_buffer_t buffer, g
ggml_vk_buffer_write_2d(buf, vk_tensor_offset(tensor) + tensor->view_offs + offset, data, stride_data, stride_tensor, size, n_copies);
}
@@ -122,7 +95,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
VK_LOG_DEBUG("ggml_backend_vk_buffer_get_tensor(" << buffer << ", " << tensor << ", " << data << ", " << offset << ", " << size << ")");
ggml_backend_vk_buffer_context * buf_ctx = (ggml_backend_vk_buffer_context *)buffer->context;
-@@ -13944,7 +13947,7 @@ static void ggml_backend_vk_buffer_get_tensor(ggml_backend_buffer_t buffer, cons
+@@ -14838,7 +14846,7 @@ static void ggml_backend_vk_buffer_get_tensor(ggml_backend_buffer_t buffer, cons
ggml_vk_buffer_read(buf, vk_tensor_offset(tensor) + tensor->view_offs + offset, data, size);
}
@@ -131,7 +104,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
size_t size, size_t n_copies, size_t stride_tensor, size_t stride_data) {
VK_LOG_DEBUG("ggml_backend_vk_buffer_get_tensor_2d(" << buffer << ", " << tensor << ", " << data << ", " << offset << ", " << size << ", " <<
n_copies << ", " << stride_tensor << ", " << stride_data << ")");
-@@ -13959,7 +13962,7 @@ static void ggml_backend_vk_buffer_get_tensor_2d(ggml_backend_buffer_t buffer, c
+@@ -14853,7 +14861,7 @@ static void ggml_backend_vk_buffer_get_tensor_2d(ggml_backend_buffer_t buffer, c
ggml_vk_buffer_read_2d(buf, vk_tensor_offset(tensor) + tensor->view_offs + offset, data, stride_tensor, stride_data, size, n_copies);
}
@@ -140,7 +113,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
if (ggml_nbytes(src) == 0) {
return true;
}
-@@ -13980,7 +13983,7 @@ static bool ggml_backend_vk_buffer_cpy_tensor(ggml_backend_buffer_t buffer, cons
+@@ -14874,7 +14882,7 @@ static bool ggml_backend_vk_buffer_cpy_tensor(ggml_backend_buffer_t buffer, cons
UNUSED(buffer);
}
@@ -149,7 +122,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
ggml_backend_vk_buffer_context * ctx = (ggml_backend_vk_buffer_context *)buffer->context;
ggml_vk_buffer_memset(ctx->dev_buffer, 0, value, buffer->size);
-@@ -13998,16 +14001,17 @@ static ggml_backend_buffer_i ggml_backend_vk_buffer_interface = {
+@@ -14892,16 +14900,17 @@ static ggml_backend_buffer_i ggml_backend_vk_buffer_interface = {
/* .cpy_tensor = */ ggml_backend_vk_buffer_cpy_tensor,
/* .clear = */ ggml_backend_vk_buffer_clear,
/* .reset = */ NULL,
@@ -169,7 +142,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
VK_LOG_MEMORY("ggml_backend_vk_buffer_type_alloc_buffer(" << size << ")");
ggml_backend_vk_buffer_type_context * ctx = (ggml_backend_vk_buffer_type_context *) buft->context;
-@@ -14023,17 +14027,17 @@ static ggml_backend_buffer_t ggml_backend_vk_buffer_type_alloc_buffer(ggml_backe
+@@ -14917,17 +14926,17 @@ static ggml_backend_buffer_t ggml_backend_vk_buffer_type_alloc_buffer(ggml_backe
return ggml_backend_buffer_init(buft, ggml_backend_vk_buffer_interface, bufctx, size);
}
@@ -190,7 +163,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
return ggml_nbytes(tensor);
UNUSED(buft);
-@@ -14051,24 +14055,24 @@ ggml_backend_buffer_type_t ggml_backend_vk_buffer_type(size_t dev_num) {
+@@ -14945,18 +14954,18 @@ ggml_backend_buffer_type_t ggml_backend_vk_buffer_type(size_t dev_num) {
// host buffer type
@@ -201,13 +174,6 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
UNUSED(buft);
}
--static const char * ggml_backend_vk_host_buffer_name(ggml_backend_buffer_t buffer) {
-+static const char * GGML_CALL ggml_backend_vk_host_buffer_name(ggml_backend_buffer_t buffer) {
- return GGML_VK_NAME "_Host";
-
- UNUSED(buffer);
- }
-
-static void ggml_backend_vk_host_buffer_free_buffer(ggml_backend_buffer_t buffer) {
+static void GGML_CALL ggml_backend_vk_host_buffer_free_buffer(ggml_backend_buffer_t buffer) {
VK_LOG_MEMORY("ggml_backend_vk_host_buffer_free_buffer()");
@@ -219,7 +185,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
VK_LOG_MEMORY("ggml_backend_vk_host_buffer_type_alloc_buffer(" << size << ")");
size += 32; // Behave like the CPU buffer type
-@@ -14084,19 +14088,20 @@ static ggml_backend_buffer_t ggml_backend_vk_host_buffer_type_alloc_buffer(ggml_
+@@ -14972,19 +14981,20 @@ static ggml_backend_buffer_t ggml_backend_vk_host_buffer_type_alloc_buffer(ggml_
ggml_backend_buffer_t buffer = ggml_backend_cpu_buffer_from_ptr(ptr, size);
buffer->buft = buft;
buffer->iface.free_buffer = ggml_backend_vk_host_buffer_free_buffer;
@@ -242,7 +208,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
return vk_instance.devices[0]->suballocation_block_size;
UNUSED(buft);
-@@ -14128,13 +14133,13 @@ ggml_backend_buffer_type_t ggml_backend_vk_host_buffer_type() {
+@@ -15016,13 +15026,13 @@ ggml_backend_buffer_type_t ggml_backend_vk_host_buffer_type() {
// backend
@@ -258,7 +224,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
ggml_backend_vk_context * ctx = (ggml_backend_vk_context *)backend->context;
VK_LOG_DEBUG("ggml_backend_vk_free(" << ctx->name << ")");
-@@ -14150,7 +14155,7 @@ static ggml_backend_buffer_type_t ggml_backend_vk_get_default_buffer_type(ggml_b
+@@ -15038,7 +15048,7 @@ static ggml_backend_buffer_type_t ggml_backend_vk_get_default_buffer_type(ggml_b
return &ctx->device->buffer_type;
}
@@ -267,7 +233,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
size_t size, size_t n_copies, size_t stride_tensor, size_t stride_data) {
VK_LOG_DEBUG("ggml_backend_vk_set_tensor_2d_async(" << size << ", " << n_copies << ")");
ggml_backend_vk_context * ctx = (ggml_backend_vk_context *)backend->context;
-@@ -14214,12 +14219,12 @@ static void ggml_backend_vk_set_tensor_2d_async(ggml_backend_t backend, ggml_ten
+@@ -15102,12 +15112,12 @@ static void ggml_backend_vk_set_tensor_2d_async(ggml_backend_t backend, ggml_ten
}
}
@@ -282,7 +248,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
size_t size, size_t n_copies, size_t stride_tensor, size_t stride_data) {
VK_LOG_DEBUG("ggml_backend_vk_get_tensor_2d_async(" << size << ", " << n_copies << ")");
ggml_backend_vk_context * ctx = (ggml_backend_vk_context *)backend->context;
-@@ -14270,12 +14275,12 @@ static void ggml_backend_vk_get_tensor_2d_async(ggml_backend_t backend, const gg
+@@ -15158,12 +15168,12 @@ static void ggml_backend_vk_get_tensor_2d_async(ggml_backend_t backend, const gg
}
}
@@ -297,7 +263,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
VK_LOG_DEBUG("ggml_backend_vk_cpy_tensor_async(" << src << " -> " << dst << ", size=" << ggml_nbytes(src) << ")");
ggml_backend_vk_context * ctx = (ggml_backend_vk_context *)backend_dst->context;
-@@ -14400,7 +14405,7 @@ static void ggml_vk_synchronize(ggml_backend_vk_context * ctx) {
+@@ -15288,7 +15298,7 @@ static void ggml_vk_synchronize(ggml_backend_vk_context * ctx) {
}
}
@@ -306,7 +272,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
VK_LOG_DEBUG("ggml_backend_vk_synchronize()");
ggml_backend_vk_context * ctx = (ggml_backend_vk_context *)backend->context;
-@@ -14936,7 +14941,7 @@ static int32_t find_first_set(uint32_t x) {
+@@ -15824,7 +15834,7 @@ static int32_t find_first_set(uint32_t x) {
return ret;
}
@@ -315,7 +281,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
VK_LOG_DEBUG("ggml_backend_vk_graph_compute(" << cgraph->n_nodes << " nodes)");
ggml_backend_vk_context * ctx = (ggml_backend_vk_context *)backend->context;
-@@ -15339,7 +15344,7 @@ static ggml_status ggml_backend_vk_graph_compute(ggml_backend_t backend, ggml_cg
+@@ -16228,7 +16238,7 @@ static ggml_status ggml_backend_vk_graph_compute(ggml_backend_t backend, ggml_cg
}
// Sort the graph for improved parallelism.
@@ -324,7 +290,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
{
VK_LOG_DEBUG("ggml_vk_graph_optimize(" << graph->n_nodes << " nodes)");
ggml_backend_vk_context * ctx = (ggml_backend_vk_context *)backend->context;
-@@ -15596,7 +15601,7 @@ static void ggml_vk_graph_optimize(ggml_backend_t backend, struct ggml_cgraph *
+@@ -16485,7 +16495,7 @@ static void ggml_vk_graph_optimize(ggml_backend_t backend, struct ggml_cgraph *
}
}
@@ -333,7 +299,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
VK_LOG_DEBUG("ggml_backend_vk_event_record(backend=" << backend << ", event=" << event << ")");
ggml_backend_vk_context * ctx = (ggml_backend_vk_context *)backend->context;
vk_event *vkev = (vk_event *)event->context;
-@@ -15634,7 +15639,7 @@ static void ggml_backend_vk_event_record(ggml_backend_t backend, ggml_backend_ev
+@@ -16523,7 +16533,7 @@ static void ggml_backend_vk_event_record(ggml_backend_t backend, ggml_backend_ev
ctx->compute_ctx.reset();
}
@@ -342,7 +308,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
VK_LOG_DEBUG("ggml_backend_vk_event_wait(backend=" << backend << ", event=" << event << ")");
ggml_backend_vk_context * ctx = (ggml_backend_vk_context *)backend->context;
vk_event *vkev = (vk_event *)event->context;
-@@ -15731,7 +15736,10 @@ void ggml_backend_vk_get_device_memory(int device, size_t * free, size_t * total
+@@ -16620,7 +16630,10 @@ void ggml_backend_vk_get_device_memory(int device, size_t * free, size_t * total
*total += heap.size;
if (membudget_supported && i < budgetprops.heapUsage.size()) {
@@ -354,7 +320,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
} else {
*free += heap.size;
}
-@@ -15799,38 +15807,38 @@ struct ggml_backend_vk_device_context {
+@@ -16688,38 +16701,38 @@ struct ggml_backend_vk_device_context {
int op_offload_min_batch_size;
};
@@ -400,7 +366,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
ggml_backend_vk_device_context * ctx = (ggml_backend_vk_device_context *)dev->context;
props->name = ggml_backend_vk_device_get_name(dev);
-@@ -15846,13 +15854,13 @@ static void ggml_backend_vk_device_get_props(ggml_backend_dev_t dev, struct ggml
+@@ -16735,13 +16748,13 @@ static void ggml_backend_vk_device_get_props(ggml_backend_dev_t dev, struct ggml
};
}
@@ -416,7 +382,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
ggml_backend_vk_device_context * ctx = (ggml_backend_vk_device_context *)dev->context;
const vk_device& device = ggml_vk_get_device(ctx->device);
-@@ -16384,7 +16392,7 @@ static bool ggml_backend_vk_device_supports_op(ggml_backend_dev_t dev, const ggm
+@@ -17292,7 +17305,7 @@ static bool ggml_backend_vk_device_supports_op(ggml_backend_dev_t dev, const ggm
UNUSED(dev);
}
@@ -425,7 +391,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
if (buft->iface.get_name != ggml_backend_vk_buffer_type_name) {
return false;
}
-@@ -16410,13 +16418,13 @@ static int64_t ggml_vk_get_op_batch_size(const ggml_tensor * op) {
+@@ -17318,13 +17331,13 @@ static int64_t ggml_vk_get_op_batch_size(const ggml_tensor * op) {
}
}
@@ -441,7 +407,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
ggml_backend_vk_device_context * ctx = (ggml_backend_vk_device_context *)dev->context;
auto device = ggml_vk_get_device(ctx->device);
-@@ -16439,7 +16447,7 @@ static ggml_backend_event_t ggml_backend_vk_device_event_new(ggml_backend_dev_t
+@@ -17347,7 +17360,7 @@ static ggml_backend_event_t ggml_backend_vk_device_event_new(ggml_backend_dev_t
};
}
@@ -450,7 +416,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
ggml_backend_vk_device_context * ctx = (ggml_backend_vk_device_context *)dev->context;
auto device = ggml_vk_get_device(ctx->device);
-@@ -16459,7 +16467,7 @@ static void ggml_backend_vk_device_event_free(ggml_backend_dev_t dev, ggml_backe
+@@ -17367,7 +17380,7 @@ static void ggml_backend_vk_device_event_free(ggml_backend_dev_t dev, ggml_backe
delete event;
}
@@ -459,7 +425,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
VK_LOG_DEBUG("ggml_backend_vk_device_event_synchronize(backend=" << dev << ", event=" << event << ")");
ggml_backend_vk_device_context * ctx = (ggml_backend_vk_device_context *)dev->context;
auto device = ggml_vk_get_device(ctx->device);
-@@ -16516,7 +16524,7 @@ static vk_buffer ggml_vk_buffer_from_host_ptr(vk_device & device, void * ptr, si
+@@ -17424,7 +17437,7 @@ static vk_buffer ggml_vk_buffer_from_host_ptr(vk_device & device, void * ptr, si
return buf;
}
@@ -468,7 +434,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu
VK_LOG_DEBUG("ggml_backend_vk_device_buffer_from_host_ptr(backend=" << dev << ", ptr=" << ptr << ", size=" << size << ")");
GGML_UNUSED(max_tensor_size);
-@@ -16554,17 +16562,17 @@ static const struct ggml_backend_device_i ggml_backend_vk_device_i = {
+@@ -17462,17 +17475,17 @@ static const struct ggml_backend_device_i ggml_backend_vk_device_i = {
/* .event_synchronize = */ ggml_backend_vk_device_event_synchronize,
};
diff --git a/llama.cpp.patches/patches/src_llama-context.cpp.patch b/llama.cpp.patches/patches/src_llama-context.cpp.patch
index 6f5eec20..26661001 100644
--- a/llama.cpp.patches/patches/src_llama-context.cpp.patch
+++ b/llama.cpp.patches/patches/src_llama-context.cpp.patch
@@ -1,7 +1,7 @@
diff --git a/src/llama-context.cpp b/src/llama-context.cpp
--- a/llama.cpp/src/llama-context.cpp
+++ b/llama.cpp/src/llama-context.cpp
-@@ -448,6 +448,16 @@ void llama_context::sched_reserve() {
+@@ -476,6 +476,16 @@ void llama_context::sched_reserve() {
LLAMA_LOG_DEBUG("%s: worst-case: n_tokens = %d, n_seqs = %d, n_outputs = %d\n", __func__, n_tokens, n_seqs, n_outputs);
// resolve automatic Flash Attention use
diff --git a/llama.cpp.patches/patches/src_models_eagle3.cpp.patch b/llama.cpp.patches/patches/src_models_eagle3.cpp.patch
new file mode 100644
index 00000000..1ff9ce7c
--- /dev/null
+++ b/llama.cpp.patches/patches/src_models_eagle3.cpp.patch
@@ -0,0 +1,41 @@
+diff --git a/src/models/eagle3.cpp b/src/models/eagle3.cpp
+--- a/llama.cpp/src/models/eagle3.cpp
++++ b/llama.cpp/src/models/eagle3.cpp
+@@ -91,18 +91,6 @@ void llama_model_eagle3::load_arch_tensors(llama_model_loader &) {
+ }
+ }
+
+-std::unique_ptr<llm_graph_context> llama_model_eagle3::build_arch_graph(const llm_graph_params & params) const {
+- switch (params.gtype) {
+- case LLM_GRAPH_TYPE_ENCODER:
+- return std::make_unique<graph<true>>(*this, params);
+- case LLM_GRAPH_TYPE_DEFAULT:
+- case LLM_GRAPH_TYPE_DECODER:
+- return std::make_unique<graph<false>>(*this, params);
+- default:
+- GGML_ABORT("invalid graph type");
+- };
+-}
+-
+ template <>
+ ggml_tensor * llama_model_eagle3::graph<true>::build_inp_embd_enc() const {
+ ggml_tensor * cur = nullptr;
+@@ -321,3 +309,18 @@ llama_model_eagle3::graph<false>::graph(const llama_model & model, const llm_gra
+
+ ggml_build_forward_expand(gf, cur);
+ }
++
++// Defined after the graph<true>/graph<false> constructor specializations above:
++// cosmocc's clang rejects an explicit specialization that appears after the
++// point where make_unique<graph<...>> would implicitly instantiate it.
++std::unique_ptr<llm_graph_context> llama_model_eagle3::build_arch_graph(const llm_graph_params & params) const {
++ switch (params.gtype) {
++ case LLM_GRAPH_TYPE_ENCODER:
++ return std::make_unique<graph<true>>(*this, params);
++ case LLM_GRAPH_TYPE_DEFAULT:
++ case LLM_GRAPH_TYPE_DECODER:
++ return std::make_unique<graph<false>>(*this, params);
++ default:
++ GGML_ABORT("invalid graph type");
++ };
++}
diff --git a/llama.cpp.patches/patches/tools_server_server-models.cpp.patch b/llama.cpp.patches/patches/tools_server_server-models.cpp.patch
index 7f1b70c6..98f7b7e7 100644
--- a/llama.cpp.patches/patches/tools_server_server-models.cpp.patch
+++ b/llama.cpp.patches/patches/tools_server_server-models.cpp.patch
@@ -1,7 +1,7 @@
diff --git a/tools/server/server-models.cpp b/tools/server/server-models.cpp
--- a/llama.cpp/tools/server/server-models.cpp
+++ b/llama.cpp/tools/server/server-models.cpp
-@@ -31,6 +31,7 @@
+@@ -33,6 +33,7 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
@@ -9,7 +9,29 @@ diff --git a/tools/server/server-models.cpp b/tools/server/server-models.cpp
extern char **environ;
#endif
-@@ -715,9 +716,12 @@ void server_models::unload_lru() {
+@@ -496,13 +497,19 @@ void server_models::load_models() {
+ }
+
+ // wait for all targeted models to reach UNLOADED; cv.wait handles unlock/relock
+- cv.wait(lk, [&]() {
++ // Use wait_for() instead of wait() to work around a Cosmopolitan libc bug
++ // where untimed futex waits on XNU (macOS) expire after ~72 minutes,
++ // causing condition_variable::wait() to throw ETIMEDOUT.
++ auto all_unloaded = [&]() {
+ for (const auto & name : to_unload) {
+ auto it = mapping.find(name);
+ if (it != mapping.end() && it->second.meta.is_running()) return false;
+ }
+ return true;
+- });
++ };
++ while (!all_unloaded()) {
++ cv.wait_for(lk, std::chrono::seconds(30));
++ }
+
+ // collect all threads to join in one pass while the lock is held:
+ // - monitoring threads from just-unloaded models (to_unload)
+@@ -807,9 +814,12 @@ void server_models::unload_lru() {
// wait for unload to complete
{
std::unique_lock<std::mutex> lk(mutex);
@@ -25,7 +47,19 @@ diff --git a/tools/server/server-models.cpp b/tools/server/server-models.cpp
}
}
}
-@@ -826,6 +830,22 @@ void server_models::load(const std::string & name) {
+@@ -823,7 +833,10 @@ void server_models::load(const std::string & name) {
+ std::unique_lock<std::mutex> lk(mutex);
+ // edge case: block until any in-progress reload has finished so we always load
+ // against the freshest preset and a consistent mapping state
+- cv.wait(lk, [this]() { return !is_reloading; });
++ // Use wait_for() instead of wait() to work around the XNU futex timeout bug.
++ while (is_reloading) {
++ cv.wait_for(lk, std::chrono::seconds(30));
++ }
+
+ auto meta = mapping[name].meta;
+ if (meta.status != SERVER_MODEL_STATUS_UNLOADED) {
+@@ -915,15 +928,34 @@ void server_models::load(const std::string & name) {
});
std::thread stopping_thread([&]() {
@@ -45,32 +79,38 @@ diff --git a/tools/server/server-models.cpp b/tools/server/server-models.cpp
+ sigdelset(&block_mask, SIGTRAP);
+ pthread_sigmask(SIG_BLOCK, &block_mask, nullptr);
+
- // thread to monitor stopping signal OR child crash
+ // thread to monitor explicit stop requests; child crash is signalled via child_proc->stopped
auto is_stopping = [this, &name]() {
return this->stopping_models.find(name) != this->stopping_models.end();
-@@ -835,7 +855,10 @@ void server_models::load(const std::string & name) {
};
{
std::unique_lock<std::mutex> lk(this->mutex);
-- this->cv_stop.wait(lk, should_wake);
-+ // Use wait_for() instead of wait() to work around XNU futex timeout bug
-+ while (!should_wake()) {
+- this->cv_stop.wait(lk, [&]() {
+- return is_stopping() || child_proc->stopped.load(std::memory_order_acquire);
+- });
++ // Use wait_for() instead of wait() to work around a Cosmopolitan
++ // libc bug where untimed futex waits on XNU (macOS) expire after
++ // ~72 minutes, causing condition_variable::wait() to throw ETIMEDOUT.
++ while (!(is_stopping() || child_proc->stopped.load(std::memory_order_acquire))) {
+ this->cv_stop.wait_for(lk, std::chrono::seconds(30));
+ }
}
- // child may have already exited (e.g. crashed) — skip shutdown sequence
- if (!subprocess_alive(child_proc.get())) {
-@@ -984,13 +1007,14 @@ void server_models::update_loaded_info(const std::string & name, std::string & r
+ // child crashed or finished on its own — skip graceful shutdown sequence
+ if (child_proc->stopped.load(std::memory_order_acquire)) {
+@@ -1237,14 +1269,16 @@ void server_models::wait(const std::string & name, std::function<bool(const serv
+ }
- void server_models::wait_until_loading_finished(const std::string & name) {
- std::unique_lock<std::mutex> lk(mutex);
-- cv.wait(lk, [this, &name]() {
-+ // Use wait_for() instead of wait() to work around XNU futex timeout bug
+ void server_models::wait(std::unique_lock<std::mutex> & lk, const std::string & name, std::function<bool(const server_model_meta &)> predicate) {
+- cv.wait(lk, [this, &name, &predicate]() {
++ // Use wait_for() instead of wait() to work around a Cosmopolitan libc bug
++ // where untimed futex waits on XNU (macOS) expire after ~72 minutes,
++ // causing condition_variable::wait() to throw ETIMEDOUT.
+ while (true) {
auto it = mapping.find(name);
- if (it != mapping.end()) {
-- return it->second.meta.status != SERVER_MODEL_STATUS_LOADING;
-+ if (it != mapping.end() && it->second.meta.status != SERVER_MODEL_STATUS_LOADING) {
+- return predicate(it->second.meta);
+-
++ if (it != mapping.end() && predicate(it->second.meta)) {
+ break;
}
- return false;
diff --git a/llama.cpp.patches/patches/tools_server_server.cpp.patch b/llama.cpp.patches/patches/tools_server_server.cpp.patch
index f292b9d0..f9c8402b 100644
--- a/llama.cpp.patches/patches/tools_server_server.cpp.patch
+++ b/llama.cpp.patches/patches/tools_server_server.cpp.patch
@@ -52,7 +52,7 @@ diff --git a/tools/server/server.cpp b/tools/server/server.cpp
common_init();
if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_SERVER)) {
-@@ -309,6 +326,13 @@ int llama_server(int argc, char ** argv) {
+@@ -332,6 +349,13 @@ int llama_server(int argc, char ** argv) {
// this will unblock start_loop()
ctx_server.terminate();
};
@@ -66,7 +66,7 @@ diff --git a/tools/server/server.cpp b/tools/server/server.cpp
}
// TODO: refactor in common/console
-@@ -339,6 +363,11 @@ int llama_server(int argc, char ** argv) {
+@@ -368,6 +392,11 @@ int llama_server(int argc, char ** argv) {
} else {
SRV_INF("server is listening on %s\n", ctx_http.listening_address.c_str());
@@ -77,8 +77,8 @@ diff --git a/tools/server/server.cpp b/tools/server/server.cpp
+
// optionally, notify router server that this instance is ready
std::thread monitor_thread;
- if (server_models::is_child_server()) {
-@@ -363,5 +392,48 @@ int llama_server(int argc, char ** argv) {
+ if (child.is_child()) {
+@@ -392,5 +421,48 @@ int llama_server(int argc, char ** argv) {
}
}
diff --git a/llama.cpp.patches/patches/vendor_cpp-httplib_httplib.cpp.patch b/llama.cpp.patches/patches/vendor_cpp-httplib_httplib.cpp.patch
index bd1e2919..d5b4dcf1 100644
--- a/llama.cpp.patches/patches/vendor_cpp-httplib_httplib.cpp.patch
+++ b/llama.cpp.patches/patches/vendor_cpp-httplib_httplib.cpp.patch
@@ -1,7 +1,7 @@
diff --git a/vendor/cpp-httplib/httplib.cpp b/vendor/cpp-httplib/httplib.cpp
--- a/llama.cpp/vendor/cpp-httplib/httplib.cpp
+++ b/llama.cpp/vendor/cpp-httplib/httplib.cpp
-@@ -6291,6 +6291,22 @@ void ThreadPool::cleanup_finished_threads() {
+@@ -6333,6 +6333,22 @@ void ThreadPool::cleanup_finished_threads() {
}
void ThreadPool::worker(bool is_dynamic) {
@@ -24,7 +24,7 @@ diff --git a/vendor/cpp-httplib/httplib.cpp b/vendor/cpp-httplib/httplib.cpp
for (;;) {
std::function<void()> fn;
{
-@@ -6308,7 +6324,13 @@ void ThreadPool::worker(bool is_dynamic) {
+@@ -6350,7 +6366,13 @@ void ThreadPool::worker(bool is_dynamic) {
break;
}
} else {
diff --git a/llamafile/BUILD.mk b/llamafile/BUILD.mk
index da2ab857..464aa27d 100644
--- a/llamafile/BUILD.mk
+++ b/llamafile/BUILD.mk
@@ -234,6 +234,7 @@ LLAMAFILE_SERVER_SUPPORT_OBJS := \
o/$(MODE)/llama.cpp/tools/server/server-http.cpp.o \
o/$(MODE)/llama.cpp/tools/server/server-models.cpp.o \
o/$(MODE)/llama.cpp/tools/server/server-queue.cpp.o \
+ o/$(MODE)/llama.cpp/tools/server/server-schema.cpp.o \
o/$(MODE)/llama.cpp/tools/server/server-task.cpp.o \
o/$(MODE)/llama.cpp/tools/server/server-tools.cpp.o \
$(UI_GEN_OBJ)
diff --git a/llamafile/chatbot_cli.cpp b/llamafile/chatbot_cli.cpp
index f0beaf86..3c312635 100644
--- a/llamafile/chatbot_cli.cpp
+++ b/llamafile/chatbot_cli.cpp
@@ -230,7 +230,9 @@ int cli_main(int argc, char **argv) {
// Load image bitmaps
for (const auto &image_path : params.image) {
- mtmd::bitmap bmp(mtmd_helper_bitmap_init_from_file(mtmd_ctx, image_path.c_str()));
+ // init_from_file now returns a wrapper {bitmap, video_ctx}; chatbot
+ // is image-only, so take the bitmap (placeholder=false loads pixels).
+ mtmd::bitmap bmp(mtmd_helper_bitmap_init_from_file(mtmd_ctx, image_path.c_str(), false).bitmap);
if (!bmp.ptr) {
fprintf(stderr, "error: failed to load image: %s\n", image_path.c_str());
cleanup(mtmd_ctx, sampler, ctx, model);
diff --git a/llamafile/chatbot_eval.cpp b/llamafile/chatbot_eval.cpp
index 932eff76..7c6e5956 100644
--- a/llamafile/chatbot_eval.cpp
+++ b/llamafile/chatbot_eval.cpp
@@ -167,8 +167,10 @@ bool eval_string(std::string_view s, bool add_special, bool parse_special) {
// Create bitmaps from decoded image data
mtmd::bitmaps bitmaps;
for (const auto &image : extraction.images) {
+ // init_from_buf now returns a wrapper {bitmap, video_ctx}; chatbot is
+ // image-only, so take the bitmap (placeholder=false loads real pixels).
mtmd::bitmap bmp(mtmd_helper_bitmap_init_from_buf(
- g_mtmd, (const unsigned char *)image.data(), image.size()));
+ g_mtmd, (const unsigned char *)image.data(), image.size(), false).bitmap);
if (!bmp.ptr) {
err("failed to load image");
return false;
diff --git a/llamafile/version.h b/llamafile/version.h
index aeb76619..ad4ea88e 100644
--- a/llamafile/version.h
+++ b/llamafile/version.h
@@ -20,7 +20,7 @@
#define LLAMAFILE_MAJOR 0
#define LLAMAFILE_MINOR 10
-#define LLAMAFILE_PATCH 3
+#define LLAMAFILE_PATCH 4
#define LLAMAFILE_VERSION \
(100000000 * LLAMAFILE_MAJOR + 1000000 * LLAMAFILE_MINOR + LLAMAFILE_PATCH)
diff --git a/tests/integration/tests/test_multimodal.py b/tests/integration/tests/test_multimodal.py
index c78f02de..693afb54 100644
--- a/tests/integration/tests/test_multimodal.py
+++ b/tests/integration/tests/test_multimodal.py
@@ -67,7 +67,7 @@ class TestMultimodalCLI:
)
assert result.returncode != 0, "Should fail with marker/image mismatch"
- assert "markers" in result.stderr.lower() or "match" in result.stderr.lower()
+ assert "image preprocessing failed" in result.stderr.lower()
@pytest.mark.multimodal