pub struct CpuContext { /* private fields */ }Expand description
CPU execution context.
Encapsulates CPU-side execution resources, analogous to cuTENSOR’s
cutensorHandle_t. Holds a rayon thread pool, a PlanCache for plan
reuse, and reusable temporary buffers for host-side execution helpers.
§Examples
use tenferro_prims::CpuContext;
let mut ctx = CpuContext::try_new(4)?; // 4-thread pool
assert_eq!(ctx.num_threads(), 4);Implementations§
Source§impl CpuContext
impl CpuContext
Sourcepub fn default_num_threads() -> usize
pub fn default_num_threads() -> usize
Return the backend-defined default CPU thread count.
On Linux this prefers the current process CPU affinity mask. Other
platforms fall back to std::thread::available_parallelism.
Sourcepub fn try_new(num_threads: usize) -> Result<CpuContext, Error>
pub fn try_new(num_threads: usize) -> Result<CpuContext, Error>
Create a new CPU context with the given number of threads.
§Errors
Returns tenferro_device::Error::InvalidArgument when
num_threads == 0, or tenferro_device::Error::DeviceError when the
underlying Rayon thread-pool construction fails.
§Examples
use tenferro_prims::CpuContext;
let ctx = CpuContext::try_new(2)?;
assert_eq!(ctx.num_threads(), 2);Sourcepub fn try_new_default() -> Result<CpuContext, Error>
pub fn try_new_default() -> Result<CpuContext, Error>
Create a new CPU context using the backend-defined default thread count.
Sourcepub fn new(num_threads: usize) -> CpuContext
pub fn new(num_threads: usize) -> CpuContext
Create a new CPU context with the given number of threads.
This is a convenience wrapper around CpuContext::try_new. Production
code should generally prefer the fallible constructor so context setup
errors stay in the normal Result flow.
§Panics
Panics if CpuContext::try_new returns an error.
§Examples
use tenferro_prims::CpuContext;
let ctx = CpuContext::new(1);
assert_eq!(ctx.num_threads(), 1);Sourcepub fn new_default() -> CpuContext
pub fn new_default() -> CpuContext
Create a new CPU context using the backend-defined default thread count.
Sourcepub fn num_threads(&self) -> usize
pub fn num_threads(&self) -> usize
Returns the number of threads in the pool.
Sourcepub fn thread_pool(&self) -> &ThreadPool
pub fn thread_pool(&self) -> &ThreadPool
Returns a reference to the underlying rayon thread pool.
Sourcepub fn install<R>(&self, op: impl FnOnce() -> R + Send) -> Rwhere
R: Send,
pub fn install<R>(&self, op: impl FnOnce() -> R + Send) -> Rwhere
R: Send,
Run a closure inside the owned rayon thread pool.
Sourcepub fn plan_cache_mut(&mut self) -> &mut PlanCache
pub fn plan_cache_mut(&mut self) -> &mut PlanCache
Returns a mutable reference to the plan cache.
Trait Implementations§
Source§impl Default for CpuContext
impl Default for CpuContext
Source§fn default() -> CpuContext
fn default() -> CpuContext
Source§impl<Input> TensorComplexRealContextFor<Input> for CpuContextwhere
Input: Scalar + ComplexFloat,
<Input as ComplexFloat>::Real: Scalar,
CpuBackend: TensorComplexRealPrims<Input, Context = CpuContext, Real = <Input as ComplexFloat>::Real>,
impl<Input> TensorComplexRealContextFor<Input> for CpuContextwhere
Input: Scalar + ComplexFloat,
<Input as ComplexFloat>::Real: Scalar,
CpuBackend: TensorComplexRealPrims<Input, Context = CpuContext, Real = <Input as ComplexFloat>::Real>,
Source§type ComplexRealBackend = CpuBackend
type ComplexRealBackend = CpuBackend
Source§impl<Input> TensorComplexScaleContextFor<Input> for CpuContextwhere
Input: ComplexFloat + Scalar,
<Input as ComplexFloat>::Real: Scalar + Send + Sync,
CpuBackend: TensorComplexScalePrims<Input, Context = CpuContext>,
impl<Input> TensorComplexScaleContextFor<Input> for CpuContextwhere
Input: ComplexFloat + Scalar,
<Input as ComplexFloat>::Real: Scalar + Send + Sync,
CpuBackend: TensorComplexScalePrims<Input, Context = CpuContext>,
Source§type ComplexScaleBackend = CpuBackend
type ComplexScaleBackend = CpuBackend
Source§impl<Alg> TensorIndexingContextFor<Alg> for CpuContext
impl<Alg> TensorIndexingContextFor<Alg> for CpuContext
Source§type IndexingBackend = CpuBackend
type IndexingBackend = CpuBackend
Source§impl<T> TensorLinalgContextFor<T> for CpuContextwhere
T: KernelLinalgScalar,
impl<T> TensorLinalgContextFor<T> for CpuContextwhere
T: KernelLinalgScalar,
Source§type Backend = CpuTensorLinalgBackend
type Backend = CpuTensorLinalgBackend
Source§impl TensorMetadataContextFor for CpuContext
impl TensorMetadataContextFor for CpuContext
Source§type MetadataBackend = CpuBackend
type MetadataBackend = CpuBackend
Source§impl<T> TensorResolveConjContextFor<T> for CpuContext
impl<T> TensorResolveConjContextFor<T> for CpuContext
Source§fn resolve_conj(ctx: &mut CpuContext, src: &Tensor<T>) -> Tensor<T>
fn resolve_conj(ctx: &mut CpuContext, src: &Tensor<T>) -> Tensor<T>
Self.Source§impl<Alg> TensorScalarContextFor<Alg> for CpuContext
impl<Alg> TensorScalarContextFor<Alg> for CpuContext
Source§type ScalarBackend = CpuBackend
type ScalarBackend = CpuBackend
Source§impl<Alg> TensorSemiringContextFor<Alg> for CpuContext
impl<Alg> TensorSemiringContextFor<Alg> for CpuContext
Source§type SemiringBackend = CpuBackend
type SemiringBackend = CpuBackend
Source§impl<Alg> TensorSortContextFor<Alg> for CpuContextwhere
Alg: Algebra,
<Alg as Algebra>::Scalar: PartialOrd,
CpuBackend: TensorSortPrims<Alg, Context = CpuContext>,
impl<Alg> TensorSortContextFor<Alg> for CpuContextwhere
Alg: Algebra,
<Alg as Algebra>::Scalar: PartialOrd,
CpuBackend: TensorSortPrims<Alg, Context = CpuContext>,
Source§type SortBackend = CpuBackend
type SortBackend = CpuBackend
Auto Trait Implementations§
impl Freeze for CpuContext
impl !RefUnwindSafe for CpuContext
impl Send for CpuContext
impl !Sync for CpuContext
impl Unpin for CpuContext
impl !UnwindSafe for CpuContext
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