Feature Request: fixed VRAM allocation pool
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 22/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- cpp
調査の方向性
The request centres on the CUDA backend's buffer allocation, so start with ggml_backend_cuda_buffer_type_alloc_buffer in ggml/src/ggml-cuda.cu and trace where cudaMalloc is called for model weights and the KV cache. The issue proposes a fixed pool sized as a fraction of VRAM, but the design (how to size it, how to handle fragmentation and freeing) is unsettled and the code in the issue is an unverified sketch. Done would need a maintainer-agreed design before any implementation.
索引モデルが issue の本文から書いたものです。
説明
Prerequisites
- I am running the latest code. Mention the version if possible as well.
- I carefully followed the README.md.
- I searched using keywords relevant to my issue to make sure that I am creating a new issue that is not already open (or closed).
- I reviewed the Discussions, and have a new and useful enhancement to share.
Feature Description
It would be nice to be able to set the value of preallocated VRAM in percents like for vLLM (ex. 0.9 = 90%) and to use preallocated pool in this mode, so that extra software never influence beellama work.
Motivation
The problem: whatever manually crafted settings for beellama and model are made, the VRAM consumption is not fully controlled, because VRAM is allocated during context growth and beellama work and because other GUI applications (browsers, electron-based projects) also continue to consume extra VRAM. Currently Firefox can easily consume up to 1.5 GB vram and begin with 100 MB initially, so generation speed just drops to almost zero from unpredictable moment.
Possible Implementation
LLM based suggestions:
Method 2: Code Modification (Hard Physical Reservation Pool)
If you want llama.cpp to allocate a single massive contiguous block of VRAM (e.g., 20 GB out of 24 GB) via cudaMalloc at program start, and have GGML consume slices of that block instead of calling cudaMalloc dynamically:
Step 1: Create a Fixed Global Pool
In ggml/src/ggml-cuda.cu (or ggml-cuda.cpp), declare a static memory pool pointer and allocate it during CUDA backend initialization:
// Static preallocated pool
static void* g_cuda_vram_pool = nullptr;
static size_t g_vram_pool_offset = 0;
static size_t g_vram_pool_size = 0;
void init_cuda_vram_pool(size_t reserve_bytes) {
if (g_cuda_vram_pool != nullptr) return;
// Physically allocate the entire pool at start
cudaError_t err = cudaMalloc(&g_cuda_vram_pool, reserve_bytes);
if (err == cudaSuccess) {
g_vram_pool_size = reserve_bytes;
printf("CUDA: Preallocated %zx bytes of VRAM pool successfully.\n", reserve_bytes);
} else {
printf("CUDA: Failed to preallocate VRAM pool: %s\n", cudaGetErrorString(err));
}
}
Step 2: Override GGML's CUDA Buffer Allocation Function
In ggml-cuda.cu, locate the buffer allocation function used by the CUDA backend: ggml_backend_cuda_buffer_type_alloc_buffer.
Replace the underlying cudaMalloc call inside that function so it returns an offset pointer into g_cuda_vram_pool:
// Simplistic bump-allocator replacement inside CUDA backend
static void* pool_alloc(size_t size) {
// Maintain 256-byte alignment required by CUDA
size_t aligned_size = (size + 255) & ~255;
if (g_vram_pool_offset + aligned_size > g_vram_pool_size) {
printf("CUDA Pool Error: Out of preallocated VRAM!\n");
return nullptr;
}
void* ptr = (uint8_t*)g_cuda_vram_pool + g_vram_pool_offset;
g_vram_pool_offset += aligned_size;
return ptr;
}
// In your buffer allocation routine:
// Replace cudaMalloc(&ptr, size) with:
ptr = pool_alloc(size);
Step 3: Call Initialization in llama_backend_init
Call init_cuda_vram_pool(target_size_bytes) inside your initialization function (e.g., llama_backend_init) before loading model layers or allocating context buffers.
Result
When llama.cpp starts up, it immediately issues a single cudaMalloc call for your requested size. All model weights, KV cache matrices, and scratch workspaces allocated during token generation will be carved directly out of this existing buffer. No further calls to cudaMalloc or cudaFree will touch the driver or OS.
- 主要言語
- C++
- スター
- 1.2k
- フォーク
- 80
- 平均マージ
- 4日 20時間
- マージ済み PR(30日)
- 2
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Anbeeld/beellama.cpp のほかの issue
-
[BUG] KVarN assertion failure in build_inp_mem_hybrid_iswa() due to uninitialized self_kvarn_rotオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
Anbeeld/beellama.cpp#205 ·
-
難易度 3/5 半日 初心者へのやさしさ 58/100
Anbeeld/beellama.cpp#206 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 57/100
Anbeeld/beellama.cpp#204 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
Anbeeld/beellama.cpp#203 · コメント 2 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
Anbeeld/beellama.cpp#202 · コメント 1 件 ·
Anbeeld/beellama.cpp の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
CachyOS/packageinstaller#144 ·
メンテナーはふだん 1 日以内に返信
-
documentation
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
TomerAberbach/profiler-md#951 ·
メンテナーはふだん 1 日以内に返信
-
[Bug] Default key routing (JavaStringHash) picks a different partition than the Java client for about half of keys対応中かも @0z5a が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
apache/pulsar-client-go#1575 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
pocoproject/poco#5764 ·
メンテナーはふだん 2 日以内に返信
-
bug cpp-core-guidelines low-priority
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
NatronGitHub/openfx-supportext#164 ·
メンテナーはふだん 1 日以内に返信