From 6ce21345be1f447063adfd223916b0f2f2962a7a Mon Sep 17 00:00:00 2001 From: Gahow Wang Date: Sat, 30 May 2026 12:50:04 +0800 Subject: [PATCH] cuda: add cached_trim() to release pooled GPU buffers Exposes the caching allocator's trim() through a public free function. Called after weight fusion during model loading to free temporary buffers that would otherwise sit in the pool and cause OOM. Co-Authored-By: Claude Opus 4.6 (1M context) --- crates/xserv-cuda/src/allocator.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/xserv-cuda/src/allocator.rs b/crates/xserv-cuda/src/allocator.rs index f007d22..3bd9e31 100644 --- a/crates/xserv-cuda/src/allocator.rs +++ b/crates/xserv-cuda/src/allocator.rs @@ -100,6 +100,13 @@ pub fn cached_alloc(size: usize) -> Result { }) } +/// Free all cached (unused) GPU buffers back to the driver. +pub fn cached_trim() { + ALLOCATOR.with(|cell| { + cell.borrow_mut().trim(); + }); +} + /// Return a raw GPU pointer to the caching allocator's free list. /// Called from `GpuBuffer::Drop` for pooled buffers. Takes raw pointer /// and size to avoid re-triggering Drop.