Skip to main content

CpuPlacementBoundEager

Struct CpuPlacementBoundEager 

Source
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

Source

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());
Source

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);
Source

pub fn with_eager_session<T: Send, E: From<Error> + Send>( &mut self, f: impl FnOnce(&mut dyn BackendSession) -> Result<T, E> + Send, ) -> Result<T, E>

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, TensorRead};

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| {
    session
        .add_read(TensorRead::from_tensor(&lhs), TensorRead::from_tensor(&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. Returns E::from(Error::SessionEntry) without running the callback when the backend cannot admit the session, for example when it is called from inside another session on this thread (tenferro_tensor::SessionEntryError::Reentered), and E::from the runtime-selection error when the CPU placement cannot be refreshed. Use only the borrowed session for work inside the scope.

Trait Implementations§

Source§

impl Debug for CpuPlacementBoundEager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSendSync for T
where T: Send + Sync,

§

impl<T> MaybeSync for T
where T: Sync,

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.