pub struct CpuBackend { /* private fields */ }Expand description
Implementations§
Source§impl CpuBackend
impl CpuBackend
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a CPU backend using the environment-driven CPU context.
§Examples
use tenferro_cpu::CpuBackend;
let backend = CpuBackend::new();Sourcepub fn with_kind(kind: CpuBackendKind) -> Result<Self>
pub fn with_kind(kind: CpuBackendKind) -> Result<Self>
Create a CPU backend using the selected compiled provider.
§Examples
use tenferro_cpu::{CpuBackend, CpuBackendKind};
let backend = CpuBackend::with_kind(CpuBackendKind::default_compiled()).unwrap();
assert_eq!(backend.kind(), CpuBackendKind::default_compiled());Sourcepub fn try_new() -> Result<Self>
pub fn try_new() -> Result<Self>
Try to create a CPU backend using RAYON_NUM_THREADS.
§Examples
use tenferro_cpu::CpuBackend;
let backend = CpuBackend::try_new()
.unwrap_or_else(|_| CpuBackend::with_threads(1).unwrap());
let _ = backend.num_threads();Sourcepub fn from_context(ctx: Arc<CpuContext>) -> Self
pub fn from_context(ctx: Arc<CpuContext>) -> Self
Create a CPU backend from an existing context.
§Examples
use std::sync::Arc;
use tenferro_cpu::{CpuBackend, CpuContext};
let ctx = Arc::new(CpuContext::with_threads(2).unwrap());
let backend = CpuBackend::from_context(ctx);
assert_eq!(backend.num_threads(), 2);Sourcepub fn from_context_with_buffer_pool_limit(
ctx: Arc<CpuContext>,
max_retained_capacity_bytes: usize,
) -> Self
pub fn from_context_with_buffer_pool_limit( ctx: Arc<CpuContext>, max_retained_capacity_bytes: usize, ) -> Self
Create a CPU backend from an existing context and buffer-pool retention cap.
The cap is measured in retained vector capacity bytes. A cap of zero disables buffer retention.
§Examples
use std::sync::Arc;
use tenferro_cpu::{CpuBackend, CpuContext};
let ctx = Arc::new(CpuContext::with_threads(1).unwrap());
let backend = CpuBackend::from_context_with_buffer_pool_limit(ctx, 0);
assert_eq!(backend.buffer_pool_limit_bytes(), 0);Sourcepub fn with_threads(num_threads: usize) -> Result<Self>
pub fn with_threads(num_threads: usize) -> Result<Self>
Sourcepub fn with_threads_and_kind(
num_threads: usize,
kind: CpuBackendKind,
) -> Result<Self>
pub fn with_threads_and_kind( num_threads: usize, kind: CpuBackendKind, ) -> Result<Self>
Create a CPU backend with a custom thread count and provider.
§Examples
use tenferro_cpu::{CpuBackend, CpuBackendKind};
let backend = CpuBackend::with_threads_and_kind(
1,
CpuBackendKind::default_compiled(),
)?;
assert_eq!(backend.num_threads(), 1);§Errors
Returns an error when num_threads is zero, Rayon rejects the pool, or
the selected provider is unavailable.
Sourcepub fn kind(&self) -> CpuBackendKind
pub fn kind(&self) -> CpuBackendKind
Return the runtime CPU provider selected by this backend.
§Examples
use tenferro_cpu::{CpuBackend, CpuBackendKind};
let backend = CpuBackend::new();
assert_eq!(backend.kind(), CpuBackendKind::default_compiled());Sourcepub fn num_threads(&self) -> usize
pub fn num_threads(&self) -> usize
Return the number of threads in this backend’s CPU context.
§Examples
use tenferro_cpu::CpuBackend;
let backend = CpuBackend::with_threads(2).unwrap();
assert_eq!(backend.num_threads(), 2);Sourcepub fn buffer_pool_len(&self) -> usize
pub fn buffer_pool_len(&self) -> usize
Number of retained typed host buffers currently held by this backend.
§Examples
use tenferro_cpu::CpuBackend;
let backend = CpuBackend::new();
assert_eq!(backend.buffer_pool_len(), 0);Sourcepub fn buffer_pool_stats(&self) -> BufferPoolStats
pub fn buffer_pool_stats(&self) -> BufferPoolStats
Snapshot reusable typed host buffers currently retained by this backend.
§Examples
use tenferro_cpu::CpuBackend;
let backend = CpuBackend::new();
let stats = backend.buffer_pool_stats();
assert_eq!(stats.buffers, 0);
assert_eq!(stats.capacity_bytes, 0);Sourcepub fn buffer_pool_cache_stats(&self) -> CacheStats
pub fn buffer_pool_cache_stats(&self) -> CacheStats
Return cache-style stats for the CPU buffer pool.
§Examples
use tenferro_cpu::CpuBackend;
let backend = CpuBackend::new();
let stats = backend.buffer_pool_cache_stats();
assert_eq!(stats.entries, 0);
assert_eq!(stats.retained_bytes, 0);Sourcepub fn buffer_pool_limit_bytes(&self) -> usize
pub fn buffer_pool_limit_bytes(&self) -> usize
Current CPU buffer-pool retention limit in bytes.
§Examples
use std::sync::Arc;
use tenferro_cpu::{CpuBackend, CpuContext};
let backend = CpuBackend::from_context_with_buffer_pool_limit(
Arc::new(CpuContext::with_threads(1).unwrap()),
4096,
);
assert_eq!(backend.buffer_pool_limit_bytes(), 4096);Sourcepub 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, )
Update the CPU buffer-pool retention limit in bytes.
Shrinking the limit evicts retained buffers immediately. A limit of zero disables buffer retention.
§Examples
use tenferro_cpu::CpuBackend;
let mut backend = CpuBackend::new();
backend.set_buffer_pool_limit_bytes(0);
assert_eq!(backend.buffer_pool_limit_bytes(), 0);
assert_eq!(backend.buffer_pool_len(), 0);Sourcepub fn reset_buffer_pool(&mut self)
pub fn reset_buffer_pool(&mut self)
Reset reusable typed host buffers currently retained by this backend.
This releases pool-owned vectors to the process allocator. Operating system RSS may not fall immediately because allocators can retain freed pages for future allocations.
§Examples
use tenferro_cpu::CpuBackend;
let mut backend = CpuBackend::new();
backend.reset_buffer_pool();
assert_eq!(backend.buffer_pool_len(), 0);Trait Implementations§
Source§impl BackendSessionHost for CpuBackend
impl BackendSessionHost for CpuBackend
fn with_backend_session<R: Send>( &mut self, f: impl FnOnce(&mut dyn BackendSession) -> R + Send, ) -> R
Source§impl Debug for CpuBackend
impl Debug for CpuBackend
Source§impl Default for CpuBackend
impl Default for CpuBackend
Source§impl TensorAnalytic for CpuBackend
impl TensorAnalytic for CpuBackend
fn exp(&mut self, input: &Tensor) -> Result<Tensor>
fn exp_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>
fn log(&mut self, input: &Tensor) -> Result<Tensor>
fn log_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>
fn sin(&mut self, input: &Tensor) -> Result<Tensor>
fn sin_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>
fn cos(&mut self, input: &Tensor) -> Result<Tensor>
fn cos_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>
fn tanh(&mut self, input: &Tensor) -> Result<Tensor>
fn tanh_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>
fn sqrt(&mut self, input: &Tensor) -> Result<Tensor>
fn sqrt_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>
fn rsqrt(&mut self, input: &Tensor) -> Result<Tensor>
fn rsqrt_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>
fn pow(&mut self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor>
fn pow_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, ) -> Result<Tensor>
fn expm1(&mut self, input: &Tensor) -> Result<Tensor>
fn expm1_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>
fn log1p(&mut self, input: &Tensor) -> Result<Tensor>
fn log1p_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>
Source§impl TensorBuffer for CpuBackend
impl TensorBuffer for CpuBackend
fn reclaim_buffer(&mut self, tensor: Tensor)
Source§impl TensorDeviceTransfer for CpuBackend
impl TensorDeviceTransfer for CpuBackend
Source§impl TensorDot for CpuBackend
impl TensorDot for CpuBackend
fn dot_general( &mut self, lhs: &Tensor, rhs: &Tensor, config: &DotGeneralConfig, ) -> Result<Tensor>
Source§impl TensorElementwise for CpuBackend
impl TensorElementwise for CpuBackend
fn add(&mut self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor>
Source§fn add_read(
&mut self,
lhs: TensorRead<'_>,
rhs: TensorRead<'_>,
) -> Result<Tensor>
fn add_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, ) -> Result<Tensor>
fn mul(&mut self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor>
fn mul_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, ) -> Result<Tensor>
fn neg(&mut self, input: &Tensor) -> Result<Tensor>
fn neg_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>
fn conj(&mut self, input: &Tensor) -> Result<Tensor>
fn conj_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>
fn div(&mut self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor>
fn div_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, ) -> Result<Tensor>
fn abs(&mut self, input: &Tensor) -> Result<Tensor>
fn abs_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>
fn sign(&mut self, input: &Tensor) -> Result<Tensor>
fn sign_read(&mut self, input: TensorRead<'_>) -> Result<Tensor>
fn maximum(&mut self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor>
fn maximum_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, ) -> Result<Tensor>
fn minimum(&mut self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor>
fn minimum_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, ) -> Result<Tensor>
fn compare( &mut self, lhs: &Tensor, rhs: &Tensor, dir: &CompareDir, ) -> Result<Tensor>
fn compare_read( &mut self, lhs: TensorRead<'_>, rhs: TensorRead<'_>, dir: &CompareDir, ) -> Result<Tensor>
fn select( &mut self, pred: &Tensor, on_true: &Tensor, on_false: &Tensor, ) -> Result<Tensor>
fn select_read( &mut self, pred: TensorRead<'_>, on_true: TensorRead<'_>, on_false: TensorRead<'_>, ) -> Result<Tensor>
fn clamp( &mut self, input: &Tensor, lower: &Tensor, upper: &Tensor, ) -> Result<Tensor>
fn clamp_read( &mut self, input: TensorRead<'_>, lower: TensorRead<'_>, upper: TensorRead<'_>, ) -> Result<Tensor>
Source§impl TensorIndexing for CpuBackend
impl TensorIndexing for CpuBackend
fn gather( &mut self, operand: &Tensor, start_indices: &Tensor, config: &GatherConfig, ) -> Result<Tensor>
fn scatter( &mut self, operand: &Tensor, scatter_indices: &Tensor, updates: &Tensor, config: &ScatterConfig, ) -> Result<Tensor>
fn slice(&mut self, input: &Tensor, config: &SliceConfig) -> Result<Tensor>
fn dynamic_slice( &mut self, input: &Tensor, starts: &Tensor, slice_sizes: &[usize], ) -> Result<Tensor>
fn dynamic_update_slice( &mut self, operand: &Tensor, update: &Tensor, starts: &Tensor, ) -> Result<Tensor>
fn pad(&mut self, input: &Tensor, config: &PadConfig) -> Result<Tensor>
fn concatenate(&mut self, inputs: &[&Tensor], axis: usize) -> Result<Tensor>
fn reverse(&mut self, input: &Tensor, axes: &[usize]) -> Result<Tensor>
Source§impl TensorReduction for CpuBackend
impl TensorReduction for CpuBackend
fn reduce_sum(&mut self, input: &Tensor, axes: &[usize]) -> Result<Tensor>
Source§fn reduce_sum_read(
&mut self,
input: TensorRead<'_>,
axes: &[usize],
) -> Result<Tensor>
fn reduce_sum_read( &mut self, input: TensorRead<'_>, axes: &[usize], ) -> Result<Tensor>
fn reduce_prod(&mut self, input: &Tensor, axes: &[usize]) -> Result<Tensor>
Source§fn reduce_prod_read(
&mut self,
input: TensorRead<'_>,
axes: &[usize],
) -> Result<Tensor>
fn reduce_prod_read( &mut self, input: TensorRead<'_>, axes: &[usize], ) -> Result<Tensor>
fn reduce_max(&mut self, input: &Tensor, axes: &[usize]) -> Result<Tensor>
Source§fn reduce_max_read(
&mut self,
input: TensorRead<'_>,
axes: &[usize],
) -> Result<Tensor>
fn reduce_max_read( &mut self, input: TensorRead<'_>, axes: &[usize], ) -> Result<Tensor>
fn reduce_min(&mut self, input: &Tensor, axes: &[usize]) -> Result<Tensor>
Source§fn reduce_min_read(
&mut self,
input: TensorRead<'_>,
axes: &[usize],
) -> Result<Tensor>
fn reduce_min_read( &mut self, input: TensorRead<'_>, axes: &[usize], ) -> Result<Tensor>
Source§impl TensorStructural for CpuBackend
impl TensorStructural for CpuBackend
fn transpose(&mut self, input: &Tensor, perm: &[usize]) -> Result<Tensor>
fn transpose_read( &mut self, input: TensorRead<'_>, perm: &[usize], ) -> Result<Tensor>
fn reshape(&mut self, input: &Tensor, shape: &[usize]) -> Result<Tensor>
fn reshape_read( &mut self, input: TensorRead<'_>, shape: &[usize], ) -> Result<Tensor>
fn broadcast_in_dim( &mut self, input: &Tensor, shape: &[usize], dims: &[usize], ) -> Result<Tensor>
fn broadcast_in_dim_read( &mut self, input: TensorRead<'_>, shape: &[usize], dims: &[usize], ) -> Result<Tensor>
Source§fn cast(&mut self, input: &Tensor, to: DType) -> Result<Tensor>
fn cast(&mut self, input: &Tensor, to: DType) -> Result<Tensor>
fn extract_diagonal( &mut self, input: &Tensor, axis_a: usize, axis_b: usize, ) -> Result<Tensor>
fn embed_diagonal( &mut self, input: &Tensor, axis_a: usize, axis_b: usize, ) -> Result<Tensor>
fn tril(&mut self, input: &Tensor, k: i64) -> Result<Tensor>
fn triu(&mut self, input: &Tensor, k: i64) -> Result<Tensor>
Source§impl<T, R> TensorViewCanonicalization<T, R> for CpuBackendwhere
T: Clone + 'static,
R: TensorRank,
impl<T, R> TensorViewCanonicalization<T, R> for CpuBackendwhere
T: Clone + 'static,
R: TensorRank,
fn to_contiguous( &mut self, view: &TypedTensorView<'_, T, R>, ) -> Result<TypedTensor<T, R>>
fn copy_from_contiguous( &mut self, src: &TypedTensor<T, R>, dst: &mut TypedTensorViewMut<'_, T, R>, ) -> Result<()>
impl BackendCachedDot for CpuBackend
impl BackendRuntimeCache for CpuBackend
impl TensorBackend for CpuBackend
impl TensorFusion for CpuBackend
Auto Trait Implementations§
impl Freeze for CpuBackend
impl !RefUnwindSafe for CpuBackend
impl Send for CpuBackend
impl Sync for CpuBackend
impl Unpin for CpuBackend
impl UnsafeUnpin for CpuBackend
impl !UnwindSafe for CpuBackend
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<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
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