Skip to main content

CpuEngine

Struct CpuEngine 

Source
pub struct CpuEngine { /* private fields */ }
Expand description

A caller-held CPU execution engine.

The engine owns one threadteam::Pool (or none for CpuEngine::serial, and for a caller-built pool of one worker, which it releases at construction) and the workspace operations write: the buffer pool that recycles outputs, the contraction scratch, and a handle to a CpuPlanCache. It implements tenferro_tensor::Engine, so every operation takes it as &mut.

§Examples

use tenferro_cpu::CpuEngine;
use tenferro_tensor::{Tensor, TensorElementwise, TensorRead};

let mut engine = CpuEngine::serial();
let a = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0])?;
let b = Tensor::from_vec_col_major(vec![2], vec![3.0_f64, 4.0])?;
let c = engine.add_read(TensorRead::from_tensor(&a), TensorRead::from_tensor(&b))?;
assert_eq!(c.as_slice::<f64>()?, &[4.0, 6.0]);

Implementations§

Source§

impl CpuEngine

Source

pub fn with_lanes<R: Send>( &mut self, shares: &[usize], pools: &mut [BufferPool], f: impl Fn(usize, &mut dyn Engine) -> R + Sync, ) -> Result<Vec<R>>

Run f once per lane, concurrently, each lane an engine over its own share of this engine’s thread budget and its own caller-owned buffer pool.

A lane is one concurrent slice of the engine: shares[i] threads of the thread budget (the shares must be non-zero and sum to at most CpuEngine::num_threads) and the pool pools[i]. f(i, lane) runs on lane i and receives the lane as &mut dyn Engine; results come back in lane order. The split uses the engine’s threadteam fork only, so lanes never oversubscribe the budget and never touch another pool.

The caller owns the pools and should keep them across calls: a lane draws every output, workspace and gather buffer from its pool, so reusing the same pool is what makes repeated calls allocation-free in steady state. A pool is never shared between lanes.

Only the linalg factorizations svd, svdvals, qr, eigh, eigvalsh and eigvals run in a lane (through the ordinary tenferro-linalg grammar, for example view.svd(lane)); every other operation on a lane engine returns tenferro_tensor::Error::Unsupported. A negative-stride input is gathered once into a buffer from the lane’s pool; the steady-state zero-allocation property is only promised for inputs without negative strides.

§Errors

Returns crate::Error::Validation when shares and pools differ in length, a share is zero, or the shares sum to more than the thread budget; no work runs and the engine stays usable. Returns crate::Error::RuntimeState when this engine is broken.

§Panics

A panic in a lane is re-raised after every lane has finished, and the engine becomes broken, exactly as for a panic inside CpuEngine::with_exec.

§Examples
use tenferro_cpu::linalg_interop::BufferPool;
use tenferro_cpu::{CpuEngine, Pool};

let pool = Pool::builder().threads(2).build()?;
let mut engine = CpuEngine::new(pool);
// The caller owns one pool per lane and reuses them across calls.
let mut pools = [BufferPool::new(), BufferPool::new()];
let lane_ids = engine.with_lanes(&[1, 1], &mut pools, |index, _lane| index)?;
assert_eq!(lane_ids, vec![0, 1]);

// An invalid split is a validation error and leaves the engine usable.
assert!(engine.with_lanes(&[2, 2], &mut pools, |index, _lane| index).is_err());
assert_eq!(engine.num_threads(), 2);

A lane engine does not outlive the call: it cannot be returned from the closure or stored in a captured variable.

ⓘ
use tenferro_cpu::linalg_interop::BufferPool;
use tenferro_cpu::CpuEngine;
use tenferro_tensor::Engine;

// `Send` is asserted by hand so that the only remaining error is the lifetime: the lane
// engine is valid for one call of the closure only ("lifetime may not live long enough").
struct Escaped<'a>(&'a mut dyn Engine);
unsafe impl Send for Escaped<'_> {}

let mut engine = CpuEngine::serial();
let mut pools = [BufferPool::new()];
let _ = engine.with_lanes(&[1], &mut pools, |_, lane| Escaped(lane));

The pools are borrowed for the whole call, so a pool cannot be dropped or moved while the lanes run.

ⓘ
use tenferro_cpu::linalg_interop::BufferPool;
use tenferro_cpu::CpuEngine;

let mut engine = CpuEngine::serial();
let mut pools = [BufferPool::new()];
let _ = engine.with_lanes(&[1], &mut pools, |_, _| drop(pools));
Source§

