Skip to main content

Crate tenferro_cpu

Crate tenferro_cpu 

Source
Expand description

CPU backend, kernels, provider selection, and CPU resource pools.

§Examples

use tenferro_cpu::CpuBackend;
use tenferro_tensor::{BackendSessionHost, Tensor, TensorRead};

let mut backend = CpuBackend::new();
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 = backend
    .with_backend_session(|session| {
        session.add_read(TensorRead::from_tensor(&a), TensorRead::from_tensor(&b))
    })??;
assert_eq!(c.as_slice::<f64>().unwrap(), &[4.0, 6.0]);

The deleted one-shot spellings do not compile on the owner or on a session. Each fixture below fails for that reason and nothing else.

ⓘ
use tenferro_cpu::CpuBackend;
use tenferro_tensor::Tensor;

let mut backend = CpuBackend::new();
let a = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0]).unwrap();
let b = Tensor::from_vec_col_major(vec![2], vec![3.0_f64, 4.0]).unwrap();
let _ = backend.add(&a, &b);
ⓘ
use tenferro_cpu::CpuBackend;
use tenferro_tensor::Tensor;

let mut backend = CpuBackend::new();
let a = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0]).unwrap();
let b = Tensor::from_vec_col_major(vec![2], vec![3.0_f64, 4.0]).unwrap();
let _ = backend.mul(&a, &b);
ⓘ
use tenferro_cpu::CpuBackend;
use tenferro_tensor::Tensor;

let mut backend = CpuBackend::new();
let a = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0]).unwrap();
let _ = backend.exp(&a);
ⓘ
use tenferro_cpu::CpuBackend;
use tenferro_tensor::Tensor;

let mut backend = CpuBackend::new();
let a = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0]).unwrap();
let _ = backend.reduce_sum(&a, &[0]);
ⓘ
use tenferro_cpu::CpuBackend;
use tenferro_tensor::Tensor;

let mut backend = CpuBackend::new();
let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0]).unwrap();
let _ = backend.transpose(&a, &[1, 0]);
ⓘ
use tenferro_cpu::CpuBackend;
use tenferro_tensor::{DotGeneralConfig, Tensor};

let mut backend = CpuBackend::new();
let a = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0]).unwrap();
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 _ = backend.dot_general(&a, &a, &config);

The owner no longer implements the cache-aware contraction entry, so an owner-level BackendCachedDot bound does not hold either:

ⓘ
use tenferro_cpu::CpuBackend;
use tenferro_tensor::BackendCachedDot;

fn requires_cached_dot<B: BackendCachedDot>(_backend: &mut B) {}

let mut backend = CpuBackend::new();
requires_cached_dot(&mut backend);

Re-exports§

pub use affinity::available_parallelism;
pub use affinity::process_cpu_affinity;
pub use affinity::process_cpu_affinity_count;
pub use affinity::CpuAffinityError;
pub use backend::CpuBackend;
pub use backend::CpuBackendError;
pub use backend::CpuBackendKind;
pub use backend::CpuExecutionInfo;
pub use backend::CpuExecutionMode;
pub use backend::CpuRuntimeIdentity;
pub use backend::ExternalCpuDomainRegistryError;
pub use context::CpuContext;
pub use context::CpuContextError;
pub use context::DEFAULT_WORKER_STACK_BYTES;
pub use provider::CpuExecutionContext;
pub use provider::ParallelMode;

Modules§

affinity
backend
context
provider
Object-safe CPU contraction provider contracts.

Macros§

same_variant_pair
Dispatch a same-variant pair of tensors to a typed kernel.
same_variant_unary
Dispatch a single tensor to a typed kernel and erase its result.

Structs§

AddOp
Ordinary CPU entry points that take a caller-provided destination and the caller’s own arithmetic instead of the typed pool. Addition.
BufferPoolStats
Snapshot of typed host buffers retained by a BufferPool.
CpuAffinityInput
CPU affinity metadata for one logical operation input.
CpuAffinitySelection
Deterministic CPU affinity selection returned by the pure resolver.
CpuBatchPolicy
A batch strategy together with the thresholds Auto uses.
CpuBatchThresholds
Thresholds that CpuBatchStrategy::Auto applies.
CpuDomainExecutorCapabilities
Immutable construction-time capabilities of a CPU domain executor.
CpuId
An operating-system logical CPU identifier.
CpuNode
One usable OS NUMA node and its process-allowed logical CPUs.
CpuProviderBundle
Immutable direct provider slots installed on a CPU backend.
CpuProviderBundleBuildError
Error returned when a custom CPU provider bundle omits mandatory slots.
CpuProviderBundleBuilder
Construction-time builder for immutable CPU provider slots.
CpuProviderExecutionCapabilities
Immutable execution capabilities declared by one CPU provider.
CpuSet
A sorted, deduplicated, non-empty set of logical CPUs.
CpuTopology
Process-visible CPU topology used for execution placement.
ExternalCpuDomain
Caller-supplied descriptor for one externally managed CPU resource domain.
IndexedPlanCacheLimits
Limits for the CPU indexed-plan cache.
MulOp
Ordinary CPU entry points that take a caller-provided destination and the caller’s own arithmetic instead of the typed pool. Multiplication.
NumaNodeId
An operating-system NUMA node identifier.
RayonCpuDomainExecutor
Adapter that executes CPU-domain jobs on one caller-owned Rayon pool.
SubOp
Ordinary CPU entry points that take a caller-provided destination and the caller’s own arithmetic instead of the typed pool. Subtraction.

