CpuBackend

Struct CpuBackend 

Source
pub struct CpuBackend;
Expand description

CPU backend using strided-kernel and GEMM.

Dispatched automatically when tensors reside on LogicalMemorySpace::MainMemory. Implements the semiring core and semiring fast-path families for Standard<T>.

§Examples

use tenferro_algebra::Standard;
use tenferro_device::LogicalMemorySpace;
use tenferro_prims::{CpuBackend, CpuContext, SemiringCoreDescriptor, TensorSemiringCore};
use tenferro_tensor::{MemoryOrder, Tensor};

let mut ctx = CpuContext::try_new(4).unwrap();
let col = MemoryOrder::ColumnMajor;
let mem = LogicalMemorySpace::MainMemory;
let a_base = Tensor::<f64>::zeros(&[3, 4], mem, col).unwrap();
let a = a_base.permute(&[1, 0]).unwrap();
let mut b = Tensor::<f64>::zeros(&[4, 3], mem, col).unwrap();
let plan = <CpuBackend as TensorSemiringCore<Standard<f64>>>::plan(
    &mut ctx,
    &SemiringCoreDescriptor::MakeContiguous,
    &[&[4, 3], &[4, 3]],
)
.unwrap();
<CpuBackend as TensorSemiringCore<Standard<f64>>>::execute(
    &mut ctx,
    &plan,
    1.0,
    &[&a],
    0.0,
    &mut b,
)
.unwrap();

Implementations§

Source§

impl CpuBackend

Source

pub fn resolve_conj<T: Scalar + Conjugate>( _ctx: &mut CpuContext, src: &Tensor<T>, ) -> Tensor<T>

Materialize a lazily-conjugated tensor.

If src.is_conjugated() is false, returns a shallow clone. If true, routes through the tensor-layer logical combine substrate so the result is resolved (conjugated = false) without reimplementing the copy logic here.

§Examples
use tenferro_prims::{CpuBackend, CpuContext};

let mut ctx = CpuContext::try_new(1).unwrap();
let a_conj = a.into_conj(); // lazy
let a_resolved = CpuBackend::resolve_conj(&mut ctx, &a_conj);
assert!(!a_resolved.is_conjugated());

Trait Implementations§

Source§

impl<S: Scalar + 'static> TensorAnalyticPrims<Standard<S>> for CpuBackend

Source§

type Plan = CpuAnalyticPlan

Source§

type Context = CpuContext

Source§

fn plan( _ctx: &mut Self::Context, desc: &AnalyticPrimsDescriptor, shapes: &[&[usize]], ) -> Result<Self::Plan>

Plan an analytic-family operation for the given input/output shapes. Read more
Source§

fn execute( _ctx: &mut Self::Context, plan: &Self::Plan, alpha: S, inputs: &[&Tensor<S>], beta: S, output: &mut Tensor<S>, ) -> Result<()>

Execute a previously planned analytic-family operation. Read more
Source§

fn has_analytic_support(desc: AnalyticPrimsDescriptor) -> bool

Report whether the backend advertises support for the given descriptor. Read more
Source§

impl<Input> TensorComplexRealPrims<Input> for CpuBackend
where Input: ComplexFloat + Scalar + 'static, Input::Real: CpuScalarValue + Float,

Source§

type Real = <Input as ComplexFloat>::Real

The real-valued output scalar type.
Source§

type Plan = CpuComplexRealPlan

Backend plan type.
Source§

type Context = CpuContext

Backend execution context.
Source§

fn plan( _ctx: &mut Self::Context, desc: &ComplexRealPrimsDescriptor, shapes: &[&[usize]], ) -> Result<Self::Plan>

Plan a complex-to-real unary operation for the given input/output shapes.
Source§

fn execute( _ctx: &mut Self::Context, plan: &Self::Plan, alpha: Input::Real, inputs: &[&Tensor<Input>], beta: Input::Real, output: &mut Tensor<Self::Real>, ) -> Result<()>

Execute a previously planned complex-to-real unary operation. Read more
Source§

fn has_complex_real_support(desc: ComplexRealPrimsDescriptor) -> bool

Report whether the backend advertises support for the given descriptor.
Source§

impl<Input> TensorComplexScalePrims<Input> for CpuBackend
where Input: ComplexFloat + Scalar + 'static + Add<Output = Input> + Mul<Input::Real, Output = Input> + Mul<Output = Input>, Input::Real: Scalar + Send + Sync,