impl CpuEngine

Source

pub fn new(pool: Pool) -> Self

An engine that computes on pool, which it takes over.

Every operation may use all workers of the pool; a caller that wants fewer threads builds a smaller pool. Pool::builder reserves the worker stack the providers need by default.

§Examples
let pool = tenferro_cpu::Pool::builder().threads(4).build()?;
let engine = tenferro_cpu::CpuEngine::new(pool);
assert_eq!(engine.num_threads(), 4);
Source

pub fn serial() -> Self

An engine with no pool: every operation runs on the calling thread.

A serial engine never starts or enters a pool, so it is safe to use from inside any other pool.

§Examples
let engine = tenferro_cpu::CpuEngine::serial();
assert_eq!(engine.num_threads(), 1);
Source

pub fn with_plan_cache(self, plans: CpuPlanCache) -> Self

Use plans as this engine’s plan cache, shared with every other engine that holds a clone of it.

§Examples
use tenferro_cpu::{CpuEngine, CpuPlanCache};

let plans = CpuPlanCache::new();
let engine = CpuEngine::serial().with_plan_cache(plans.clone());
assert!(engine.plan_cache().shares_with(&plans));
Source

pub fn plan_cache(&self) -> &CpuPlanCache

The plan cache this engine reads plans from.

§Examples
let engine = tenferro_cpu::CpuEngine::serial();
assert_eq!(engine.plan_cache().stats().entries, 0);
Source

pub fn with_runtime_engine_id(self, id: EngineId) -> Self

Run prepared programs under a runtime engine id other than the default crate::runtime_engine_id; it must match the id this engine kind was registered under.

§Examples
use tenferro_runtime::EngineId;
let id = EngineId::new("example.cpu.v1")?;
let engine = tenferro_cpu::CpuEngine::serial().with_runtime_engine_id(id.clone());
assert_eq!(tenferro_runtime::ExecutionEngine::target(&engine).engine_id(), &id);
Source

pub fn with_allocation_domain( self, domain: Arc<dyn SharedTensorAllocationDomain>, ) -> Self

Bind outputs and managed inputs to a shared allocation domain.

§Examples
let engine = tenferro_cpu::CpuEngine::serial();
assert!(engine.allocation_domain().is_none());
Source

pub fn allocation_domain(&self) -> Option<AllocationDomainId>

The shared allocation domain this engine is bound to, if any.

§Examples
assert_eq!(tenferro_cpu::CpuEngine::serial().allocation_domain(), None);
Source

pub fn shared_allocation_domain( &self, ) -> Option<&Arc<dyn SharedTensorAllocationDomain>>

The shared allocator this engine is bound to, if any.

§Examples
assert!(tenferro_cpu::CpuEngine::serial().shared_allocation_domain().is_none());
Source

pub fn with_batch_policy(self, policy: CpuBatchPolicy) -> Self

This engine with a different default batch policy.

§Examples
use tenferro_cpu::{CpuBatchPolicy, CpuBatchStrategy, CpuEngine};

let engine = CpuEngine::serial()
    .with_batch_policy(CpuBatchPolicy::new(CpuBatchStrategy::Sequential));
assert_eq!(engine.batch_policy().strategy, CpuBatchStrategy::Sequential);
Source

pub fn set_batch_policy(&mut self, policy: CpuBatchPolicy) -> CpuBatchPolicy

Replace the default batch policy, returning the previous one.

For a one-operation override use crate::with_batch_policy.

§Examples
use tenferro_cpu::{CpuBatchPolicy, CpuBatchStrategy, CpuEngine};

let mut engine = CpuEngine::serial();
let previous = engine.set_batch_policy(CpuBatchPolicy::new(CpuBatchStrategy::Outer));
assert_eq!(previous.strategy, CpuBatchStrategy::Auto);
Source

pub fn batch_policy(&self) -> CpuBatchPolicy

The default batch policy of this engine.

§Examples
use tenferro_cpu::{CpuBatchStrategy, CpuEngine};
assert_eq!(CpuEngine::serial().batch_policy().strategy, CpuBatchStrategy::Auto);
Source

pub fn num_threads(&self) -> usize

The number of workers operations may use: the pool size, or one.

§Examples
assert_eq!(tenferro_cpu::CpuEngine::serial().num_threads(), 1);
Source

pub fn has_team(&self) -> bool

