pub struct CacheFriendlyState {
pub interleaved_buffers: HashMap<usize, Vec<f32>>,
pub param_metadata: HashMap<usize, ParameterMetadata>,
pub step: usize,
pub cache_config: CacheConfig,
}Expand description
Cache-friendly memory layout for optimizer state.
This structure organizes optimizer state data to maximize cache utilization by grouping frequently accessed data together.
Fields§
§interleaved_buffers: HashMap<usize, Vec<f32>>Interleaved momentum and variance data for cache efficiency Format: [momentum[i], variance[i], momentum[i+1], variance[i+1], …]
param_metadata: HashMap<usize, ParameterMetadata>Parameter metadata for efficient access
step: usizeCurrent step counter
cache_config: CacheConfigCache configuration
Implementations§
Source§impl CacheFriendlyState
impl CacheFriendlyState
Sourcepub fn new(cache_config: CacheConfig) -> Self
pub fn new(cache_config: CacheConfig) -> Self
Creates a new cache-friendly state with the given configuration.
Sourcepub fn allocate_parameter(&mut self, param_id: usize, size: usize) -> Result<()>
pub fn allocate_parameter(&mut self, param_id: usize, size: usize) -> Result<()>
Allocates buffers for a parameter with optimal memory layout.
Sourcepub fn get_interleaved_buffer_mut(
&mut self,
param_id: usize,
) -> Option<(&mut [f32], usize)>
pub fn get_interleaved_buffer_mut( &mut self, param_id: usize, ) -> Option<(&mut [f32], usize)>
Gets direct access to interleaved buffer for efficient in-place operations.
Sourcepub fn get_buffers_mut(
&mut self,
param_id: usize,
) -> Option<(Vec<f32>, Vec<f32>)>
pub fn get_buffers_mut( &mut self, param_id: usize, ) -> Option<(Vec<f32>, Vec<f32>)>
Gets momentum and variance slices for a parameter (backward compatibility). Note: This creates temporary vectors and is less efficient than get_interleaved_buffer_mut.
Sourcepub fn update_buffers(
&mut self,
param_id: usize,
momentum: &[f32],
variance: &[f32],
) -> Result<()>
pub fn update_buffers( &mut self, param_id: usize, momentum: &[f32], variance: &[f32], ) -> Result<()>
Updates interleaved buffers with new momentum and variance values.
Sourcepub fn garbage_collect(&mut self, access_threshold: usize)
pub fn garbage_collect(&mut self, access_threshold: usize)
Clears unused buffers to free memory.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CacheFriendlyState
impl RefUnwindSafe for CacheFriendlyState
impl Send for CacheFriendlyState
impl Sync for CacheFriendlyState
impl Unpin for CacheFriendlyState
impl UnwindSafe for CacheFriendlyState
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