pub struct CpuBackend;Expand description
Deterministic CPU backend with fixed operation order.
Trait Implementations§
Source§impl Backend for CpuBackend
impl Backend for CpuBackend
fn add(&self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor, KernelError>
fn sub(&self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor, KernelError>
fn mul(&self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor, KernelError>
fn relu(&self, input: &Tensor) -> Tensor
fn sigmoid(&self, input: &Tensor) -> Tensor
fn exp(&self, input: &Tensor) -> Tensor
fn tanh_act(&self, input: &Tensor) -> Tensor
fn softmax_last_dim(&self, input: &Tensor) -> Result<Tensor, KernelError>
fn log_softmax_last_dim(&self, input: &Tensor) -> Result<Tensor, KernelError>
fn logsumexp_last_dim(&self, input: &Tensor) -> Result<Tensor, KernelError>
fn layer_norm_last_dim( &self, input: &Tensor, params: LayerNormLastDimParams<'_>, ) -> Result<Tensor, KernelError>
fn max_pool2d_nhwc( &self, input: &Tensor, kernel_h: usize, kernel_w: usize, stride_h: usize, stride_w: usize, ) -> Result<Tensor, KernelError>
fn avg_pool2d_nhwc( &self, input: &Tensor, kernel_h: usize, kernel_w: usize, stride_h: usize, stride_w: usize, ) -> Result<Tensor, KernelError>
fn conv2d_nhwc( &self, input: &Tensor, kernel: &Tensor, bias: Option<&Tensor>, stride_h: usize, stride_w: usize, ) -> Result<Tensor, KernelError>
fn depthwise_conv2d_nhwc( &self, input: &Tensor, kernel: &Tensor, bias: Option<&Tensor>, stride_h: usize, stride_w: usize, ) -> Result<Tensor, KernelError>
fn separable_conv2d_nhwc( &self, input: &Tensor, params: SeparableConv2dParams<'_>, stride_h: usize, stride_w: usize, ) -> Result<Tensor, KernelError>
fn batch_norm2d_nhwc( &self, input: &Tensor, params: BatchNorm2dParams<'_>, ) -> Result<Tensor, KernelError>
fn group_norm_nhwc( &self, input: &Tensor, params: GroupNormNhwcParams<'_>, ) -> Result<Tensor, KernelError>
fn rms_norm_last_dim( &self, input: &Tensor, params: RmsNormLastDimParams<'_>, ) -> Result<Tensor, KernelError>
fn matmul_2d(&self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor, KernelError>
Source§fn div(&self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor, KernelError>
fn div(&self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor, KernelError>
Element-wise division with broadcast.
Source§fn transpose_2d(&self, input: &Tensor) -> Result<Tensor, KernelError>
fn transpose_2d(&self, input: &Tensor) -> Result<Tensor, KernelError>
Transpose a 2-D matrix.
Source§fn sum_all(&self, input: &Tensor) -> Tensor
fn sum_all(&self, input: &Tensor) -> Tensor
Scalar sum of all elements (returns a scalar tensor).
Source§fn mul_scalar(&self, input: &Tensor, scalar: f32) -> Tensor
fn mul_scalar(&self, input: &Tensor, scalar: f32) -> Tensor
Multiply every element by a scalar.
Source§fn reciprocal(&self, input: &Tensor) -> Tensor
fn reciprocal(&self, input: &Tensor) -> Tensor
Element-wise reciprocal (1/x).
Source§impl BackwardOps for CpuBackend
impl BackwardOps for CpuBackend
Source§fn relu_backward(
&self,
upstream: &Tensor,
forward_input: &Tensor,
) -> Result<Tensor, KernelError>
fn relu_backward( &self, upstream: &Tensor, forward_input: &Tensor, ) -> Result<Tensor, KernelError>
ReLU backward:
grad_input[i] = upstream[i] * (forward_input[i] > 0 ? 1 : 0).Source§fn sigmoid_backward(
&self,
upstream: &Tensor,
forward_output: &Tensor,
) -> Result<Tensor, KernelError>
fn sigmoid_backward( &self, upstream: &Tensor, forward_output: &Tensor, ) -> Result<Tensor, KernelError>
Sigmoid backward:
grad_input[i] = upstream[i] * s[i] * (1 - s[i]) where s = forward output.Source§fn tanh_backward(
&self,
upstream: &Tensor,
forward_output: &Tensor,
) -> Result<Tensor, KernelError>
fn tanh_backward( &self, upstream: &Tensor, forward_output: &Tensor, ) -> Result<Tensor, KernelError>
Tanh backward:
grad_input[i] = upstream[i] * (1 - t[i]^2) where t = forward output.Source§fn exp_backward(
&self,
upstream: &Tensor,
forward_output: &Tensor,
) -> Result<Tensor, KernelError>
fn exp_backward( &self, upstream: &Tensor, forward_output: &Tensor, ) -> Result<Tensor, KernelError>
Exp backward:
grad_input[i] = upstream[i] * e[i] where e = forward output.Source§fn reduce_sum_backward(
&self,
upstream: &Tensor,
original_shape: &[usize],
) -> Result<Tensor, KernelError>
fn reduce_sum_backward( &self, upstream: &Tensor, original_shape: &[usize], ) -> Result<Tensor, KernelError>
Reduce-sum backward: broadcast scalar gradient to all elements of
original_shape.Source§fn matmul_backward(
&self,
upstream: &Tensor,
lhs: &Tensor,
rhs: &Tensor,
) -> Result<(Tensor, Tensor), KernelError>
fn matmul_backward( &self, upstream: &Tensor, lhs: &Tensor, rhs: &Tensor, ) -> Result<(Tensor, Tensor), KernelError>
MatMul backward:
grad_lhs = upstream @ rhs^T, grad_rhs = lhs^T @ upstream.Source§fn add_backward(
&self,
upstream: &Tensor,
_lhs: &Tensor,
_rhs: &Tensor,
) -> Result<(Tensor, Tensor), KernelError>
fn add_backward( &self, upstream: &Tensor, _lhs: &Tensor, _rhs: &Tensor, ) -> Result<(Tensor, Tensor), KernelError>
Add backward: gradient passes through unchanged to both operands.
Source§fn sub_backward(
&self,
upstream: &Tensor,
_lhs: &Tensor,
_rhs: &Tensor,
) -> Result<(Tensor, Tensor), KernelError>
fn sub_backward( &self, upstream: &Tensor, _lhs: &Tensor, _rhs: &Tensor, ) -> Result<(Tensor, Tensor), KernelError>
Sub backward:
grad_lhs = upstream, grad_rhs = -upstream.Source§fn mul_backward(
&self,
upstream: &Tensor,
lhs: &Tensor,
rhs: &Tensor,
) -> Result<(Tensor, Tensor), KernelError>
fn mul_backward( &self, upstream: &Tensor, lhs: &Tensor, rhs: &Tensor, ) -> Result<(Tensor, Tensor), KernelError>
Mul backward:
grad_lhs = upstream * rhs, grad_rhs = upstream * lhs.Source§impl Clone for CpuBackend
impl Clone for CpuBackend
Source§fn clone(&self) -> CpuBackend
fn clone(&self) -> CpuBackend
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CpuBackend
impl Debug for CpuBackend
Source§impl Default for CpuBackend
impl Default for CpuBackend
Source§fn default() -> CpuBackend
fn default() -> CpuBackend
Returns the “default value” for a type. Read more
impl Copy for CpuBackend
Auto Trait Implementations§
impl Freeze for CpuBackend
impl RefUnwindSafe for CpuBackend
impl Send for CpuBackend
impl Sync for CpuBackend
impl Unpin for CpuBackend
impl UnsafeUnpin for CpuBackend
impl UnwindSafe for CpuBackend
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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