pub struct CpuPlacementBoundEager { /* private fields */ }Expand description
Placement-selected CPU view of one EagerRuntime.
The view snapshots the runtime’s CPU coordinator/provider bundle and the
immutable runtime registration metadata when EagerRuntime::on_cpu is
called. It holds no resource permit while idle and enters one backend
session only while Self::with_eager_session runs. The session exposes
core BackendSession operations on concrete Tensor values. This
bridge deliberately does not expose the eager runtime’s linalg, FFT, einsum,
or extension-runtime registries.
The value is intentionally not Clone: mutable use makes concurrent
session ownership explicit without adding another backend mutex.
§Examples
use tenferro_ad::EagerRuntime;
use tenferro_cpu::CpuPlacement;
let runtime = EagerRuntime::new()?;
let cpu = runtime.on_cpu(CpuPlacement::Auto)?;
assert_eq!(cpu.runtime_id(), runtime.id());Implementations§
Source§impl CpuPlacementBoundEager
impl CpuPlacementBoundEager
Sourcepub fn runtime_id(&self) -> ContextId
pub fn runtime_id(&self) -> ContextId
Return the identity of the original eager runtime.
§Examples
use tenferro_ad::EagerRuntime;
use tenferro_cpu::CpuPlacement;
let runtime = EagerRuntime::new()?;
let cpu = runtime.on_cpu(CpuPlacement::Auto)?;
assert_eq!(cpu.runtime_id(), runtime.id());Sourcepub fn placement(&self) -> CpuPlacement
pub fn placement(&self) -> CpuPlacement
Return the placement requested when this view was created.
§Examples
use tenferro_ad::EagerRuntime;
use tenferro_cpu::CpuPlacement;
let runtime = EagerRuntime::new()?;
let cpu = runtime.on_cpu(CpuPlacement::Auto)?;
assert_eq!(cpu.placement(), CpuPlacement::Auto);Sourcepub fn with_eager_session<R: Send>(
&mut self,
f: impl FnOnce(&mut dyn BackendSession) -> Result<R> + Send,
) -> Result<R>
pub fn with_eager_session<R: Send>( &mut self, f: impl FnOnce(&mut dyn BackendSession) -> Result<R> + Send, ) -> Result<R>
Enter one CPU backend session and run core operations through it.
One call creates one backend session. Tenferro-managed CPU executors
enter once around the closure and core operations reuse that compatible
execution scope. The closure may borrow stack data and need not be
'static.
This phase-2 bridge accepts only core BackendSession operations. It
does not lock or dispatch the eager runtime’s linalg, FFT, einsum, or
extension registries.
§Examples
use tenferro_ad::{EagerRuntime, Error};
use tenferro_cpu::CpuPlacement;
use tenferro_tensor::{Tensor, TensorElementwise};
let runtime = EagerRuntime::new()?;
let mut cpu = runtime.on_cpu(CpuPlacement::Auto)?;
let lhs = Tensor::from_vec_col_major(vec![1], vec![1.0_f64])?;
let rhs = Tensor::from_vec_col_major(vec![1], vec![2.0_f64])?;
let output = cpu.with_eager_session(|session| {
TensorElementwise::add(session, &lhs, &rhs).map_err(Error::from)
})?;
assert_eq!(output.as_slice::<f64>().unwrap(), &[3.0]);§Errors
Returns the callback’s Error unchanged. Core backend operations may
report validation, unsupported capability, backend, or runtime-state
failures through that error.
§Panics
The existing CPU backend re-entry guard panics if the callback enters a
public CpuBackend or calls an ordinary EagerTensor operation on this
same runtime. Use only the borrowed session for work inside the scope.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CpuPlacementBoundEager
impl !RefUnwindSafe for CpuPlacementBoundEager
impl Send for CpuPlacementBoundEager
impl Sync for CpuPlacementBoundEager
impl Unpin for CpuPlacementBoundEager
impl UnsafeUnpin for CpuPlacementBoundEager
impl !UnwindSafe for CpuPlacementBoundEager
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
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