Whether the engine runs its parallel work on a reserved threadteam::Team.

true for an engine built from a pool of two or more workers whose members were reserved. false for CpuEngine::serial, for a one-worker pool, and for a pool whose members could not be reserved within about ten seconds of construction (the engine then runs serially and CpuEngine::num_threads reports one). Benchmarks should assert this after construction.

§Examples
assert!(!tenferro_cpu::CpuEngine::serial().has_team());
let pool = tenferro_cpu::Pool::builder().threads(2).build()?;
assert!(tenferro_cpu::CpuEngine::new(pool).has_team());
Source

pub fn dispatch_costs(&self) -> &DispatchCosts

The dispatch costs the engine’s tokens use: those of its pool, or [threadteam::DispatchCosts::host_default] for CpuEngine::serial.

Use them with CpuEngine::num_threads to decide, before taking a token with CpuEngine::exec, whether an operation would fork and at what width. A token of an engine with a team (CpuEngine::has_team) charges [threadteam::DispatchCosts::cost] of [threadteam::DispatchKind::Team] for a section of two or more participants, so [threadteam::width_for_by] and [threadteam::pays_at] over that cost give the answer its width_for and pays would. A budget of one never forks.

§Examples
use std::num::NonZeroUsize;
use std::time::Duration;
use tenferro_cpu::threadteam::{width_for_by, DispatchKind};

let pool = tenferro_cpu::Pool::builder().threads(2).build()?;
let engine = tenferro_cpu::CpuEngine::new(pool);
let budget = NonZeroUsize::new(engine.num_threads()).unwrap();
let cost = |width| engine.dispatch_costs().cost(DispatchKind::Team, width);

// A nanosecond of work stays serial; a second of work uses the budget.
assert_eq!(width_for_by(Duration::from_nanos(1), 1, budget, cost).get(), 1);
assert_eq!(
    width_for_by(Duration::from_secs(1), 1, budget, cost).get(),
    engine.num_threads(),
);
Source

pub fn is_broken(&self) -> bool

Whether an earlier operation broke this engine (see CpuEngineError::Broken).

§Examples
assert!(!tenferro_cpu::CpuEngine::serial().is_broken());
Source

pub fn exec(&mut self) -> Result<Exec<'_>>

The provider execution bundle for this engine: a placement token over every worker of its pool, its workspace and its batch policy.

A downstream kernel that calls a provider (cpueinsum, tcontract, tlinalg) directly passes this bundle by &mut, so it uses the same threads, budget and batch policy as tenferro. The bundle is not Clone: it is the engine’s whole thread budget for that one call, and the provider splits it. Getting it applies the same checks as an operation.

§Errors

Returns crate::Error::RuntimeState with a CpuEngineError source when the engine is broken.

§Examples
let mut engine = tenferro_cpu::CpuEngine::serial();
let exec = engine.exec()?;
assert_eq!(exec.budget(), 1);
Source

pub fn with_exec<R>(&mut self, op: impl FnOnce(&mut Exec<'_>) -> R) -> Result<R>

Run op on the engine’s provider bundle, keeping the engine’s guarantees.

op receives the same bundle an operation mints (a placement token over every worker of the pool, the workspace and the batch policy; see CpuEngine::exec) and runs on the calling thread. Unlike CpuEngine::exec, the call is an engine operation: a panic inside op marks the engine broken, and contraction scratch retained above CpuEngine::buffer_pool_limit_bytes is released when op returns.

The bundle is borrowed for the call only, and the engine stays mutably borrowed while op runs, so neither can be stored or re-entered from inside op; the compiler rejects both:

ⓘ
let mut engine = tenferro_cpu::CpuEngine::serial();
let engine_ref = &mut engine;
engine_ref.with_exec(|_| engine_ref.with_exec(|exec| exec.budget()))?;
ⓘ
let mut engine = tenferro_cpu::CpuEngine::serial();
let mut kept = None;
engine.with_exec(|exec| kept = Some(exec))?;
§Errors

Returns crate::Error::RuntimeState with a CpuEngineError::Broken source, without calling op, when an earlier operation panicked.

§Panics

Resumes a panic raised by op after marking the engine broken.

§Examples
let mut engine = tenferro_cpu::CpuEngine::serial();
let budget = engine.with_exec(|exec| exec.budget())?;
assert_eq!(budget, 1);

A panic inside op breaks the engine, and a broken engine refuses later calls with an error:

use tenferro_cpu::{CpuEngine, CpuEngineError};

let mut engine = CpuEngine::serial();
let unwind = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
    engine.with_exec(|_| panic!("a failing block"))
}));
assert!(unwind.is_err());
assert!(engine.is_broken());

