pub struct SharedMemoryPool { /* private fields */ }Expand description
Shared memory pool for multiple models.
Manages multiple virtual memory pools with a global physical memory limit. Enables memory sharing across models with per-model statistics.
§Example
use candle_cuda_vmm::SharedMemoryPool;
use candle_core::Device;
let device = Device::new_cuda(0)?;
let mut shared_pool = SharedMemoryPool::new(
32 * 1024 * 1024 * 1024, // 32GB global physical limit
device,
)?;
// Register models
shared_pool.register_model("llama-7b", 64 * 1024 * 1024 * 1024)?; // 64GB virtual
shared_pool.register_model("gpt2", 32 * 1024 * 1024 * 1024)?; // 32GB virtual
// Allocate for specific model
let addr = shared_pool.allocate_for_model("llama-7b", 1024 * 1024 * 1024)?;Implementations§
Sourcepub fn deallocate_for_model(
&mut self,
model_id: &str,
offset: usize,
size: usize,
) -> Result<()>
pub fn deallocate_for_model( &mut self, model_id: &str, offset: usize, size: usize, ) -> Result<()>
Free from specific model’s pool.
§Arguments
model_id- Model identifier.offset- Offset in model’s virtual address space (bytes).size- Size to free (bytes).
Sourcepub fn get_model_stats(&self, model_id: &str) -> Option<MemoryStats>
pub fn get_model_stats(&self, model_id: &str) -> Option<MemoryStats>
Get per-model memory statistics.
Sourcepub fn global_stats(&self) -> GlobalMemoryStats
pub fn global_stats(&self) -> GlobalMemoryStats
Global memory statistics.
Sourcepub fn unregister_model(&mut self, model_id: &str) -> Result<()>
pub fn unregister_model(&mut self, model_id: &str) -> Result<()>
Unregister a model and free its resources.
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more