Source§

type Plan = CpuComplexScalePlan

Backend plan type.
Source§

type Context = CpuContext

Backend execution context.
Source§

fn plan( _ctx: &mut Self::Context, desc: &ComplexScalePrimsDescriptor, shapes: &[&[usize]], ) -> Result<Self::Plan>

Plan a complex-by-real pointwise operation for the given shapes.
Source§

fn execute( _ctx: &mut Self::Context, plan: &Self::Plan, alpha: Input, lhs: &Tensor<Input>, rhs: &Tensor<Input::Real>, beta: Input, output: &mut Tensor<Input>, ) -> Result<()>

Execute a previously planned complex-by-real pointwise operation.
Source§

fn has_complex_scale_support(desc: ComplexScalePrimsDescriptor) -> bool

Report whether the backend advertises support for the given descriptor.
Source§

impl<S: Scalar + 'static> TensorIndexingPrims<Standard<S>> for CpuBackend

Source§

type Plan = CpuIndexingPlan

Backend-specific execution plan.
Source§

type Context = CpuContext

Backend execution context.
Source§

fn plan( _ctx: &mut Self::Context, desc: &IndexingPrimsDescriptor, shapes: &[&[usize]], ) -> Result<Self::Plan>

Plan an indexing operation for the given input/index/output shapes. Read more
Source§

fn execute( _ctx: &mut Self::Context, plan: &Self::Plan, inputs: &[&Tensor<S>], indices: &Tensor<i64>, output: &mut Tensor<S>, ) -> Result<()>

Execute a previously planned indexing operation. Read more
Source§

fn has_indexing_support(_desc: IndexingPrimsDescriptor) -> bool

Report whether the backend advertises support for the given descriptor.
Source§

impl<S> TensorMetadataCastPrims<S> for CpuBackend
where S: Scalar + NumCast + 'static,

Source§

type Plan = MetadataCastPrimsDescriptor

Backend plan type.
Source§

type Context = CpuContext

Backend execution context.
Source§

fn plan( _ctx: &mut Self::Context, desc: &MetadataCastPrimsDescriptor, shapes: &[&[usize]], ) -> Result<Self::Plan>

Plan a metadata-to-scalar bridge operation.
Source§