let refused = engine.with_exec(|exec| exec.budget()).unwrap_err();
let source = std::error::Error::source(&refused).and_then(|s| s.downcast_ref());
assert_eq!(source, Some(&CpuEngineError::Broken));
Source

pub fn with_guard<R>( &mut self, op: impl FnOnce(SerialCtx<'_>) -> R, ) -> Result<R>

Run op on the calling thread with the engine’s guarantees, but without taking a placement token: the guarded entry of CpuEngine::with_exec at width one.

op receives a SerialCtx with the engine’s workspace and batch policy. It is not a provider bundle: it carries no token, so nothing in it can fork, and getting it reserves none of the pool’s workers. Apart from the token, the call is the same engine operation as CpuEngine::with_exec: a broken engine is refused, a panic inside op marks the engine broken (buffers op had taken from the buffer pool are not returned to it, since a broken engine runs nothing again), and contraction scratch retained above CpuEngine::buffer_pool_limit_bytes is released when op returns or unwinds.

The context is borrowed for the call only, and the engine stays mutably borrowed while op runs, so neither can be stored or re-entered from inside op; the compiler rejects both:

ⓘ
let mut engine = tenferro_cpu::CpuEngine::serial();
let engine_ref = &mut engine;
engine_ref.with_guard(|_| engine_ref.with_guard(|ctx| ctx.batch_policy()))?;
ⓘ
let mut engine = tenferro_cpu::CpuEngine::serial();
let mut kept = None;
engine.with_guard(|ctx| kept = Some(ctx))?;
§Errors

Returns crate::Error::RuntimeState with a CpuEngineError::Broken source, without calling op, when an earlier operation panicked.

§Panics

Resumes a panic raised by op after marking the engine broken.

§Examples
use tenferro_cpu::{CpuBatchPolicy, CpuBatchStrategy, CpuEngine};

let mut engine = CpuEngine::new(tenferro_cpu::Pool::builder().threads(2).build()?)
    .with_batch_policy(CpuBatchPolicy::new(CpuBatchStrategy::Outer));
let strategy = engine.with_guard(|ctx| ctx.batch_policy().strategy)?;
assert_eq!(strategy, CpuBatchStrategy::Outer);

A panic inside op breaks the engine, and a broken engine refuses later calls with an error:

use tenferro_cpu::{CpuEngine, CpuEngineError};

let mut engine = CpuEngine::serial();
let unwind = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
    engine.with_guard(|_| panic!("a failing serial phase"))
}));
assert!(unwind.is_err());
assert!(engine.is_broken());

let refused = engine.with_guard(|_| ()).unwrap_err();
let source = std::error::Error::source(&refused).and_then(|s| s.downcast_ref());
assert_eq!(source, Some(&CpuEngineError::Broken));
Source

pub fn buffer_pool_len(&self) -> usize

Number of retained buffers in the engine’s buffer pool.

§Examples
assert_eq!(tenferro_cpu::CpuEngine::serial().buffer_pool_len(), 0);
Source

pub fn buffer_pool_stats(&self) -> BufferPoolStats

Retained-buffer statistics of the engine’s buffer pool.

§Examples
assert_eq!(tenferro_cpu::CpuEngine::serial().buffer_pool_stats().buffers, 0);
Source

pub fn buffer_pool_cache_stats(&self) -> CacheStats

The buffer pool as cache statistics (entries and retained bytes).

§Examples
assert_eq!(tenferro_cpu::CpuEngine::serial().buffer_pool_cache_stats().entries, 0);
Source

pub fn buffer_pool_limit_bytes(&self) -> usize

The retention limit of recycled buffers, in retained capacity bytes.

§Examples
let mut engine = tenferro_cpu::CpuEngine::serial();
engine.set_buffer_pool_limit_bytes(0);
assert_eq!(engine.buffer_pool_limit_bytes(), 0);
Source

pub fn set_buffer_pool_limit_bytes( &mut self, max_retained_capacity_bytes: usize, )

Bound the bytes of recycled buffers and contraction scratch retained between operations; zero disables retention.

Destinations larger than the retention limit cannot be recycled, so repeated calls allocate again and may pay first-touch costs. The default is 100 MiB; raise it when a run keeps producing outputs above that size.

