pub struct CpuBackend;Expand description
CPU backend for tensor operations.
Implementations§
Source§impl CpuBackend
impl CpuBackend
Source§impl CpuBackend
impl CpuBackend
Sourcepub fn add<T: Numeric + Sync + Send>(dst: &mut [T], a: &[T], b: &[T])
pub fn add<T: Numeric + Sync + Send>(dst: &mut [T], a: &[T], b: &[T])
Adds two slices element-wise with optional parallelization.
Sourcepub fn sub<T: Numeric + Sync + Send>(dst: &mut [T], a: &[T], b: &[T])
pub fn sub<T: Numeric + Sync + Send>(dst: &mut [T], a: &[T], b: &[T])
Subtracts two slices element-wise with optional parallelization.
Sourcepub fn mul<T: Numeric + Sync + Send>(dst: &mut [T], a: &[T], b: &[T])
pub fn mul<T: Numeric + Sync + Send>(dst: &mut [T], a: &[T], b: &[T])
Multiplies two slices element-wise with optional parallelization.
Sourcepub fn div<T: Numeric + Sync + Send>(dst: &mut [T], a: &[T], b: &[T])
pub fn div<T: Numeric + Sync + Send>(dst: &mut [T], a: &[T], b: &[T])
Divides two slices element-wise with optional parallelization.
Sourcepub fn add_scalar<T: Numeric + Sync + Send>(dst: &mut [T], a: &[T], scalar: T)
pub fn add_scalar<T: Numeric + Sync + Send>(dst: &mut [T], a: &[T], scalar: T)
Adds a scalar to each element with optional parallelization.
Sourcepub fn mul_scalar<T: Numeric + Sync + Send>(dst: &mut [T], a: &[T], scalar: T)
pub fn mul_scalar<T: Numeric + Sync + Send>(dst: &mut [T], a: &[T], scalar: T)
Multiplies each element by a scalar with optional parallelization.
Source§impl CpuBackend
impl CpuBackend
Sourcepub fn relu<T: Float + Sync + Send>(dst: &mut [T], a: &[T])
pub fn relu<T: Float + Sync + Send>(dst: &mut [T], a: &[T])
Applies ReLU activation: max(0, x) with optional parallelization.
Sourcepub fn sigmoid<T: Float + Sync + Send>(dst: &mut [T], a: &[T])
pub fn sigmoid<T: Float + Sync + Send>(dst: &mut [T], a: &[T])
Applies sigmoid activation: 1 / (1 + exp(-x)) with optional parallelization.
Sourcepub fn tanh<T: Float + Sync + Send>(dst: &mut [T], a: &[T])
pub fn tanh<T: Float + Sync + Send>(dst: &mut [T], a: &[T])
Applies tanh activation with optional parallelization.
Sourcepub fn exp<T: Float + Sync + Send>(dst: &mut [T], a: &[T])
pub fn exp<T: Float + Sync + Send>(dst: &mut [T], a: &[T])
Applies exponential function with optional parallelization.
Sourcepub fn ln<T: Float + Sync + Send>(dst: &mut [T], a: &[T])
pub fn ln<T: Float + Sync + Send>(dst: &mut [T], a: &[T])
Applies natural logarithm with optional parallelization.
Source§impl CpuBackend
impl CpuBackend
Source§impl CpuBackend
impl CpuBackend
Sourcepub fn matmul<T: Numeric>(
c: &mut [T],
a: &[T],
b: &[T],
m: usize,
n: usize,
k: usize,
)
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.
Sourcepub fn sgemm(
c: &mut [f32],
a: &[f32],
b: &[f32],
m: usize,
n: usize,
k: usize,
alpha: f32,
beta: f32,
)
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
Sourcepub fn dgemm(
c: &mut [f64],
a: &[f64],
b: &[f64],
m: usize,
n: usize,
k: usize,
alpha: f64,
beta: f64,
)
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
Sourcepub fn matmul_f32(
c: &mut [f32],
a: &[f32],
b: &[f32],
m: usize,
n: usize,
k: usize,
)
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.
Sourcepub fn matmul_f64(
c: &mut [f64],
a: &[f64],
b: &[f64],
m: usize,
n: usize,
k: usize,
)
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.
Trait Implementations§
Source§impl Backend for CpuBackend
impl Backend for CpuBackend
Source§fn is_available(&self) -> bool
fn is_available(&self) -> bool
Source§fn capabilities(&self) -> DeviceCapabilities
fn capabilities(&self) -> DeviceCapabilities
Source§fn copy_to_device(&self, dst: *mut u8, src: *const u8, size: usize)
fn copy_to_device(&self, dst: *mut u8, src: *const u8, size: usize)
Source§fn copy_to_host(&self, dst: *mut u8, src: *const u8, size: usize)
fn copy_to_host(&self, dst: *mut u8, src: *const u8, size: usize)
Source§fn copy_device_to_device(&self, dst: *mut u8, src: *const u8, size: usize)
fn copy_device_to_device(&self, dst: *mut u8, src: *const u8, size: usize)
Source§fn synchronize(&self)
fn synchronize(&self)
Source§impl Clone for CpuBackend
impl Clone for CpuBackend
Source§fn clone(&self) -> CpuBackend
fn clone(&self) -> CpuBackend
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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
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 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
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>
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