pub struct FusedAdamState { /* private fields */ }Expand description
Interleaved (parameter, momentum, variance) layout used by the fused CPU update.
§This is CPU code
Despite the “kernel fusion” vocabulary, nothing here touches a GPU: there is no
allocation, no kernel launch and no device memory. What the module really provides
is a blocked, cache-friendly, vectorizable Adam over an interleaved layout, and
the accounting below describes that layout — see
FusedAdamState::planned_layout_bytes.
Implementations§
Source§impl FusedAdamState
impl FusedAdamState
Sourcepub const MAX_LAYOUT_BYTES: usize
pub const MAX_LAYOUT_BYTES: usize
Largest layout this state will plan for, as a sanity bound on caller input.
Sourcepub fn new(config: KernelFusionConfig) -> Self
pub fn new(config: KernelFusionConfig) -> Self
Creates a new fused GPU state.
Sourcepub fn allocate_parameter(&mut self, id: String, size: usize) -> Result<()>
pub fn allocate_parameter(&mut self, id: String, size: usize) -> Result<()>
Registers a parameter in the interleaved layout plan.
No memory is allocated: the buffer records the parameter’s size, alignment and offset so the fused update can walk it in cache-friendly blocks.
§Errors
Returns an error when the requested layout exceeds
FusedAdamState::MAX_LAYOUT_BYTES.
Sourcepub fn run_fused_adam_block(
&mut self,
param_id: &str,
param: &mut [f32],
grad: &[f32],
lr: f32,
betas: (f32, f32),
eps: f32,
weight_decay: f32,
) -> Result<()>
pub fn run_fused_adam_block( &mut self, param_id: &str, param: &mut [f32], grad: &[f32], lr: f32, betas: (f32, f32), eps: f32, weight_decay: f32, ) -> Result<()>
Runs the blocked, vectorizable Adam update for one parameter.
The work is done on the CPU in optimal_block_size-sized blocks over the
interleaved layout; the block/grid arithmetic below mirrors the tiling a GPU
kernel would use, but no kernel is launched.
Sourcepub fn launch_multi_param_kernel(
&mut self,
params: Vec<(&str, &mut [f32], &[f32])>,
lr: f32,
betas: (f32, f32),
eps: f32,
weight_decay: f32,
) -> Result<()>
pub fn launch_multi_param_kernel( &mut self, params: Vec<(&str, &mut [f32], &[f32])>, lr: f32, betas: (f32, f32), eps: f32, weight_decay: f32, ) -> Result<()>
Launches multi-parameter fused kernel.
Sourcepub fn fused_layout_stats(&self) -> FusedLayoutStats
pub fn fused_layout_stats(&self) -> FusedLayoutStats
Statistics about the interleaved layout plan.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for FusedAdamState
impl RefUnwindSafe for FusedAdamState
impl Send for FusedAdamState
impl Sync for FusedAdamState
impl Unpin for FusedAdamState
impl UnsafeUnpin for FusedAdamState
impl UnwindSafe for FusedAdamState
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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