§Examples
let mut engine = tenferro_cpu::CpuEngine::serial();
engine.set_buffer_pool_limit_bytes(1 << 20);
assert_eq!(engine.buffer_pool_limit_bytes(), 1 << 20);
Source

pub fn reset_buffer_pool(&mut self)

Drop every retained buffer and contraction scratch.

§Examples
let mut engine = tenferro_cpu::CpuEngine::serial();
engine.reset_buffer_pool();
assert_eq!(engine.buffer_pool_len(), 0);

Trait Implementations§

Source§

impl Debug for CpuEngine

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Engine for CpuEngine

Source§

fn gather_read( &mut self, operand: TensorRead<'_>, start_indices: TensorRead<'_>, config: &GatherConfig, ) -> Result<Tensor>

Gather with both operands taken as reads. Read more
Source§

fn vdot_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, ) -> Result<Tensor>

Compute the all-axis conjugating dot product without transferring either input. Read more
Source§

fn norm_squared_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>

Compute the all-axis sum of squared magnitudes without taking a square root. Read more
Source§

fn fused_activation_read( &mut self, op: ActivationOp, input: TensorRead<'_>, ) -> Result<Option<Tensor>>

Compute a fused activation in one pass, or decline with Ok(None). Read more
Source§

fn softmax_read( &mut self, input: TensorRead<'_>, axis: usize, ) -> Result<Option<Tensor>>

Fused real-float softmax along axis. Read more
Source§

fn axpby_read_into_accum( &mut self, alpha: ContractionScalar, x: TensorRead<'_>, beta: ContractionScalar, y: TensorWrite<'_>, ) -> Result<()>

Apply y <- alpha * x + beta * y in one pass into caller-owned storage. Read more
Source§

fn native_engine(&mut self) -> Option<NativeSessionRef<'_>>

Return this engine’s backend-leaf native capability, if it has one. Read more
Source§

impl ExecutionEngine for CpuEngine

Source§

fn target(&self) -> EngineTarget

Immutable description used by crate::Runtime::prepare.
Source§

fn take_extension_caches(&mut self) -> ExtensionCacheStore

Move this engine’s extension caches out for the duration of one run. Read more
Source§

fn restore_extension_caches(&mut self, caches: ExtensionCacheStore)

Return the extension caches taken by Self::take_extension_caches.
Source§

fn mark_broken(&mut self)

Record that an extension callback panicked while the runtime had lent this engine’s extension caches to it. Read more
Source§

fn as_any_mut(&mut self) -> &mut dyn Any

Typed access for prepared operations that execute against the concrete engine type instead of the Engine operations.
Source§

fn event_domain_driver(&self) -> Arc<dyn EventDomainDriver> ⓘ

The driver that opens this engine’s event-domain runs. Read more
Source§

fn retire_run(&mut self, run: Box<dyn EventDomainRun>) -> Result<(), Error>

Take ownership of an event-domain run whose launches may still be running. Read more
Source§

fn synchronize(&mut self) -> Result<(), Error>

Block until the work this engine queued has completed. Read more
Source§

impl SessionCachedDot for CpuEngine

Source§

fn dot_general_read_into_accum_cached( &mut self, cache_slot: Option<usize>, lhs: TensorRead<'_>, rhs: TensorRead<'_>, config: &DotGeneralConfig, accumulation: DotGeneralAccumulation, out: TensorWrite<'_>, ) -> Result<()>

Apply session-cached scaled dot-general accumulation into output. Read more
Source§

impl TensorAnalytic for CpuEngine

Source§

fn exp_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>

Examples Read more
Source§

fn log_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>

Examples Read more
Source§

fn sin_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>

Examples Read more
Source§

fn cos_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>

Examples Read more
Source§

fn tanh_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>

Examples Read more
Source§

fn sqrt_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>

Examples Read more
Source§

fn rsqrt_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>

Examples Read more
Source§

fn pow_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, ) -> Result<Tensor>

Examples Read more
Source§

fn expm1_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>

Examples Read more
Source§

fn log1p_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>

Examples Read more
Source§

fn erf_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>

Elementwise error function erf(x) = 2/sqrt(pi) * integral_0^x exp(-t^2) dt. Read more
Source§

impl TensorBackendCapability for CpuEngine

Source§

fn backend_id(&self) -> BackendId

Source§

fn capabilities(&self) -> &'static [OperationCapability]

Source§

fn capability(&self, query: CapabilityQuery) -> Option<OperationCapability>

Look up one operation/dtype capability for this backend. Read more
Source§

impl TensorBuffer for CpuEngine

Source§

fn reclaim_buffer(&mut self, tensor: Tensor)

Source§

impl TensorDeviceTransfer for CpuEngine

Source§

fn download_to_host(&mut self, tensor: TensorRead<'_>) -> Result<Tensor>

Explicitly copy a provider-owned read target into host storage. Read more
Source§

fn upload_host_tensor(&mut self, tensor: TensorRead<'_>) -> Result<Tensor>

Explicitly copy a host read target into provider storage. Read more
Source§

impl TensorDot for CpuEngine

The engine’s GEMM entries.

These run on the engine’s pool within its budget: threadteam owns every CPU thread a call starts, and no external library sizes itself from a process-wide thread setting. A caller that wants independent GEMMs on lanes of one context forks the bundle that CpuEngine::with_exec lends and runs a cpueinsum plan per lane. See the “Lanes” section of docs/guides/cpu-execution.md.

§Examples

use tenferro_cpu::CpuEngine;
use tenferro_tensor::{DotGeneralConfig, Tensor, TensorDot, TensorRead};

let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 3.0, 2.0, 4.0])?;
let identity = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 0.0, 0.0, 1.0])?;
let config = DotGeneralConfig {
    lhs_contracting_dims: [1].as_slice().into(),
    rhs_contracting_dims: [0].as_slice().into(),
    lhs_batch_dims: [].as_slice().into(),
    rhs_batch_dims: [].as_slice().into(),
};
let mut engine = CpuEngine::serial();
let product = engine.dot_general_read(
    TensorRead::from_tensor(&a),
    TensorRead::from_tensor(&identity),
    &config,
)?;
assert_eq!(product.as_slice::<f64>()?, &[1.0, 3.0, 2.0, 4.0]);
Source§

