pub struct CpuBackend { /* private fields */ }Expand description
CPU compute backend using Candle for tensor operations.
Implementations§
Source§impl CpuBackend
impl CpuBackend
Sourcepub fn candle_device(&self) -> &Device
pub fn candle_device(&self) -> &Device
Returns the Candle device.
Trait Implementations§
Source§impl ComputeBackend for CpuBackend
impl ComputeBackend for CpuBackend
Source§fn allocate(&self, shape: &[usize], dtype: DType) -> Result<Self::Tensor>
fn allocate(&self, shape: &[usize], dtype: DType) -> Result<Self::Tensor>
Allocates a new tensor filled with zeros.
Source§fn from_slice(&self, data: &[f32], shape: &[usize]) -> Result<Self::Tensor>
fn from_slice(&self, data: &[f32], shape: &[usize]) -> Result<Self::Tensor>
Creates a tensor from raw data.
Source§fn matmul(&self, a: &Self::Tensor, b: &Self::Tensor) -> Result<Self::Tensor>
fn matmul(&self, a: &Self::Tensor, b: &Self::Tensor) -> Result<Self::Tensor>
Performs matrix multiplication: C = A @ B.
Source§fn batch_matmul(
&self,
a: &Self::Tensor,
b: &Self::Tensor,
) -> Result<Self::Tensor>
fn batch_matmul( &self, a: &Self::Tensor, b: &Self::Tensor, ) -> Result<Self::Tensor>
Performs batched matrix multiplication.
Source§fn attention(
&self,
q: &Self::Tensor,
k: &Self::Tensor,
v: &Self::Tensor,
mask: Option<&Self::Tensor>,
scale: Option<f32>,
) -> Result<Self::Tensor>
fn attention( &self, q: &Self::Tensor, k: &Self::Tensor, v: &Self::Tensor, mask: Option<&Self::Tensor>, scale: Option<f32>, ) -> Result<Self::Tensor>
Performs scaled dot-product attention.
Returns softmax(Q @ K^T / sqrt(d_k)) @ V with optional causal masking.
Source§fn rms_norm(
&self,
x: &Self::Tensor,
weight: &Self::Tensor,
eps: f32,
) -> Result<Self::Tensor>
fn rms_norm( &self, x: &Self::Tensor, weight: &Self::Tensor, eps: f32, ) -> Result<Self::Tensor>
Applies RMS normalization: x * weight / sqrt(mean(x^2) + eps).
Source§fn layer_norm(
&self,
x: &Self::Tensor,
weight: &Self::Tensor,
bias: Option<&Self::Tensor>,
eps: f32,
) -> Result<Self::Tensor>
fn layer_norm( &self, x: &Self::Tensor, weight: &Self::Tensor, bias: Option<&Self::Tensor>, eps: f32, ) -> Result<Self::Tensor>
Applies Layer normalization.
Source§fn silu(&self, x: &Self::Tensor) -> Result<Self::Tensor>
fn silu(&self, x: &Self::Tensor) -> Result<Self::Tensor>
Applies SiLU (Swish) activation: x * sigmoid(x).
Source§fn softmax(&self, x: &Self::Tensor, dim: i32) -> Result<Self::Tensor>
fn softmax(&self, x: &Self::Tensor, dim: i32) -> Result<Self::Tensor>
Applies softmax along the specified dimension.
Source§fn add(&self, a: &Self::Tensor, b: &Self::Tensor) -> Result<Self::Tensor>
fn add(&self, a: &Self::Tensor, b: &Self::Tensor) -> Result<Self::Tensor>
Element-wise addition.
Source§fn mul(&self, a: &Self::Tensor, b: &Self::Tensor) -> Result<Self::Tensor>
fn mul(&self, a: &Self::Tensor, b: &Self::Tensor) -> Result<Self::Tensor>
Element-wise multiplication.
Source§fn transpose(&self, x: &Self::Tensor) -> Result<Self::Tensor>
fn transpose(&self, x: &Self::Tensor) -> Result<Self::Tensor>
Transposes the last two dimensions.
Source§impl Debug for CpuBackend
impl Debug for CpuBackend
Auto Trait Implementations§
impl !RefUnwindSafe for CpuBackend
impl !UnwindSafe for CpuBackend
impl Freeze for CpuBackend
impl Send for CpuBackend
impl Sync for CpuBackend
impl Unpin for CpuBackend
impl UnsafeUnpin 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
impl<T> ErasedDestructor for Twhere
T: 'static,
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> ⓘ
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