fn execute( _ctx: &mut Self::Context, plan: &Self::Plan, alpha: S, inputs: &[MetadataScalarTensorRef<'_, S>], beta: S, output: &mut Tensor<S>, ) -> Result<()>

Execute a previously planned metadata-to-scalar bridge operation. Read more
Source§

fn has_metadata_cast_support(desc: MetadataCastPrimsDescriptor) -> bool

Report whether the backend advertises support for the given descriptor.
Source§

impl TensorMetadataPrims for CpuBackend

Source§

type Plan = MetadataPrimsDescriptor

Backend plan type.
Source§

type Context = CpuContext

Backend execution context.
Source§

fn plan( _ctx: &mut Self::Context, desc: &MetadataPrimsDescriptor, inputs: &[MetadataTensorRef<'_>], output: MetadataTensorMut<'_>, ) -> Result<Self::Plan>

Plan a metadata-family operation for the given input and output tensor handles.
Source§

fn execute( _ctx: &mut Self::Context, plan: &Self::Plan, inputs: &[MetadataTensorRef<'_>], output: MetadataTensorMut<'_>, ) -> Result<()>

Execute a previously planned metadata-family operation in overwrite mode.
Source§

fn has_metadata_support(desc: MetadataPrimsDescriptor) -> bool

Report whether the backend advertises support for the given descriptor.
Source§

impl TensorRngPrims<Standard<f64>> for CpuBackend

Source§

type Plan = (RngPrimsDescriptor, Vec<usize>)

Backend-specific execution plan.
Source§

type Context = CpuContext

Backend execution context.
Source§

fn plan( _ctx: &mut Self::Context, desc: &RngPrimsDescriptor, shapes: &[&[usize]], ) -> Result<Self::Plan>

Plan a tensor RNG operation for the given output shape.
Source§

fn execute( _ctx: &mut Self::Context, plan: &Self::Plan, generator: &mut Generator, output: &mut Tensor<f64>, ) -> Result<()>

Execute a previously planned RNG operation.
Source§

fn has_rng_support(desc: RngPrimsDescriptor) -> bool

Report whether the backend advertises support for the given descriptor.
Source§

impl TensorRngPrims<Standard<i32>> for CpuBackend

Source§

type Plan = (RngPrimsDescriptor, Vec<usize>)

Backend-specific execution plan.
Source§

type Context = CpuContext

Backend execution context.
Source§

fn plan( _ctx: &mut Self::Context, desc: &RngPrimsDescriptor, shapes: &[&[usize]], ) -> Result<Self::Plan>

Plan a tensor RNG operation for the given output shape.
Source§

fn execute( _ctx: &mut Self::Context, plan: &Self::Plan, generator: &mut Generator, output: &mut Tensor<i32>, ) -> Result<()>

Execute a previously planned RNG operation.
Source§

fn has_rng_support(desc: RngPrimsDescriptor) -> bool

Report whether the backend advertises support for the given descriptor.
Source§

impl<S: Scalar + 'static> TensorScalarPrims<Standard<S>> for CpuBackend

Source§

type Plan = CpuScalarPlan

Source§

type Context = CpuContext

Source§

fn plan( _ctx: &mut Self::Context, desc: &ScalarPrimsDescriptor, shapes: &[&[usize]], ) -> Result<Self::Plan>

Plan a scalar-family operation for the given input/output shapes. Read more
Source§

fn execute( _ctx: &mut Self::Context, plan: &Self::Plan, alpha: S, inputs: &[&Tensor<S>], beta: S, output: &mut Tensor<S>, ) -> Result<()>

Execute a previously planned scalar-family operation. Read more
Source§

fn has_scalar_support(desc: ScalarPrimsDescriptor) -> bool

Report whether the backend advertises support for the given descriptor. Read more
Source§

impl<S: Scalar> TensorSemiringCore<Standard<S>> for CpuBackend

Source§

type Plan = CpuPlan<S>

Backend-specific plan type.
Source§

type Context = CpuContext

Backend-specific execution context.
Source§

fn plan( ctx: &mut CpuContext, desc: &SemiringCoreDescriptor, shapes: &[&[usize]], ) -> Result<CpuPlan<S>>

Plan a semiring-core operation.
Source§

fn execute( ctx: &mut CpuContext, plan: &CpuPlan<S>, alpha: S, inputs: &[&Tensor<S>], beta: S, output: &mut Tensor<S>, ) -> Result<()>

Execute a semiring-core operation.
Source§

impl<S: Scalar> TensorSemiringFastPath<Standard<S>> for CpuBackend

Source§

type Plan = CpuPlan<S>

Backend-specific plan type.
Source§

type Context = CpuContext

Backend-specific execution context.
Source§

fn plan( ctx: &mut CpuContext, desc: &SemiringFastPathDescriptor, shapes: &[&[usize]], ) -> Result<CpuPlan<S>>

Plan an optional semiring fast path.
Source§

fn execute( ctx: &mut CpuContext, plan: &CpuPlan<S>, alpha: S, inputs: &[&Tensor<S>], beta: S, output: &mut Tensor<S>, ) -> Result<()>

Execute an optional semiring fast path.
Source§

fn has_fast_path(desc: SemiringFastPathDescriptor) -> bool

Query whether the optional path is available.
Source§

impl<S: Scalar + PartialOrd + 'static> TensorSortPrims<Standard<S>> for CpuBackend

Source§

type Plan = CpuSortPlan

Backend-specific execution plan.
Source§

type Context = CpuContext

Backend execution context.
Source§

fn plan( _ctx: &mut Self::Context, desc: &SortPrimsDescriptor, shapes: &[&[usize]], ) -> Result<Self::Plan>

Plan a sort operation for the given input shape. Read more
Source§

fn execute( _ctx: &mut Self::Context, plan: &Self::Plan, input: &Tensor<S>, values_out: &mut Tensor<S>, indices_out: &mut Tensor<i64>, ) -> Result<()>

Execute a previously planned sort operation. Read more
Source§

fn has_sort_support(_desc: &SortPrimsDescriptor) -> bool

Report whether the backend advertises support for the given descriptor.

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
§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

§

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

§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

§

impl<T> MaybeSend for T

§

impl<T> MaybeSendSync for T

§

impl<T> MaybeSync for T