Struct CpuEngine
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 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§
§impl CpuEngine
impl CpuEngine
pub fn new(pool: Pool) -> CpuEngine
pub fn new(pool: Pool) -> CpuEngine
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);pub fn serial() -> CpuEngine
pub fn serial() -> CpuEngine
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);pub fn with_plan_cache(self, plans: CpuPlanCache) -> CpuEngine
pub fn with_plan_cache(self, plans: CpuPlanCache) -> CpuEngine
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));pub fn plan_cache(&self) -> &CpuPlanCache
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);pub fn with_runtime_engine_id(self, id: EngineId) -> CpuEngine
pub fn with_runtime_engine_id(self, id: EngineId) -> CpuEngine
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);pub fn with_allocation_domain(
self,
domain: Arc<dyn SharedTensorAllocationDomain>,
) -> CpuEngine
pub fn with_allocation_domain( self, domain: Arc<dyn SharedTensorAllocationDomain>, ) -> CpuEngine
Bind outputs and managed inputs to a shared allocation domain.
§Examples
let engine = tenferro_cpu::CpuEngine::serial();
assert!(engine.allocation_domain().is_none());pub fn allocation_domain(&self) -> Option<AllocationDomainId>
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);The shared allocator this engine is bound to, if any.
§Examples
assert!(tenferro_cpu::CpuEngine::serial().shared_allocation_domain().is_none());pub fn with_batch_policy(self, policy: BatchPolicy) -> CpuEngine
pub fn with_batch_policy(self, policy: BatchPolicy) -> CpuEngine
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);pub fn set_batch_policy(&mut self, policy: BatchPolicy) -> BatchPolicy
pub fn set_batch_policy(&mut self, policy: BatchPolicy) -> BatchPolicy
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);pub fn batch_policy(&self) -> BatchPolicy
pub fn batch_policy(&self) -> BatchPolicy
The default batch policy of this engine.
§Examples
use tenferro_cpu::{CpuBatchStrategy, CpuEngine};
assert_eq!(CpuEngine::serial().batch_policy().strategy, CpuBatchStrategy::Auto);pub fn num_threads(&self) -> usize
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);pub fn has_team(&self) -> bool
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());pub fn is_broken(&self) -> bool
pub fn is_broken(&self) -> bool
Whether an earlier operation broke this engine (see
[CpuEngineError::Broken]).
§Examples
assert!(!tenferro_cpu::CpuEngine::serial().is_broken());pub fn exec(&mut self) -> Result<Exec<'_>, Error>
pub fn exec(&mut self) -> Result<Exec<'_>, Error>
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);pub fn with_exec<R>(
&mut self,
op: impl FnOnce(&mut Exec<'_>) -> R,
) -> Result<R, Error>
pub fn with_exec<R>( &mut self, op: impl FnOnce(&mut Exec<'_>) -> R, ) -> Result<R, Error>
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));pub fn buffer_pool_len(&self) -> usize
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);pub fn buffer_pool_stats(&self) -> BufferPoolStats
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);pub fn buffer_pool_cache_stats(&self) -> CacheStats
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);pub fn buffer_pool_limit_bytes(&self) -> usize
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);pub fn set_buffer_pool_limit_bytes(
&mut self,
max_retained_capacity_bytes: usize,
)
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);pub fn reset_buffer_pool(&mut self)
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§
§impl Engine for CpuEngine
impl Engine for CpuEngine
§fn gather_read(
&mut self,
operand: TensorRead<'_>,
start_indices: TensorRead<'_>,
config: &GatherConfig,
) -> Result<Tensor, Error>
fn gather_read( &mut self, operand: TensorRead<'_>, start_indices: TensorRead<'_>, config: &GatherConfig, ) -> Result<Tensor, Error>
§fn vdot_read(
&mut self,
lhs: TensorRead<'_>,
rhs: TensorRead<'_>,
) -> Result<Tensor, Error>
fn vdot_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, ) -> Result<Tensor, Error>
§fn norm_squared_read(&mut self, input: TensorRead<'_>) -> Result<Tensor, Error>
fn norm_squared_read(&mut self, input: TensorRead<'_>) -> Result<Tensor, Error>
§fn fused_activation_read(
&mut self,
op: ActivationOp,
input: TensorRead<'_>,
) -> Result<Option<Tensor>, Error>
fn fused_activation_read( &mut self, op: ActivationOp, input: TensorRead<'_>, ) -> Result<Option<Tensor>, Error>
Ok(None). Read more§fn softmax_read(
&mut self,
input: TensorRead<'_>,
axis: usize,
) -> Result<Option<Tensor>, Error>
fn softmax_read( &mut self, input: TensorRead<'_>, axis: usize, ) -> Result<Option<Tensor>, Error>
axis. Read more§fn axpby_read_into_accum(
&mut self,
alpha: ContractionScalar,
x: TensorRead<'_>,
beta: ContractionScalar,
y: TensorWrite<'_>,
) -> Result<(), Error>
fn axpby_read_into_accum( &mut self, alpha: ContractionScalar, x: TensorRead<'_>, beta: ContractionScalar, y: TensorWrite<'_>, ) -> Result<(), Error>
y <- alpha * x + beta * y in one pass into caller-owned storage. Read more§fn native_engine(&mut self) -> Option<NativeSessionRef<'_>>
fn native_engine(&mut self) -> Option<NativeSessionRef<'_>>
§impl ExecutionEngine for CpuEngine
impl ExecutionEngine for CpuEngine
§fn take_extension_caches(&mut self) -> ExtensionCacheStore
fn take_extension_caches(&mut self) -> ExtensionCacheStore
§fn restore_extension_caches(&mut self, caches: ExtensionCacheStore)
fn restore_extension_caches(&mut self, caches: ExtensionCacheStore)
Self::take_extension_caches].§fn mark_broken(&mut self)
fn mark_broken(&mut self)
§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Engine] operations.§fn event_domain_driver(&self) -> Arc<dyn EventDomainDriver> ⓘ
fn event_domain_driver(&self) -> Arc<dyn EventDomainDriver> ⓘ
§fn retire_run(&mut self, run: Box<dyn EventDomainRun>) -> Result<(), Error>
fn retire_run(&mut self, run: Box<dyn EventDomainRun>) -> Result<(), Error>
§fn synchronize(&mut self) -> Result<(), Error>
fn synchronize(&mut self) -> Result<(), Error>
Source§impl From<CpuEngine> for CpuBackend
impl From<CpuEngine> for CpuBackend
§impl LinalgBackend for CpuEngine
impl LinalgBackend for CpuEngine
§fn cholesky(&mut self, input: &Tensor) -> Result<Tensor, Error>
fn cholesky(&mut self, input: &Tensor) -> Result<Tensor, Error>
§fn triangular_solve(
&mut self,
a: &Tensor,
b: &Tensor,
left_side: bool,
lower: bool,
transpose_a: bool,
unit_diagonal: bool,
) -> Result<Tensor, Error>
fn triangular_solve( &mut self, a: &Tensor, b: &Tensor, left_side: bool, lower: bool, transpose_a: bool, unit_diagonal: bool, ) -> Result<Tensor, Error>
§fn triangular_solve_read(
&mut self,
a: TensorRead<'_>,
b: TensorRead<'_>,
left_side: bool,
lower: bool,
transpose_a: bool,
unit_diagonal: bool,
) -> Result<Tensor, Error>
fn triangular_solve_read( &mut self, a: TensorRead<'_>, b: TensorRead<'_>, left_side: bool, lower: bool, transpose_a: bool, unit_diagonal: bool, ) -> Result<Tensor, Error>
§fn lu(&mut self, input: &Tensor) -> Result<Vec<Tensor>, Error>
fn lu(&mut self, input: &Tensor) -> Result<Vec<Tensor>, Error>
(P, L, U, parity). Read more§fn full_piv_lu(&mut self, input: &Tensor) -> Result<Vec<Tensor>, Error>
fn full_piv_lu(&mut self, input: &Tensor) -> Result<Vec<Tensor>, Error>
(P, L, U, Q, parity). Read more§fn full_piv_lu_solve(
&mut self,
a: &Tensor,
b: &Tensor,
transpose_a: bool,
) -> Result<Tensor, Error>
fn full_piv_lu_solve( &mut self, a: &Tensor, b: &Tensor, transpose_a: bool, ) -> Result<Tensor, Error>
§fn svd(&mut self, input: &Tensor) -> Result<Vec<Tensor>, Error>
fn svd(&mut self, input: &Tensor) -> Result<Vec<Tensor>, Error>
(U, S, Vt). Read more§fn svd_full(&mut self, input: &Tensor) -> Result<Vec<Tensor>, Error>
fn svd_full(&mut self, input: &Tensor) -> Result<Vec<Tensor>, Error>
(U, S, Vt) with U shaped
m x m and Vt shaped n x n, so the trailing Vt rows span the
input’s right nullspace. Read more§fn svd_full_read(&mut self, input: TensorRead<'_>) -> Result<Vec<Tensor>, Error>
fn svd_full_read(&mut self, input: TensorRead<'_>) -> Result<Vec<Tensor>, Error>
(U, S, Vt) from a tensor read target. Read more§fn svd_read(&mut self, input: TensorRead<'_>) -> Result<Vec<Tensor>, Error>
fn svd_read(&mut self, input: TensorRead<'_>) -> Result<Vec<Tensor>, Error>
§fn qr(&mut self, input: &Tensor) -> Result<Vec<Tensor>, Error>
fn qr(&mut self, input: &Tensor) -> Result<Vec<Tensor>, Error>
(Q, R). Read more§fn qr_read(&mut self, input: TensorRead<'_>) -> Result<Vec<Tensor>, Error>
fn qr_read(&mut self, input: TensorRead<'_>) -> Result<Vec<Tensor>, Error>
(Q, R) from a tensor read target. Read more§fn eigh(&mut self, input: &Tensor) -> Result<Vec<Tensor>, Error>
fn eigh(&mut self, input: &Tensor) -> Result<Vec<Tensor>, Error>
(values, vectors). Read more§fn eigh_read(&mut self, input: TensorRead<'_>) -> Result<Vec<Tensor>, Error>
fn eigh_read(&mut self, input: TensorRead<'_>) -> Result<Vec<Tensor>, Error>
§fn cholesky_read(&mut self, input: TensorRead<'_>) -> Result<Tensor, Error>
fn cholesky_read(&mut self, input: TensorRead<'_>) -> Result<Tensor, Error>
§fn lu_read(&mut self, input: TensorRead<'_>) -> Result<Vec<Tensor>, Error>
fn lu_read(&mut self, input: TensorRead<'_>) -> Result<Vec<Tensor>, Error>
§fn full_piv_lu_read(
&mut self,
input: TensorRead<'_>,
) -> Result<Vec<Tensor>, Error>
fn full_piv_lu_read( &mut self, input: TensorRead<'_>, ) -> Result<Vec<Tensor>, Error>
§fn eig_read(&mut self, input: TensorRead<'_>) -> Result<Vec<Tensor>, Error>
fn eig_read(&mut self, input: TensorRead<'_>) -> Result<Vec<Tensor>, Error>
§fn eig(&mut self, input: &Tensor) -> Result<Vec<Tensor>, Error>
fn eig(&mut self, input: &Tensor) -> Result<Vec<Tensor>, Error>
(values, vectors).
Eigenvectors come back with unit 2-norm columns, whichever provider computed them;
a column the provider left non-finite is reported as a numerical failure instead
of being returned as NaN (#2148). Read more§fn solve(&mut self, a: &Tensor, b: &Tensor) -> Result<Tensor, Error>
fn solve(&mut self, a: &Tensor, b: &Tensor) -> Result<Tensor, Error>
§fn solve_read(
&mut self,
a: TensorRead<'_>,
b: TensorRead<'_>,
) -> Result<Tensor, Error>
fn solve_read( &mut self, a: TensorRead<'_>, b: TensorRead<'_>, ) -> Result<Tensor, Error>
§fn solve_read_into(
&mut self,
a: TensorRead<'_>,
b: TensorRead<'_>,
out: TensorWrite<'_>,
) -> Result<(), Error>
fn solve_read_into( &mut self, a: TensorRead<'_>, b: TensorRead<'_>, out: TensorWrite<'_>, ) -> Result<(), Error>
§fn svd_with_options(
&mut self,
input: &Tensor,
options: SvdOptions,
) -> Result<Vec<Tensor>, Error>
fn svd_with_options( &mut self, input: &Tensor, options: SvdOptions, ) -> Result<Vec<Tensor>, Error>
(U, S, Vt) with explicit options. Read more§fn svd_with_options_read(
&mut self,
input: TensorRead<'_>,
options: SvdOptions,
) -> Result<Vec<Tensor>, Error>
fn svd_with_options_read( &mut self, input: TensorRead<'_>, options: SvdOptions, ) -> Result<Vec<Tensor>, Error>
(U, S, Vt) from a tensor read target with
explicit options. Read more§fn qr_with_options(
&mut self,
input: &Tensor,
options: QrOptions,
) -> Result<Vec<Tensor>, Error>
fn qr_with_options( &mut self, input: &Tensor, options: QrOptions, ) -> Result<Vec<Tensor>, Error>
(Q, R) with explicit options. Read more§fn qr_with_options_read(
&mut self,
input: TensorRead<'_>,
options: QrOptions,
) -> Result<Vec<Tensor>, Error>
fn qr_with_options_read( &mut self, input: TensorRead<'_>, options: QrOptions, ) -> Result<Vec<Tensor>, Error>
(Q, R) from a tensor read target with options. Read more§fn eigh_with_options(
&mut self,
input: &Tensor,
options: EighOptions,
) -> Result<Vec<Tensor>, Error>
fn eigh_with_options( &mut self, input: &Tensor, options: EighOptions, ) -> Result<Vec<Tensor>, Error>
§fn eigh_with_options_read(
&mut self,
input: TensorRead<'_>,
options: EighOptions,
) -> Result<Vec<Tensor>, Error>
fn eigh_with_options_read( &mut self, input: TensorRead<'_>, options: EighOptions, ) -> Result<Vec<Tensor>, Error>
(values, vectors) from a tensor read
target with explicit options. Read more§impl SessionCachedDot for CpuEngine
impl SessionCachedDot for CpuEngine
§fn dot_general_read_into_accum_cached(
&mut self,
cache_slot: Option<usize>,
lhs: TensorRead<'_>,
rhs: TensorRead<'_>,
config: &DotGeneralConfig,
accumulation: DotGeneralAccumulation,
out: TensorWrite<'_>,
) -> Result<(), Error>
fn dot_general_read_into_accum_cached( &mut self, cache_slot: Option<usize>, lhs: TensorRead<'_>, rhs: TensorRead<'_>, config: &DotGeneralConfig, accumulation: DotGeneralAccumulation, out: TensorWrite<'_>, ) -> Result<(), Error>
§impl TensorAnalytic for CpuEngine
impl TensorAnalytic for CpuEngine
§fn rsqrt_read(&mut self, input: TensorRead<'_>) -> Result<Tensor, Error>
fn rsqrt_read(&mut self, input: TensorRead<'_>) -> Result<Tensor, Error>
§fn pow_read(
&mut self,
lhs: TensorRead<'_>,
rhs: TensorRead<'_>,
) -> Result<Tensor, Error>
fn pow_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, ) -> Result<Tensor, Error>
§fn expm1_read(&mut self, input: TensorRead<'_>) -> Result<Tensor, Error>
fn expm1_read(&mut self, input: TensorRead<'_>) -> Result<Tensor, Error>
§fn log1p_read(&mut self, input: TensorRead<'_>) -> Result<Tensor, Error>
fn log1p_read(&mut self, input: TensorRead<'_>) -> Result<Tensor, Error>
§impl TensorBackendCapability for CpuEngine
impl TensorBackendCapability for CpuEngine
fn backend_id(&self) -> BackendId
fn capabilities(&self) -> &'static [OperationCapability]
§fn capability(&self, query: CapabilityQuery) -> Option<OperationCapability>
fn capability(&self, query: CapabilityQuery) -> Option<OperationCapability>
§fn require_capability(
&self,
query: CapabilityQuery,
axis: CapabilityAxis,
) -> Result<OperationCapability, Error>
fn require_capability( &self, query: CapabilityQuery, axis: CapabilityAxis, ) -> Result<OperationCapability, Error>
§impl TensorBuffer for CpuEngine
impl TensorBuffer for CpuEngine
fn reclaim_buffer(&mut self, tensor: Tensor)
§impl TensorDeviceTransfer for CpuEngine
impl TensorDeviceTransfer for CpuEngine
§fn download_to_host(&mut self, tensor: TensorRead<'_>) -> Result<Tensor, Error>
fn download_to_host(&mut self, tensor: TensorRead<'_>) -> Result<Tensor, Error>
§fn upload_host_tensor(
&mut self,
tensor: TensorRead<'_>,
) -> Result<Tensor, Error>
fn upload_host_tensor( &mut self, tensor: TensorRead<'_>, ) -> Result<Tensor, Error>
§impl TensorDot for CpuEngine
The engine’s GEMM entries, and on a blas build the only GEMM entries.
impl TensorDot for CpuEngine
The engine’s GEMM entries, and on a blas build the only GEMM entries.
On the native provider these run on the engine’s pool within its budget. 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; that per-context entry exists
only on the native provider.
On the blas provider a call takes the whole engine and the vendor library’s own threads:
the context budget is not honoured by that provider, because the vendor step ignores the
placement token and sizes itself from the library’s process-wide thread setting
(OPENBLAS_NUM_THREADS, MKL_NUM_THREADS, VECLIB_MAXIMUM_THREADS). Lanes must not call
into the vendor provider concurrently unless the linked library is known to tolerate it; two
lanes asking for different widths cannot both be honoured by one global setting. tenferro does
not offer a wrapper that sets that global per lane to simulate per-lane widths, because it would
hide who owns the setting instead of answering it. See the “Lanes and the vendor provider”
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]);§fn dot_general_read_into(
&mut self,
lhs: TensorRead<'_>,
rhs: TensorRead<'_>,
config: &DotGeneralConfig,
out: TensorWrite<'_>,
) -> Result<(), Error>
fn dot_general_read_into( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, config: &DotGeneralConfig, out: TensorWrite<'_>, ) -> Result<(), Error>
§fn dot_general_read_into_accum(
&mut self,
lhs: TensorRead<'_>,
rhs: TensorRead<'_>,
config: &DotGeneralConfig,
accumulation: DotGeneralAccumulation,
out: TensorWrite<'_>,
) -> Result<(), Error>
fn dot_general_read_into_accum( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, config: &DotGeneralConfig, accumulation: DotGeneralAccumulation, out: TensorWrite<'_>, ) -> Result<(), Error>
§impl TensorElementwise for CpuEngine
impl TensorElementwise for CpuEngine
§fn elementwise_read_into(
&mut self,
op: ElementwiseReadOp,
inputs: &[TensorRead<'_>],
out: TensorWrite<'_>,
) -> Result<(), Error>
fn elementwise_read_into( &mut self, op: ElementwiseReadOp, inputs: &[TensorRead<'_>], out: TensorWrite<'_>, ) -> Result<(), Error>
§fn add_read(
&mut self,
lhs: TensorRead<'_>,
rhs: TensorRead<'_>,
) -> Result<Tensor, Error>
fn add_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, ) -> Result<Tensor, Error>
§fn sub_read(
&mut self,
lhs: TensorRead<'_>,
rhs: TensorRead<'_>,
) -> Result<Tensor, Error>
fn sub_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, ) -> Result<Tensor, Error>
§fn mul_read(
&mut self,
lhs: TensorRead<'_>,
rhs: TensorRead<'_>,
) -> Result<Tensor, Error>
fn mul_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, ) -> Result<Tensor, Error>
§fn div_read(
&mut self,
lhs: TensorRead<'_>,
rhs: TensorRead<'_>,
) -> Result<Tensor, Error>
fn div_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, ) -> Result<Tensor, Error>
§fn rem(&mut self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor, Error>
fn rem(&mut self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor, Error>
§fn rem_read(
&mut self,
lhs: TensorRead<'_>,
rhs: TensorRead<'_>,
) -> Result<Tensor, Error>
fn rem_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, ) -> Result<Tensor, Error>
§fn maximum_read(
&mut self,
lhs: TensorRead<'_>,
rhs: TensorRead<'_>,
) -> Result<Tensor, Error>
fn maximum_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, ) -> Result<Tensor, Error>
§fn minimum_read(
&mut self,
lhs: TensorRead<'_>,
rhs: TensorRead<'_>,
) -> Result<Tensor, Error>
fn minimum_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, ) -> Result<Tensor, Error>
§fn compare_read(
&mut self,
lhs: TensorRead<'_>,
rhs: TensorRead<'_>,
dir: &CompareDir,
) -> Result<Tensor, Error>
fn compare_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, dir: &CompareDir, ) -> Result<Tensor, Error>
§fn select_read(
&mut self,
pred: TensorRead<'_>,
on_true: TensorRead<'_>,
on_false: TensorRead<'_>,
) -> Result<Tensor, Error>
fn select_read( &mut self, pred: TensorRead<'_>, on_true: TensorRead<'_>, on_false: TensorRead<'_>, ) -> Result<Tensor, Error>
§fn clamp_read(
&mut self,
input: TensorRead<'_>,
lower: TensorRead<'_>,
upper: TensorRead<'_>,
) -> Result<Tensor, Error>
fn clamp_read( &mut self, input: TensorRead<'_>, lower: TensorRead<'_>, upper: TensorRead<'_>, ) -> Result<Tensor, Error>
§fn add_into(
&mut self,
lhs: &Tensor,
rhs: &Tensor,
out: TensorWrite<'_>,
) -> Result<(), Error>
fn add_into( &mut self, lhs: &Tensor, rhs: &Tensor, out: TensorWrite<'_>, ) -> Result<(), Error>
§fn add_read_into(
&mut self,
lhs: TensorRead<'_>,
rhs: TensorRead<'_>,
out: TensorWrite<'_>,
) -> Result<(), Error>
fn add_read_into( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, out: TensorWrite<'_>, ) -> Result<(), Error>
§fn sub_into(
&mut self,
lhs: &Tensor,
rhs: &Tensor,
out: TensorWrite<'_>,
) -> Result<(), Error>
fn sub_into( &mut self, lhs: &Tensor, rhs: &Tensor, out: TensorWrite<'_>, ) -> Result<(), Error>
§fn sub_read_into(
&mut self,
lhs: TensorRead<'_>,
rhs: TensorRead<'_>,
out: TensorWrite<'_>,
) -> Result<(), Error>
fn sub_read_into( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, out: TensorWrite<'_>, ) -> Result<(), Error>
§fn mul_into(
&mut self,
lhs: &Tensor,
rhs: &Tensor,
out: TensorWrite<'_>,
) -> Result<(), Error>
fn mul_into( &mut self, lhs: &Tensor, rhs: &Tensor, out: TensorWrite<'_>, ) -> Result<(), Error>
§fn mul_read_into(
&mut self,
lhs: TensorRead<'_>,
rhs: TensorRead<'_>,
out: TensorWrite<'_>,
) -> Result<(), Error>
fn mul_read_into( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, out: TensorWrite<'_>, ) -> Result<(), Error>
§fn neg_into(
&mut self,
input: &Tensor,
out: TensorWrite<'_>,
) -> Result<(), Error>
fn neg_into( &mut self, input: &Tensor, out: TensorWrite<'_>, ) -> Result<(), Error>
§fn neg_read_into(
&mut self,
input: TensorRead<'_>,
out: TensorWrite<'_>,
) -> Result<(), Error>
fn neg_read_into( &mut self, input: TensorRead<'_>, out: TensorWrite<'_>, ) -> Result<(), Error>
§fn conj_into(
&mut self,
input: &Tensor,
out: TensorWrite<'_>,
) -> Result<(), Error>
fn conj_into( &mut self, input: &Tensor, out: TensorWrite<'_>, ) -> Result<(), Error>
§fn conj_read_into(
&mut self,
input: TensorRead<'_>,
out: TensorWrite<'_>,
) -> Result<(), Error>
fn conj_read_into( &mut self, input: TensorRead<'_>, out: TensorWrite<'_>, ) -> Result<(), Error>
§fn div_into(
&mut self,
lhs: &Tensor,
rhs: &Tensor,
out: TensorWrite<'_>,
) -> Result<(), Error>
fn div_into( &mut self, lhs: &Tensor, rhs: &Tensor, out: TensorWrite<'_>, ) -> Result<(), Error>
§fn div_read_into(
&mut self,
lhs: TensorRead<'_>,
rhs: TensorRead<'_>,
out: TensorWrite<'_>,
) -> Result<(), Error>
fn div_read_into( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, out: TensorWrite<'_>, ) -> Result<(), Error>
impl TensorFusion for CpuEngine
§impl TensorIndexing for CpuEngine
impl TensorIndexing for CpuEngine
§fn gather(
&mut self,
operand: &Tensor,
start_indices: &Tensor,
config: &GatherConfig,
) -> Result<Tensor, Error>
fn gather( &mut self, operand: &Tensor, start_indices: &Tensor, config: &GatherConfig, ) -> Result<Tensor, Error>
§fn scatter(
&mut self,
operand: &Tensor,
indices: &Tensor,
updates: &Tensor,
config: &ScatterConfig,
) -> Result<Tensor, Error>
fn scatter( &mut self, operand: &Tensor, indices: &Tensor, updates: &Tensor, config: &ScatterConfig, ) -> Result<Tensor, Error>
§fn dynamic_update_slice_read(
&mut self,
operand: TensorRead<'_>,
update: TensorRead<'_>,
starts: TensorRead<'_>,
) -> Result<Tensor, Error>
fn dynamic_update_slice_read( &mut self, operand: TensorRead<'_>, update: TensorRead<'_>, starts: TensorRead<'_>, ) -> Result<Tensor, Error>
§fn scatter_read(
&mut self,
operand: TensorRead<'_>,
indices: TensorRead<'_>,
updates: TensorRead<'_>,
config: &ScatterConfig,
) -> Result<Tensor, Error>
fn scatter_read( &mut self, operand: TensorRead<'_>, indices: TensorRead<'_>, updates: TensorRead<'_>, config: &ScatterConfig, ) -> Result<Tensor, Error>
§fn slice(
&mut self,
input: &Tensor,
config: &SliceConfig,
) -> Result<Tensor, Error>
fn slice( &mut self, input: &Tensor, config: &SliceConfig, ) -> Result<Tensor, Error>
§fn slice_read(
&mut self,
input: TensorRead<'_>,
config: &SliceConfig,
) -> Result<Tensor, Error>
fn slice_read( &mut self, input: TensorRead<'_>, config: &SliceConfig, ) -> Result<Tensor, Error>
§fn dynamic_slice_read(
&mut self,
input: TensorRead<'_>,
starts: TensorRead<'_>,
slice_sizes: &[usize],
) -> Result<Tensor, Error>
fn dynamic_slice_read( &mut self, input: TensorRead<'_>, starts: TensorRead<'_>, slice_sizes: &[usize], ) -> Result<Tensor, Error>
§fn dynamic_slice(
&mut self,
input: &Tensor,
starts: &Tensor,
slice_sizes: &[usize],
) -> Result<Tensor, Error>
fn dynamic_slice( &mut self, input: &Tensor, starts: &Tensor, slice_sizes: &[usize], ) -> Result<Tensor, Error>
§fn dynamic_update_slice(
&mut self,
operand: &Tensor,
update: &Tensor,
starts: &Tensor,
) -> Result<Tensor, Error>
fn dynamic_update_slice( &mut self, operand: &Tensor, update: &Tensor, starts: &Tensor, ) -> Result<Tensor, Error>
§fn pad_read(
&mut self,
input: TensorRead<'_>,
config: &PadConfig,
) -> Result<Tensor, Error>
fn pad_read( &mut self, input: TensorRead<'_>, config: &PadConfig, ) -> Result<Tensor, Error>
§fn concatenate(
&mut self,
inputs: &[&Tensor],
axis: usize,
) -> Result<Tensor, Error>
fn concatenate( &mut self, inputs: &[&Tensor], axis: usize, ) -> Result<Tensor, Error>
§fn concatenate_read(
&mut self,
inputs: &[TensorRead<'_>],
axis: usize,
) -> Result<Tensor, Error>
fn concatenate_read( &mut self, inputs: &[TensorRead<'_>], axis: usize, ) -> Result<Tensor, Error>
§fn reverse_read(
&mut self,
input: TensorRead<'_>,
axes: &[usize],
) -> Result<Tensor, Error>
fn reverse_read( &mut self, input: TensorRead<'_>, axes: &[usize], ) -> Result<Tensor, Error>
§impl TensorReduction for CpuEngine
impl TensorReduction for CpuEngine
§fn reduce_sum_read(
&mut self,
input: TensorRead<'_>,
axes: &[usize],
) -> Result<Tensor, Error>
fn reduce_sum_read( &mut self, input: TensorRead<'_>, axes: &[usize], ) -> Result<Tensor, Error>
§fn reduce_prod_read(
&mut self,
input: TensorRead<'_>,
axes: &[usize],
) -> Result<Tensor, Error>
fn reduce_prod_read( &mut self, input: TensorRead<'_>, axes: &[usize], ) -> Result<Tensor, Error>
§fn reduce_max_read(
&mut self,
input: TensorRead<'_>,
axes: &[usize],
) -> Result<Tensor, Error>
fn reduce_max_read( &mut self, input: TensorRead<'_>, axes: &[usize], ) -> Result<Tensor, Error>
§fn reduce_min_read(
&mut self,
input: TensorRead<'_>,
axes: &[usize],
) -> Result<Tensor, Error>
fn reduce_min_read( &mut self, input: TensorRead<'_>, axes: &[usize], ) -> Result<Tensor, Error>
§impl TensorStructural for CpuEngine
impl TensorStructural for CpuEngine
§fn to_contiguous_read(&mut self, input: TensorRead<'_>) -> Result<Tensor, Error>
fn to_contiguous_read(&mut self, input: TensorRead<'_>) -> Result<Tensor, Error>
§fn copy_read_into(
&mut self,
src: TensorRead<'_>,
dst: TensorWrite<'_>,
) -> Result<(), Error>
fn copy_read_into( &mut self, src: TensorRead<'_>, dst: TensorWrite<'_>, ) -> Result<(), Error>
§fn transpose_read(
&mut self,
input: TensorRead<'_>,
perm: &[usize],
) -> Result<Tensor, Error>
fn transpose_read( &mut self, input: TensorRead<'_>, perm: &[usize], ) -> Result<Tensor, Error>
§fn reshape_read(
&mut self,
input: TensorRead<'_>,
shape: &[usize],
) -> Result<Tensor, Error>
fn reshape_read( &mut self, input: TensorRead<'_>, shape: &[usize], ) -> Result<Tensor, Error>
§fn broadcast_in_dim_read(
&mut self,
input: TensorRead<'_>,
shape: &[usize],
dims: &[usize],
) -> Result<Tensor, Error>
fn broadcast_in_dim_read( &mut self, input: TensorRead<'_>, shape: &[usize], dims: &[usize], ) -> Result<Tensor, Error>
§fn tril_read(&mut self, input: TensorRead<'_>, k: i64) -> Result<Tensor, Error>
fn tril_read(&mut self, input: TensorRead<'_>, k: i64) -> Result<Tensor, Error>
§fn triu_read(&mut self, input: TensorRead<'_>, k: i64) -> Result<Tensor, Error>
fn triu_read(&mut self, input: TensorRead<'_>, k: i64) -> Result<Tensor, Error>
§fn extract_diagonal_read(
&mut self,
input: TensorRead<'_>,
axis_a: usize,
axis_b: usize,
) -> Result<Tensor, Error>
fn extract_diagonal_read( &mut self, input: TensorRead<'_>, axis_a: usize, axis_b: usize, ) -> Result<Tensor, Error>
§fn embed_diagonal_read(
&mut self,
input: TensorRead<'_>,
axis_a: usize,
axis_b: usize,
) -> Result<Tensor, Error>
fn embed_diagonal_read( &mut self, input: TensorRead<'_>, axis_a: usize, axis_b: usize, ) -> Result<Tensor, Error>
§fn cast(&mut self, input: &Tensor, to: DType) -> Result<Tensor, Error>
fn cast(&mut self, input: &Tensor, to: DType) -> Result<Tensor, Error>
§fn extract_diagonal(
&mut self,
input: &Tensor,
axis_a: usize,
axis_b: usize,
) -> Result<Tensor, Error>
fn extract_diagonal( &mut self, input: &Tensor, axis_a: usize, axis_b: usize, ) -> Result<Tensor, Error>
Auto Trait Implementations§
impl !Freeze for CpuEngine
impl !RefUnwindSafe for CpuEngine
impl !UnwindSafe for CpuEngine
impl Send for CpuEngine
impl Sync for CpuEngine
impl Unpin for CpuEngine
impl UnsafeUnpin for CpuEngine
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T, U> Imply<T> for U
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