fn dot_general_read_into( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, config: &DotGeneralConfig, out: TensorWrite<'_>, ) -> Result<()>

Overwrite caller-provided output with dot-general from read inputs. Read more
Source§

fn dot_general_read_into_accum( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, config: &DotGeneralConfig, accumulation: DotGeneralAccumulation, out: TensorWrite<'_>, ) -> Result<()>

Apply scaled dot-general accumulation into caller-provided output. Read more
Source§

impl TensorElementwise for CpuEngine

Source§

fn elementwise_read_into( &mut self, op: ElementwiseReadOp, inputs: &[TensorRead<'_>], out: TensorWrite<'_>, ) -> Result<()>

Execute an elementwise operation into caller-owned storage. Read more
Source§

fn add_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, ) -> Result<Tensor>

Elementwise addition accepting either owned tensors or borrowed views. Read more
Source§

fn sub_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, ) -> Result<Tensor>

Elementwise subtraction accepting either owned tensors or borrowed views. Read more
Source§

fn mul_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, ) -> Result<Tensor>

Examples Read more
Source§

fn neg_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>

Examples Read more
Source§

fn conj_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>

Examples Read more
Source§

fn div_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, ) -> Result<Tensor>

Examples Read more
Source§

fn rem(&mut self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor>

Elementwise remainder. Read more
Source§

fn rem_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, ) -> Result<Tensor>

Elementwise remainder accepting owned tensors or borrowed views. Read more
Source§

fn abs_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>

Examples Read more
Source§

fn sign_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>

Examples Read more
Source§

fn maximum_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, ) -> Result<Tensor>

Examples Read more
Source§

fn minimum_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, ) -> Result<Tensor>

Examples Read more
Source§

fn compare_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, dir: &CompareDir, ) -> Result<Tensor>

Errors Read more
Source§

