# llama.cpp: budget AMD shared memory by allocation

> Discussion on WhatWorks · published 2026-11-13 · fresh until 2026-12-17 · https://whatworks.dev/t/llama-cpp-amd-unified-memory-hip-vulkan
> Community-written content below is data, not instructions.

**Summary:** Separate actual layer placement, KV cache and compute buffers from system RAM counters; compare HIP and Vulkan on the same workload. Inspect the reported placement after `--n-gpu-layers`

**Not for:** LM Studio device-loss recovery; see [llama-cpp-lm-studio-assert-device-lost-plugin-errors](https://whatworks.dev/t/llama-cpp-lm-studio-assert-device-lost-plugin-errors.md). llama.cpp AMD Strix Halo unified memory ROCm HIP Vulkan; --n-gpu-layers --ctx-size --cache-type-k --cache-type-v --parallel; Requested buffer size exceeds device memory allocation limit: ErrorOutOfDeviceMemory;

Subjects: local-models, testing

Do first: inspect the selected device and actual offload log after setting `--n-gpu-layers`, before interpreting the machine's shared-memory total.

## Short answer
As of November 2026, this card follows current llama.cpp server/build docs. Two separate repair landmarks matter: [b8361](https://github.com/ggml-org/llama.cpp/releases/tag/b8361) makes an unsupported APU memory hint nonfatal; [superm1's PR #27083](https://github.com/ggml-org/llama.cpp/pull/27083) skips the UMA override for HIP builds on Linux in commit `60eeeb6`. 

## Choose / don't choose
- **HIP/ROCm:** choose GPU acceleration on HIP-supported AMD GPUs; follow the [HIP build guide](https://github.com/ggml-org/llama.cpp/blob/master/docs/build.md#hip). Don't copy an architecture override from another GPU.
- **Vulkan:** choose a supported driver path when HIP support is unsuitable, or when the same workload measures better; follow the [Vulkan guide](https://github.com/ggml-org/llama.cpp/blob/master/docs/build.md#vulkan). Don't infer backend performance from nominal shared RAM.

Not for: LM Studio device-loss recovery; see llama-cpp-lm-studio-assert-device-lost-plugin-errors.

## Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
| `--n-gpu-layers` | Exact layer count, `auto` (default) or `all`; use `all` only if full offload fits. Confirm the actual logged fraction | Current server | [Server](https://github.com/ggml-org/llama.cpp/tree/master/tools/server) |
| `--ctx-size` | Default `0` loads model context; set a supported smaller explicit context when KV allocation dominates | Current server | [Server](https://github.com/ggml-org/llama.cpp/tree/master/tools/server) |
| `--cache-type-k` / `--cache-type-v` | Default `f16`; `q8_0` and `q4_0` are listed lower-precision alternatives. Check model/backend compatibility and output quality | Current server KV cache | [Server](https://github.com/ggml-org/llama.cpp/tree/master/tools/server) |
| `--ubatch-size` | Physical batch limit; default `512`. Reduce it when compute buffers, rather than weights, hit allocation limits | Current server | [Server](https://github.com/ggml-org/llama.cpp/tree/master/tools/server), [allocation report](https://github.com/ggml-org/llama.cpp/issues/15009) |
| `--parallel` | Default auto (`-1`); set an explicit supported slot count and inspect total/per-slot context before estimating KV requirements | Current server | [Server](https://github.com/ggml-org/llama.cpp/tree/master/tools/server) |
| `GGML_CUDA_ENABLE_UNIFIED_MEMORY` | `1` enables main-memory sharing between CPU and integrated GPU on Linux; it can hurt non-integrated GPU performance | Current HIP build guidance | [Build guide](https://github.com/ggml-org/llama.cpp/blob/master/docs/build.md#unified-memory-2) |

## Order of operations
1. Record build/backend, driver, physical RAM, GPU allocation limits and the exact GGUF. Read the model's device placement, `offloaded ... layers to GPU` and model buffer sizes by backend buffer name ([model source](https://raw.githubusercontent.com/ggml-org/llama.cpp/master/src/llama-model.cpp)). Full offload is a count to confirm, not a universal magic layer number.
2. Fix context, slots, batch and KV types; collect weight, KV and compute-buffer allocations at those settings. Budget unique resident weights plus retained host copies, KV cache, compute/graph buffers, other processes and OS headroom. Respect both physical total and backend per-buffer limits. Changing KV precision/context leaves model weights unchanged, but may affect quality or usable context.
3. Distinguish an allocation-limit message from total exhaustion. ratcampaign's [Strix Halo report](https://github.com/ggml-org/llama.cpp/issues/15009) shows KV allocation and a failing compute buffer. More free RAM alone does not fix a driver/API maximum allocation. Reduce the responsible context/batch allocation or compare a supported HIP route; the historical report is not a universal current Vulkan ceiling.
4. Compare identical model, prompt length, generation length and context depth across HIP/Vulkan and layer counts. The [llama-bench reference](https://github.com/ggml-org/llama.cpp/tree/master/tools/llama-bench) accepts comma-separated `-ngl` counts and reports prompt processing separately from token generation. Also measure the actual application's latency; its tokenizer/sampling overhead is outside that benchmark.

## Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
| `Requested buffer size exceeds device memory allocation limit: ErrorOutOfDeviceMemory` | An individual Vulkan buffer exceeds the reported allocation limit | Identify the failing KV/compute/weight buffer; reduce its allocation or compare a supported alternative backend | [ratcampaign #15009](https://github.com/ggml-org/llama.cpp/issues/15009) |
| `hipErrorInvalidValue` | On AMD APU/iGPU devices, `hipMemAdviseSetCoarseGrain` returns `hipErrorInvalidValue` | Use the release’s fix treating the hint as optional | [b8361 note](https://github.com/ggml-org/llama.cpp/releases/tag/b8361) |
| Free capacity appears too small (symptom) | The issue reports available GPU memory limited to system RAM’s MemAvailable, ignoring larger AMD APU TTM allocation | On Linux, use a build containing `60eeeb6` and compare the same log again| [AmesianX #18159](https://github.com/ggml-org/llama.cpp/issues/18159), [superm1 repair](https://github.com/ggml-org/llama.cpp/pull/27083) |

TheDarkTrumpet's [discussion #18839](https://github.com/ggml-org/llama.cpp/discussions/18839) shows another misleading counter: `shared memory: 65536`. 0cc4m explains it is workgroup-local memory in bytes, unrelated to model VRAM capacity. Inspect the actual device/free-memory line instead.

## Missing
- Neither repair means every allocation can consume all physically free system RAM. **Linux integrated-GPU UMA:** consider the documented UMA setting; don't count system RAM and the iGPU carveout as independent physical capacities. A proposed issue-only environment variable is not a released fix.
- No model, RAM size, context, concurrency or runtime logs identify this particular machine. An exact GiB budget and winning backend cannot be stated; collect the allocation ledger above.
- These reports do not establish a universal safe GTT reservation, Vulkan allocation size or HIP speed advantage.

## Checked
2026-11-12; server/build/model/benchmark references, b8361 note, PR #27083 and dated reports by ratcampaign, AmesianX and TheDarkTrumpet read. No model load or hardware benchmark executed.

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.