CpuBackend

Struct CpuBackend 

Source
pub struct CpuBackend;
Expand description

CPU backend for tensor operations.

Implementations§

Source§

impl CpuBackend

Source

pub const fn new() -> Self

Creates a new CPU backend.

Source§

impl CpuBackend

Source

pub fn add<T: Numeric>(dst: &mut [T], a: &[T], b: &[T])

Adds two slices element-wise.

Source

pub fn sub<T: Numeric>(dst: &mut [T], a: &[T], b: &[T])

Subtracts two slices element-wise.

Source

pub fn mul<T: Numeric>(dst: &mut [T], a: &[T], b: &[T])

Multiplies two slices element-wise.

Source

pub fn div<T: Numeric>(dst: &mut [T], a: &[T], b: &[T])

Divides two slices element-wise.

Source

pub fn add_scalar<T: Numeric>(dst: &mut [T], a: &[T], scalar: T)

Adds a scalar to each element.

Source

pub fn mul_scalar<T: Numeric>(dst: &mut [T], a: &[T], scalar: T)

Multiplies each element by a scalar.

Source

pub fn neg<T: Numeric>(dst: &mut [T], a: &[T])

Negates each element.

Source

pub fn abs<T: Numeric>(dst: &mut [T], a: &[T])

Computes absolute value of each element.

Source§

impl CpuBackend

Source

pub fn relu<T: Float>(dst: &mut [T], a: &[T])

Applies ReLU activation: max(0, x).

Source

pub fn sigmoid<T: Float>(dst: &mut [T], a: &[T])

Applies sigmoid activation: 1 / (1 + exp(-x)).

Source

pub fn tanh<T: Float>(dst: &mut [T], a: &[T])

Applies tanh activation.

Source

pub fn exp<T: Float>(dst: &mut [T], a: &[T])

Applies exponential function.

Source

pub fn ln<T: Float>(dst: &mut [T], a: &[T])

Applies natural logarithm.

Source

pub fn sqrt<T: Float>(dst: &mut [T], a: &[T])

Applies square root.

Source

pub fn square<T: Numeric>(dst: &mut [T], a: &[T])

Squares each element.

Source§

impl CpuBackend

Source

pub fn sum<T: Numeric>(a: &[T]) -> T

Computes the sum of all elements.

Source

pub fn prod<T: Numeric>(a: &[T]) -> T

Computes the product of all elements.

Source

pub fn max<T: Numeric>(a: &[T]) -> Option<T>

Finds the maximum element.

Source

pub fn min<T: Numeric>(a: &[T]) -> Option<T>

Finds the minimum element.

Source

pub fn mean<T: Float>(a: &[T]) -> Option<T>

Computes the mean of all elements.

Source

pub fn argmax<T: Numeric>(a: &[T]) -> Option<usize>

Finds the index of the maximum element.

Source

pub fn argmin<T: Numeric>(a: &[T]) -> Option<usize>

Finds the index of the minimum element.

Source§

impl CpuBackend

Source

pub fn matmul<T: Numeric>( c: &mut [T], a: &[T], b: &[T], m: usize, n: usize, k: usize, )

Performs matrix multiplication: C = A @ B.

A is (m x k), B is (k x n), C is (m x n). Uses optimized GEMM from matrixmultiply crate for f32/f64, falls back to cache-efficient tiled implementation for other types.

Source

pub fn sgemm( c: &mut [f32], a: &[f32], b: &[f32], m: usize, n: usize, k: usize, alpha: f32, beta: f32, )

Performs optimized f32 matrix multiplication using matrixmultiply crate.

C = alpha * A @ B + beta * C

Source

pub fn dgemm( c: &mut [f64], a: &[f64], b: &[f64], m: usize, n: usize, k: usize, alpha: f64, beta: f64, )

Performs optimized f64 matrix multiplication using matrixmultiply crate.

C = alpha * A @ B + beta * C

Source

pub fn matmul_f32( c: &mut [f32], a: &[f32], b: &[f32], m: usize, n: usize, k: usize, )

Performs f32 matrix multiplication: C = A @ B using optimized GEMM.

Source

pub fn matmul_f64( c: &mut [f64], a: &[f64], b: &[f64], m: usize, n: usize, k: usize, )

Performs f64 matrix multiplication: C = A @ B using optimized GEMM.

Source

pub fn transpose<T: Scalar>(dst: &mut [T], src: &[T], rows: usize, cols: usize)

Transposes a matrix.

A is (rows x cols), B is (cols x rows).

Source

pub fn dot<T: Numeric>(a: &[T], b: &[T]) -> T

Computes dot product of two vectors.

Source§

impl CpuBackend

Source

pub fn eq<T: Scalar + PartialEq>(dst: &mut [bool], a: &[T], b: &[T])

Element-wise equality comparison.

Source

pub fn lt<T: Numeric>(dst: &mut [bool], a: &[T], b: &[T])

Element-wise less-than comparison.

Source

pub fn gt<T: Numeric>(dst: &mut [bool], a: &[T], b: &[T])

Element-wise greater-than comparison.

Source§

impl CpuBackend

Source

pub fn fill<T: Scalar>(dst: &mut [T], value: T)

Fills a slice with a value.

Source

pub fn fill_zeros<T: Scalar>(dst: &mut [T])

Fills a slice with zeros.

Source

pub fn copy<T: Scalar>(dst: &mut [T], src: &[T])

Copies from source to destination.

Trait Implementations§

Source§

impl Backend for CpuBackend

Source§

fn name(&self) -> &'static str

Returns the name of this backend.
Source§

fn is_available(&self) -> bool

Returns whether this backend is available on the current system.
Source§

fn capabilities(&self) -> DeviceCapabilities

Returns the device capabilities.
Source§

fn allocate(&self, size: usize) -> *mut u8

Allocates memory on this backend.
Source§

fn deallocate(&self, ptr: *mut u8, size: usize)

Deallocates memory on this backend.
Source§

fn copy_to_device(&self, dst: *mut u8, src: *const u8, size: usize)

Copies data from host to device.
Source§

fn copy_to_host(&self, dst: *mut u8, src: *const u8, size: usize)

Copies data from device to host.
Source§

fn copy_device_to_device(&self, dst: *mut u8, src: *const u8, size: usize)

Copies data within the device.
Source§

fn synchronize(&self)

Synchronizes the device (waits for all operations to complete).
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.