Skip to content

ggml : add alloc_buffer_n to buffer type interface#23671

Draft
ggerganov wants to merge 2 commits into
masterfrom
gg/ggml-alloc-refactor-meta
Draft

ggml : add alloc_buffer_n to buffer type interface#23671
ggerganov wants to merge 2 commits into
masterfrom
gg/ggml-alloc-refactor-meta

Conversation

@ggerganov

Copy link
Copy Markdown
Member

Overview

cont #19378

The ggml_backend_meta_alloc_ctx_tensors_from_buft was a temporary workaround. This patch avoids the function by extending the buffer type interface with an API that allocates a backend buffer from a list of tensors. This decouples the ggml-alloc from meta backend specifics and allows more flexible buffer allocations in the future.

Additional information

Detailed review is still pending - atm this is a one-shot with Qwen3.6, so I have yet to check that the implementation is good. For now mainly interested in running the full CI over this.

Requirements

@github-actions github-actions Bot added Nvidia GPU Issues specific to Nvidia GPUs Vulkan Issues specific to the Vulkan backend ggml changes relating to the ggml tensor library for machine learning SYCL https://en.wikipedia.org/wiki/SYCL - GPU programming language Apple Metal https://en.wikipedia.org/wiki/Metal_(API) Ascend NPU issues specific to Ascend NPUs OpenCL Issues specific to the OpenCL backend IBM zDNN issues specific to IBM zDNN Accelerator Hexagon OpenVINO WebGPU labels May 25, 2026
michaelw9999 added a commit to michaelw9999/advanced-gguf-quantizer that referenced this pull request May 26, 2026
Port ggml-org/llama.cpp#23671 into advanced-gguf-quantizer as one local integration commit.

Includes upstream commits 0743dce657dc9901ee56734dbce571cf0a6abb8d (add alloc_buffer_n to buffer type interface) and 3f9bcab883c84c6336e100ce5d7408bb4bf47ac9 (fix cur_buf_size after buffer flush).
Add alloc_buffer_n method to ggml_backend_buffer_type_i
interface, with a public API ggml_backend_buft_alloc_buffer_n.

- Default implementation in ggml-backend.cpp handles multi-buffer
  splitting and tensor allocation via ggml_tallocr
- Meta buffer type provides custom implementation that creates
  per-device sub-contexts and delegates to simple buffer types
- ggml_backend_alloc_ctx_tensors_from_buft now collects tensors
  into a list and delegates to the new API
- Remove temporary ggml_backend_meta_alloc_ctx_tensors_from_buft
- Add NULL alloc_buffer_n to all existing buffer type
  interfaces (cpu, metal, openvino, hexagon, webgpu, zdnn, virtgpu, repack)

Assisted-by: llama.cpp:local pi
@ggerganov ggerganov force-pushed the gg/ggml-alloc-refactor-meta branch from 3f9bcab to 7c7be0f Compare June 15, 2026 13:06
@github-actions github-actions Bot added the CUDA Related to the CUDA backend label Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Apple Metal https://en.wikipedia.org/wiki/Metal_(API) Ascend NPU issues specific to Ascend NPUs CUDA Related to the CUDA backend ggml changes relating to the ggml tensor library for machine learning Hexagon IBM zDNN issues specific to IBM zDNN Accelerator Nvidia GPU Issues specific to Nvidia GPUs OpenCL Issues specific to the OpenCL backend OpenVINO SYCL https://en.wikipedia.org/wiki/SYCL - GPU programming language Vulkan Issues specific to the Vulkan backend WebGPU

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant