pub struct CpuTensorOpsImpl;Expand description
CPU implementation of tensor operations
Implementations§
Trait Implementations§
Source§impl TensorOps for CpuTensorOpsImpl
impl TensorOps for CpuTensorOpsImpl
Source§fn mul(&self, a: &Tensor, b: &Tensor) -> Result<Tensor>
fn mul(&self, a: &Tensor, b: &Tensor) -> Result<Tensor>
Element-wise multiplication: C = A * B
Source§fn attention(
&self,
query: &Tensor,
key: &Tensor,
value: &Tensor,
mask: Option<&Tensor>,
scale: Option<f32>,
) -> Result<Tensor>
fn attention( &self, query: &Tensor, key: &Tensor, value: &Tensor, mask: Option<&Tensor>, scale: Option<f32>, ) -> Result<Tensor>
Scaled dot-product attention
Source§fn layer_norm(
&self,
input: &Tensor,
weight: &Tensor,
bias: Option<&Tensor>,
eps: f32,
) -> Result<Tensor>
fn layer_norm( &self, input: &Tensor, weight: &Tensor, bias: Option<&Tensor>, eps: f32, ) -> Result<Tensor>
Layer normalization
Source§fn zeros(
&self,
shape: &[usize],
dtype: DataType,
device: &Device,
) -> Result<Tensor>
fn zeros( &self, shape: &[usize], dtype: DataType, device: &Device, ) -> Result<Tensor>
Create tensor with zeros
Source§fn randn(
&self,
shape: &[usize],
dtype: DataType,
device: &Device,
) -> Result<Tensor>
fn randn( &self, shape: &[usize], dtype: DataType, device: &Device, ) -> Result<Tensor>
Create tensor with random values
Source§fn concat(&self, tensors: &[&Tensor], dim: usize) -> Result<Tensor>
fn concat(&self, tensors: &[&Tensor], dim: usize) -> Result<Tensor>
Concatenate tensors along a dimension
Source§fn rms_norm(&self, input: &Tensor, weight: &Tensor, eps: f32) -> Result<Tensor>
fn rms_norm(&self, input: &Tensor, weight: &Tensor, eps: f32) -> Result<Tensor>
RMS normalization
Source§fn topk(&self, input: &Tensor, k: usize, dim: i64) -> Result<(Tensor, Tensor)>
fn topk(&self, input: &Tensor, k: usize, dim: i64) -> Result<(Tensor, Tensor)>
Top-k operation: returns (values, indices) for top k elements along dimension
Source§fn conv1d(
&self,
input: &Tensor,
weight: &Tensor,
bias: Option<&Tensor>,
stride: usize,
padding: usize,
) -> Result<Tensor>
fn conv1d( &self, input: &Tensor, weight: &Tensor, bias: Option<&Tensor>, stride: usize, padding: usize, ) -> Result<Tensor>
1D convolution
Source§fn gather(&self, input: &Tensor, dim: usize, indices: &Tensor) -> Result<Tensor>
fn gather(&self, input: &Tensor, dim: usize, indices: &Tensor) -> Result<Tensor>
Gather elements along dimension using indices
Source§fn scatter(
&self,
input: &Tensor,
dim: usize,
indices: &Tensor,
src: &Tensor,
) -> Result<Tensor>
fn scatter( &self, input: &Tensor, dim: usize, indices: &Tensor, src: &Tensor, ) -> Result<Tensor>
Scatter elements along dimension using indices
Source§fn flash_attention(
&self,
query: &Tensor,
key: &Tensor,
value: &Tensor,
scale: f32,
causal: bool,
) -> Result<Tensor>
fn flash_attention( &self, query: &Tensor, key: &Tensor, value: &Tensor, scale: f32, causal: bool, ) -> Result<Tensor>
Fused scaled dot-product attention (Flash Attention pattern)
Computes: softmax(Q @ K^T / sqrt(d_k)) @ V in a memory-efficient manner
Works for all attention-based models: LLaMA, Qwen, Gemma, Mistral, etc.
Auto Trait Implementations§
impl Freeze for CpuTensorOpsImpl
impl RefUnwindSafe for CpuTensorOpsImpl
impl Send for CpuTensorOpsImpl
impl Sync for CpuTensorOpsImpl
impl Unpin for CpuTensorOpsImpl
impl UnsafeUnpin for CpuTensorOpsImpl
impl UnwindSafe for CpuTensorOpsImpl
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