pub struct ScratchSpaceManager { /* private fields */ }Expand description
Manager for per-thread scratch space (non-WASM version).
Provides each thread with its own scratch buffer for temporary computations during inference, avoiding allocation on the hot path.
§Design
- Each thread gets a dedicated scratch buffer on first access
- Buffers are sized based on model dimensions
- Scratch is reset at the start of each generation step
- Thread-safe lazy initialization
Implementations§
Source§impl ScratchSpaceManager
impl ScratchSpaceManager
Sourcepub fn for_model(hidden_dim: usize, max_threads: usize) -> Result<Self>
pub fn for_model(hidden_dim: usize, max_threads: usize) -> Result<Self>
Create a scratch manager sized for model dimensions.
§Arguments
hidden_dim- Model hidden dimensionmax_threads- Maximum number of threads
Sourcepub fn get_scratch(&self) -> Result<ScratchSpace<'_>>
pub fn get_scratch(&self) -> Result<ScratchSpace<'_>>
Sourcepub fn reset_all(&self)
pub fn reset_all(&self)
Reset all thread scratch buffers.
Should be called at the start of each generation step.
Sourcepub fn scratch_size(&self) -> usize
pub fn scratch_size(&self) -> usize
Get the configured scratch size per thread.
Sourcepub fn active_threads(&self) -> usize
pub fn active_threads(&self) -> usize
Get the number of active threads with scratch buffers.
Sourcepub fn stats(&self) -> ScratchStats
pub fn stats(&self) -> ScratchStats
Get statistics about scratch usage.
Trait Implementations§
Source§impl Debug for ScratchSpaceManager
Available on non-WebAssembly only.
impl Debug for ScratchSpaceManager
Available on non-WebAssembly only.
impl Send for ScratchSpaceManager
Available on non-WebAssembly only.
impl Sync for ScratchSpaceManager
Available on non-WebAssembly only.
Auto Trait Implementations§
impl !Freeze for ScratchSpaceManager
impl !RefUnwindSafe for ScratchSpaceManager
impl Unpin for ScratchSpaceManager
impl UnsafeUnpin for ScratchSpaceManager
impl UnwindSafe for ScratchSpaceManager
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