pub struct BlockPool { /* private fields */ }Expand description
Pre-allocated pool of KvPages shared across all sequences.
Pages are handed out via BlockPool::allocate and returned via
BlockPool::free. The pool never grows beyond its initial capacity.
Implementations§
Source§impl BlockPool
impl BlockPool
Sourcepub fn new(
capacity: usize,
block_size: usize,
num_layers: usize,
num_kv_heads: usize,
head_dim: usize,
) -> Self
pub fn new( capacity: usize, block_size: usize, num_layers: usize, num_kv_heads: usize, head_dim: usize, ) -> Self
Create a pool with capacity pages.
Every page is pre-allocated and zeroed at construction time so that subsequent allocations are O(1) pointer-hand-offs from the free list.
§Arguments
capacity– total number of physical pages.block_size– token slots per page.num_layers– number of transformer layers (informational; each logical layer has its own independent block list inBlockTable).num_kv_heads– number of KV attention heads.head_dim– per-head dimension.
Sourcepub fn allocate(&mut self) -> Option<usize>
pub fn allocate(&mut self) -> Option<usize>
Allocate one page and return its physical index.
Returns None when the pool is exhausted (out-of-memory).
Sourcepub fn free(&mut self, idx: usize)
pub fn free(&mut self, idx: usize)
Return page idx to the pool.
The page contents are not zeroed on release; callers must overwrite every slot they intend to read.
Sourcepub fn free_count(&self) -> usize
pub fn free_count(&self) -> usize
Number of pages currently available for allocation.
Sourcepub fn total_count(&self) -> usize
pub fn total_count(&self) -> usize
Total number of pages in the pool (constant after construction).
Sourcepub fn utilization(&self) -> f32
pub fn utilization(&self) -> f32
Fraction of pages currently in use, in [0.0, 1.0].
Returns 0.0 when the pool is empty (capacity == 0).
Auto Trait Implementations§
impl Freeze for BlockPool
impl RefUnwindSafe for BlockPool
impl Send for BlockPool
impl Sync for BlockPool
impl Unpin for BlockPool
impl UnsafeUnpin for BlockPool
impl UnwindSafe for BlockPool
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
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>
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>
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