Skip to content

openvino : report the device allocation limit to ggml - #29124

Closed
lslusarczyk wants to merge 1 commit into
ggml-org:masterfrom
lslusarczyk:openvino-kvcache-alloc-limit
Closed

lslusarczyk wants to merge 1 commit into
ggml-org:masterfrom
lslusarczyk:openvino-kvcache-alloc-limit

Conversation

@lslusarczyk

Copy link
Copy Markdown
Contributor

Overview

OpenVINO reported no GPU allocation limit to ggml, so a single buffer for the whole kvcache was always used. A GPU caps the size of a single memory object and a model could fail to load if the context was too large (e.g. on an iGPU with a 4 GiB cap). With the real limit ggml splits the buffer and large contexts work.

Fixes #29087. See that issue for more details including reproduction steps.

Implementation details

The real limit is taken by getting the CL_DEVICE_MAX_MEM_ALLOC_SIZE property from a clGetDeviceInfo call once at GPU initialization phase. In case of failed query - old unlimited value is used as fallback, which is the same as previous behavior ensuring no regression.

Verification

Checked that all models mentioned in the issue as failing with large enough contexts now pass on my iGPU (UHD Graphics 770)

model context enough to cause error (see the issue) context checked result
Llama-3.2-1B 131071 131072 pass
Llama-3.2-3B 37449 65536 pass
Qwen2.5-14B 21845 22016 pass
Qwen2.5-32B 16383 16384 pass

The path on dGPU (Intel Arc Pro B70) has much larger limit (~30GiB). The code works as before in this path: alloc_tensor_range uses one allocation because kvcaches are below larger limit.

Executing on CPU doesn't enter this code at all as before - unlimited value is used.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES. Cursor IDE was used to find the issue root cause. It wrote the code under my guidance and verification with multiple changes requested by me or written by hand by me during the course of coding. This PR description was written by hand by me. Code change is fully understood and maintainable by me.

OpenVINO reported no GPU allocation limit to ggml, so a single buffer
for the whole kvcache was always used. A GPU caps the size of a single
memory object and a model could fail to load if the context was too
large (e.g. on an iGPU with a 4 GiB cap). With the real limit ggml
splits the buffer and large contexts work.

Assisted-by: Claude Opus 5
@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning OpenVINO labels Sep 19, 2026
@lslusarczyk
lslusarczyk marked this pull request as ready for review September 21, 2026 11:17
@lslusarczyk
lslusarczyk requested a review from wine99 as a code owner September 21, 2026 11:17
@wine99

wine99 commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

LGTM. I will trigger CI once the self-hosted machine for the OV CI is back online. cc @ravi9

@lslusarczyk

Copy link
Copy Markdown
Contributor Author

This change was cherry-picked and merged into dev_backend_openvino branch by this PR ravi9#256. The change will be incorporated into llama.cpp master together with other changes in dev_backend_openvino branch, therefore I'm closing this PR.

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

Labels

ggml changes relating to the ggml tensor library for machine learning OpenVINO

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Eval bug: OpenVINO backend fails with "unable to create context" when KV cache exceeds CL_DEVICE_MAX_MEM_ALLOC_SIZE

2 participants