pub struct SsmStatePool { /* private fields */ }Expand description
A free-list pool of SequenceSlots for SSM-based models.
Pre-allocates capacity slots at construction time. Slots are identified
by their index into the internal slots vector.
Free slots are tracked by a free_list: Vec<usize>. alloc pops from the
list; release resets the slot and pushes back.
Implementations§
Source§impl SsmStatePool
impl SsmStatePool
Sourcepub fn from_forward_pass(
forward_pass: &dyn ForwardPass,
capacity: usize,
max_context_length: usize,
) -> Self
pub fn from_forward_pass( forward_pass: &dyn ForwardPass, capacity: usize, max_context_length: usize, ) -> Self
Create a pool by calling ForwardPass::allocate_sequence_state for each slot.
This is the preferred construction path because it delegates state
allocation to the architecture implementation, rather than hard-coding
the state type at the call site. The runtime calls this once at model
load time, after ForwardPass is available.
let pool = SsmStatePool::from_forward_pass(fwd_pass.as_ref(), capacity, max_ctx);Sourcepub fn new<F>(capacity: usize, make_state: F) -> Self
pub fn new<F>(capacity: usize, make_state: F) -> Self
Create a new pool using a factory closure to produce each slot’s state.
The closure is called once per slot with the slot index. Use it to
initialise arch-specific state (e.g. Mamba2SequenceState::new(...)).
let pool = SsmStatePool::new(8, |_| {
Box::new(Mamba2SequenceState::new(24, 16, 256, 4096))
});Sourcepub fn alloc(&mut self, request_id: u64) -> PoolResult<usize>
pub fn alloc(&mut self, request_id: u64) -> PoolResult<usize>
Allocate a free slot and bind it to request_id.
Returns Ok(slot_idx) on success.
§Errors
Returns PoolError::Exhausted when no free slots are available.
Sourcepub fn release(&mut self, idx: usize) -> PoolResult<()>
pub fn release(&mut self, idx: usize) -> PoolResult<()>
Release slot idx back to the free list.
The slot’s state is reset (zeroed) and its request_id cleared.
§Errors
Returns PoolError::InvalidSlot if idx is out of range or already free.
Sourcepub fn slot(&self, idx: usize) -> Option<&SequenceSlot>
pub fn slot(&self, idx: usize) -> Option<&SequenceSlot>
Get a shared reference to slot idx.
Returns None if the slot has never been initialised (should not happen
for a correctly-constructed pool) or the index is out of range.
Sourcepub fn slot_mut(&mut self, idx: usize) -> Option<&mut SequenceSlot>
pub fn slot_mut(&mut self, idx: usize) -> Option<&mut SequenceSlot>
Get a mutable reference to slot idx.
Returns None if the slot is uninitialised or out of range.
Sourcepub fn free_count(&self) -> usize
pub fn free_count(&self) -> usize
Number of currently free (unallocated) slots.
Sourcepub fn used_count(&self) -> usize
pub fn used_count(&self) -> usize
Number of currently allocated (live) slots.
Auto Trait Implementations§
impl Freeze for SsmStatePool
impl !RefUnwindSafe for SsmStatePool
impl !Send for SsmStatePool
impl !Sync for SsmStatePool
impl Unpin for SsmStatePool
impl UnsafeUnpin for SsmStatePool
impl !UnwindSafe for SsmStatePool
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