Enums§

CpuAdmissionMode
Admission contract for one CPU resource domain.
CpuAffinityInputError
Failure to derive logical input bytes for CPU affinity resolution.
CpuAffinityPolicy
Policy used to select a CPU execution domain from input affinity metadata.
CpuAffinityResolutionError
Failure to resolve CPU affinity from input metadata.
CpuAffinitySelectionReason
Why the CPU affinity resolver selected a domain.
CpuBatchStrategy
How the items of one batched operation are executed.
CpuDomainExecutorError
Failure at the CPU executor admission or scheduling boundary.
CpuDomainOwnership
Ownership class of a CPU resource domain.
CpuEngineConstructionError
Typed failure raised while constructing a CPU execution engine.
CpuExecutorAffinity
Affinity claim made by a CPU domain executor.
CpuExecutorReentrancy
Re-entry capability of one CPU domain executor.
CpuExecutorShutdown
Ownership of CPU executor shutdown.
CpuInnerParallelism
Inner parallel-region support offered by a CPU domain executor.
CpuPlacement
Requested CPU execution placement.
CpuPlacementControl
Per-call control over where a CPU provider executes.
CpuPlacementError
Failure to resolve a CPU placement for the selected public provider kind.
CpuProviderBundleInstallError
Failure to install a CPU provider bundle for the backend’s domains.
CpuProviderDomainError
Typed incompatibility between a CPU provider and a selected CPU domain.
CpuProviderSlot
Provider slot that failed construction-time domain validation.
CpuSetError
Failure to construct a non-empty CPU set.
CpuThreadCountControl
Per-call control over the maximum number of threads used by a CPU provider.
CpuThreadExecution
What CPU execution the current thread is inside.
CpuTopologyError
Failure to canonicalize discovered NUMA topology.
ExternalCpuDomainError
Typed failure to construct an externally managed CPU resource domain.
GeneralContractionPolicy
Policy applied when the configured general-contraction provider reports a typed capability miss.
ResolvedCpuPlacement
Concrete CPU placement resolved for a managed domain or declared by an external domain.

Traits§

BinaryScalarOp
Ordinary CPU entry points that take a caller-provided destination and the caller’s own arithmetic instead of the typed pool. A binary operation between two scalars of the same type.
CpuDomainExecutor
Object-safe synchronous executor for one CPU resource domain.
FaerParallelismExt
Invoke a direct faer operation with the parallelism selected by a CPU session.
ScopedCpuJob
One borrowed job installed synchronously into a CPU domain executor.
ScopedCpuJobs
Synchronously submitted indexed jobs for engine-owned outer scheduling.

Functions§

cpu_capabilities
Return the CPU backend operation capability descriptor table.
current_cpu_execution
Report what CPU execution the current thread is inside, including a managed Rayon worker running a session or scope callback.
discover_cpu_topology
Discover the process-visible CPU and NUMA topology.
resolve_cpu_affinity
Resolve a CPU execution domain from input affinity metadata.
resolve_cpu_affinity_with_override
Resolve CPU affinity with an optional operation-local explicit override.
runtime_engine_id
Return the canonical CPU runtime engine identifier.
runtime_engine_registration
Build a runtime engine registration for a CpuBackend.
runtime_engine_registration_with_id
Build a runtime engine registration for a CpuBackend with a caller-selected engine identifier.
runtime_hardware_class
Return the canonical CPU runtime hardware class.
scalar_binary_into
Ordinary CPU entry points that take a caller-provided destination and the caller’s own arithmetic instead of the typed pool. Apply a named binary operation elementwise into a caller-owned destination.
scalar_fold
Ordinary CPU entry points that take a caller-provided destination and the caller’s own arithmetic instead of the typed pool. Fold every element of a caller-owned tensor with a named associative operation, starting from init.
with_batch_policy
Run f on session with policy as the effective batch policy.