Skip to main content

CpuBackend

Struct CpuBackend 

Source
pub struct CpuBackend;
Expand description

Deterministic CPU backend with fixed operation order.

Trait Implementations§

Source§

impl Backend for CpuBackend

Source§

fn add(&self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor, KernelError>

Source§

fn sub(&self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor, KernelError>

Source§

fn mul(&self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor, KernelError>

Source§

fn relu(&self, input: &Tensor) -> Tensor

Source§

fn sigmoid(&self, input: &Tensor) -> Tensor

Source§

fn exp(&self, input: &Tensor) -> Tensor

Source§

fn tanh_act(&self, input: &Tensor) -> Tensor

Source§

fn softmax_last_dim(&self, input: &Tensor) -> Result<Tensor, KernelError>

Source§

fn log_softmax_last_dim(&self, input: &Tensor) -> Result<Tensor, KernelError>

Source§

fn logsumexp_last_dim(&self, input: &Tensor) -> Result<Tensor, KernelError>

Source§

fn layer_norm_last_dim( &self, input: &Tensor, params: LayerNormLastDimParams<'_>, ) -> Result<Tensor, KernelError>

Source§

fn max_pool2d_nhwc( &self, input: &Tensor, kernel_h: usize, kernel_w: usize, stride_h: usize, stride_w: usize, ) -> Result<Tensor, KernelError>

Source§

fn avg_pool2d_nhwc( &self, input: &Tensor, kernel_h: usize, kernel_w: usize, stride_h: usize, stride_w: usize, ) -> Result<Tensor, KernelError>

Source§

fn conv2d_nhwc( &self, input: &Tensor, kernel: &Tensor, bias: Option<&Tensor>, stride_h: usize, stride_w: usize, ) -> Result<Tensor, KernelError>

Source§

fn depthwise_conv2d_nhwc( &self, input: &Tensor, kernel: &Tensor, bias: Option<&Tensor>, stride_h: usize, stride_w: usize, ) -> Result<Tensor, KernelError>

Source§

fn separable_conv2d_nhwc( &self, input: &Tensor, params: SeparableConv2dParams<'_>, stride_h: usize, stride_w: usize, ) -> Result<Tensor, KernelError>

Source§

fn batch_norm2d_nhwc( &self, input: &Tensor, params: BatchNorm2dParams<'_>, ) -> Result<Tensor, KernelError>

Source§

fn group_norm_nhwc( &self, input: &Tensor, params: GroupNormNhwcParams<'_>, ) -> Result<Tensor, KernelError>

Source§

fn rms_norm_last_dim( &self, input: &Tensor, params: RmsNormLastDimParams<'_>, ) -> Result<Tensor, KernelError>

Source§

fn matmul_2d(&self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor, KernelError>

Source§

fn neg(&self, input: &Tensor) -> Tensor

Element-wise negation.
Source§

fn div(&self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor, KernelError>

Element-wise division with broadcast.
Source§

fn sqrt(&self, input: &Tensor) -> Tensor

Element-wise square root.
Source§

fn transpose_2d(&self, input: &Tensor) -> Result<Tensor, KernelError>

Transpose a 2-D matrix.
Source§

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

Multiply every element by a scalar.
Source§

fn reciprocal(&self, input: &Tensor) -> Tensor

Element-wise reciprocal (1/x).
Source§

impl BackwardOps for CpuBackend

Source§

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>

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>

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>

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>

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>

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>

Add backward: gradient passes through unchanged to both operands.
Source§

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>

Mul backward: grad_lhs = upstream * rhs, grad_rhs = upstream * lhs.
Source§

fn conv2d_input_backward( &self, upstream: &Tensor, kernel: &Tensor, input_shape: &[usize], stride_h: usize, stride_w: usize, ) -> Result<Tensor, KernelError>

Conv2d backward (input gradient): compute dL/dInput from dL/dOutput and weights. Read more
Source§

impl Clone for CpuBackend

Source§

fn clone(&self) -> CpuBackend

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CpuBackend

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CpuBackend

Source§

fn default() -> CpuBackend

Returns the “default value” for a type. Read more
Source§

impl Copy for CpuBackend

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.