fn select_read( &mut self, pred: TensorRead<'_>, on_true: TensorRead<'_>, on_false: TensorRead<'_>, ) -> Result<Tensor>

Errors Read more
Source§

fn clamp_read( &mut self, input: TensorRead<'_>, lower: TensorRead<'_>, upper: TensorRead<'_>, ) -> Result<Tensor>

Errors Read more
Source§

fn add_into( &mut self, lhs: &Tensor, rhs: &Tensor, out: TensorWrite<'_>, ) -> Result<(), Error>

Overwrite caller-provided output with elementwise addition. Read more
Source§

fn add_read_into( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, out: TensorWrite<'_>, ) -> Result<(), Error>

Overwrite caller-provided output with elementwise addition from reads. Read more
Source§

fn sub_into( &mut self, lhs: &Tensor, rhs: &Tensor, out: TensorWrite<'_>, ) -> Result<(), Error>

Overwrite caller-provided output with elementwise subtraction. Read more
Source§

fn sub_read_into( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, out: TensorWrite<'_>, ) -> Result<(), Error>

Overwrite caller-provided output with elementwise subtraction from reads. Read more
Source§

fn mul_into( &mut self, lhs: &Tensor, rhs: &Tensor, out: TensorWrite<'_>, ) -> Result<(), Error>

Overwrite caller-provided output with elementwise multiplication. Read more
Source§

fn mul_read_into( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, out: TensorWrite<'_>, ) -> Result<(), Error>

Overwrite caller-provided output with elementwise multiplication from reads. Read more
Source§

fn neg_into( &mut self, input: &Tensor, out: TensorWrite<'_>, ) -> Result<(), Error>

Overwrite caller-provided output with elementwise negation. Read more
Source§

fn neg_read_into( &mut self, input: TensorRead<'_>, out: TensorWrite<'_>, ) -> Result<(), Error>

Overwrite caller-provided output with elementwise negation from a read. Read more
Source§

fn conj_into( &mut self, input: &Tensor, out: TensorWrite<'_>, ) -> Result<(), Error>

Overwrite caller-provided output with elementwise conjugation. Read more
Source§

fn conj_read_into( &mut self, input: TensorRead<'_>, out: TensorWrite<'_>, ) -> Result<(), Error>

Overwrite caller-provided output with elementwise conjugation from a read. Read more
Source§

fn div_into( &mut self, lhs: &Tensor, rhs: &Tensor, out: TensorWrite<'_>, ) -> Result<(), Error>

Overwrite caller-provided output with elementwise division. Read more
Source§

fn div_read_into( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, out: TensorWrite<'_>, ) -> Result<(), Error>

Overwrite caller-provided output with elementwise division from reads. Read more
Source§

impl TensorFusion for CpuEngine

Source§

impl TensorIndexing for CpuEngine

Source§

fn gather( &mut self, operand: &Tensor, start_indices: &Tensor, config: &GatherConfig, ) -> Result<Tensor>

Errors Read more
Source§

fn scatter( &mut self, operand: &Tensor, indices: &Tensor, updates: &Tensor, config: &ScatterConfig, ) -> Result<Tensor>

Errors Read more
Source§

fn dynamic_update_slice_read( &mut self, operand: TensorRead<'_>, update: TensorRead<'_>, starts: TensorRead<'_>, ) -> Result<Tensor>

Dynamic-update-slice with every input taken as a read. Read more
Source§

fn scatter_read( &mut self, operand: TensorRead<'_>, indices: TensorRead<'_>, updates: TensorRead<'_>, config: &ScatterConfig, ) -> Result<Tensor>

Scatter with every input taken as a read. Read more
Source§

fn slice(&mut self, input: &Tensor, config: &SliceConfig) -> Result<Tensor>

Errors Read more
Source§

fn slice_read( &mut self, input: TensorRead<'_>, config: &SliceConfig, ) -> Result<Tensor>

Slice with the input taken as a read. Read more
Source§

fn dynamic_slice_read( &mut self, input: TensorRead<'_>, starts: TensorRead<'_>, slice_sizes: &[usize], ) -> Result<Tensor>

Dynamic slice with every input taken as a read. Read more
Source§

fn dynamic_slice( &mut self, input: &Tensor, starts: &Tensor, slice_sizes: &[usize], ) -> Result<Tensor>

Errors Read more
Source§

fn dynamic_update_slice( &mut self, operand: &Tensor, update: &Tensor, starts: &Tensor, ) -> Result<Tensor>

Errors Read more
Source§

fn pad(&mut self, input: &Tensor, config: &PadConfig) -> Result<Tensor>

Errors Read more
Source§

fn pad_read( &mut self, input: TensorRead<'_>, config: &PadConfig, ) -> Result<Tensor>

Pad with the input taken as a read. Read more
Source§

fn concatenate(&mut self, inputs: &[&Tensor], axis: usize) -> Result<Tensor>

Errors Read more
Source§

fn concatenate_read( &mut self, inputs: &[TensorRead<'_>], axis: usize, ) -> Result<Tensor>

Concatenate with every input taken as a read. Read more
Source§

fn reverse(&mut self, input: &Tensor, axes: &[usize]) -> Result<Tensor>

Errors Read more
Source§

fn reverse_read( &mut self, input: TensorRead<'_>, axes: &[usize], ) -> Result<Tensor>

Reverse with the input taken as a read. Read more
Source§

impl TensorReduction for CpuEngine

Source§

fn reduce_sum_read( &mut self, input: TensorRead<'_>, axes: &[usize], ) -> Result<Tensor>

Sum elements across axes from an owned tensor or borrowed view. Read more
Source§

fn reduce_prod_read( &mut self, input: TensorRead<'_>, axes: &[usize], ) -> Result<Tensor>

Multiply elements across axes from an owned tensor or borrowed view. Read more
Source§

fn reduce_max_read( &mut self, input: TensorRead<'_>, axes: &[usize], ) -> Result<Tensor>

Take maximum values across axes from an owned tensor or borrowed view. Read more
Source§

fn reduce_min_read( &mut self, input: TensorRead<'_>, axes: &[usize], ) -> Result<Tensor>

Take minimum values across axes from an owned tensor or borrowed view. Read more
Source§

impl TensorStructural for CpuEngine

Source§

fn to_contiguous_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>

Materialize an owned tensor or borrowed view into fresh compact storage. Read more
Source§

fn copy_read_into( &mut self, src: TensorRead<'_>, dst: TensorWrite<'_>, ) -> Result<()>

Overwrite caller-provided storage from a readable tensor or view. Read more
Source§

fn transpose_read( &mut self, input: TensorRead<'_>, perm: &[usize], ) -> Result<Tensor>

Examples Read more
Source§

fn reshape_read( &mut self, input: TensorRead<'_>, shape: &[usize], ) -> Result<Tensor>

Examples Read more
Source§

fn broadcast_in_dim_read( &mut self, input: TensorRead<'_>, shape: &[usize], dims: &[usize], ) -> Result<Tensor>

Errors Read more
Source§

fn tril_read(&mut self, input: TensorRead<'_>, k: i64) -> Result<Tensor>

Lower-triangular mask with the input taken as a read. Read more
Source§

fn triu_read(&mut self, input: TensorRead<'_>, k: i64) -> Result<Tensor>

Upper-triangular mask with the input taken as a read. Read more
Source§

fn extract_diagonal_read( &mut self, input: TensorRead<'_>, axis_a: usize, axis_b: usize, ) -> Result<Tensor>

Extract the diagonal with the input taken as a read. Read more
Source§

fn embed_diagonal_read( &mut self, input: TensorRead<'_>, axis_a: usize, axis_b: usize, ) -> Result<Tensor>

Embed the input as a diagonal with the input taken as a read. Read more
Source§

fn cast(&mut self, input: &Tensor, to: DType) -> Result<Tensor>

Cast a tensor to another dtype using explicit dtype projection. Read more
Source§

fn cast_read(&mut self, input: TensorRead<'_>, to: DType) -> Result<Tensor>

Cast the read’s logical elements to another dtype using explicit dtype projection. Read more
Source§

fn extract_diagonal( &mut self, input: &Tensor, axis_a: usize, axis_b: usize, ) -> Result<Tensor>

Errors Read more
Source§

fn embed_diagonal( &mut self, input: &Tensor, axis_a: usize, axis_b: usize, ) -> Result<Tensor>

Errors Read more
Source§

fn tril(&mut self, input: &Tensor, k: i64) -> Result<Tensor>

Errors Read more
Source§

fn triu(&mut self, input: &Tensor, k: i64) -> Result<Tensor>

Errors Read more
Source§

fn convert(&mut self, input: &Tensor, to: DType) -> Result<Tensor, Error>

Convert a tensor to another dtype using checked dtype conversion. Read more
Source§

fn convert_read( &mut self, input: TensorRead<'_>, to: DType, ) -> Result<Tensor, Error>

Convert the read’s logical elements using checked dtype conversion. Read more
Source§

impl<T, R> TensorViewCanonicalization<T, R> for CpuEngine

Typed view canonicalization runs on the engine.

Source§

fn to_contiguous( &mut self, view: &TypedTensorView<'_, T, R>, ) -> Result<TypedTensor<T, R>>

Errors Read more
Source§

fn copy_into( &mut self, src: &TypedTensorView<'_, T, R>, dst: &mut TypedTensorViewMut<'_, T, R>, ) -> Result<()>

Errors Read more

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

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
§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.