- Pre-allocate compute buffer once, reuse across decode steps (no malloc/free)
- Create persistent ggml_threadpool with strict CPU binding + high priority
- Pre-allocate graph work buffer, grow only when needed
- Use ggml_graph_plan + ggml_graph_compute instead of ggml_graph_compute_with_ctx
to leverage the persistent threadpool
Eliminates per-token overhead:
- malloc/free of ~500MB compute buffer
- pthread creation/destruction (12 threads)
- work buffer allocation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Instead of memcpy-ing the entire KV cache history into new GGML tensors
each decode step (~52MB at 100 tokens for Qwen2.5-32B), point the GGML
tensor data pointer directly at the cache's host memory.
The cache memory is long-lived (persists across steps) and contiguous,
so GGML can read it directly during graph computation without copying.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>