Skip to main content

LazyHostStorage

Struct LazyHostStorage 

Source
pub struct LazyHostStorage { /* private fields */ }
Expand description

Host storage for a tensor whose bytes are still on a device.

A device tensor crosses the model boundary wrapped in one of these. The result is a host tensor as far as facts, datum type and shape go, but nothing is copied back until something reads the bytes: as_bytes, as_slice, try_as_plain_ram and friends materialize it once and keep the result, and a caller that only hands it to the next run() never pays a readback at all, because DeviceSync takes the device tensor back out of it.

Only owned device tensors belong here. A view borrows a buffer whose contents are only good for the turn, so it is copied out at the boundary rather than held.

Implementations§

Source§

impl LazyHostStorage

Source

pub fn new(device: DeviceTensor) -> TractResult<Self>

Wrap a device tensor whose bytes are to be read later.

Waits for the work producing those bytes before wrapping: the wait belongs to the thread that queued the work, and a reader is free to be another one – a Metal stream is thread-local, so a wait deferred to the reader would be a wait on an empty queue and the bytes would be read before the device wrote them.

Source

pub fn device(&self) -> Option<&DeviceTensor>

The device tensor still backing this storage, if it has not been detached by a host-side mutation.

Source

pub fn is_materialized(&self) -> bool

True once the bytes have been brought back to host.

Source

pub fn datum_type(&self) -> DatumType

Source

pub fn shape(&self) -> TVec<usize>

Source

pub fn into_tensor(self) -> Tensor

Wrap into a Tensor carrying the device tensor’s datum type and shape.

Trait Implementations§

Source§

impl Debug for LazyHostStorage

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for LazyHostStorage

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for LazyHostStorage

Source§

impl PartialEq for LazyHostStorage

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl TensorStorage for LazyHostStorage

Source§

fn slice( &self, dt: DatumType, shape: &[usize], axis: usize, start: usize, end: usize, ) -> TractResult<Option<Tensor>>

Bytes still on the device are sliced there, and the slice stays lazy: an application truncating state it hands straight back to the next run() never brings either side across. Once they are here the generic copy is the cheaper path, and a host-side write has detached the device tensor, leaving nothing to ask.

Source§

fn byte_len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

fn deep_clone(&self) -> Box<dyn TensorStorage>

Source§

fn as_plain_ram(&self) -> Option<&PlainStorage>

Source§

fn as_plain_ram_mut(&mut self) -> Option<&mut PlainStorage>

Source§

fn into_plain_ram(self: Box<Self>) -> Option<PlainStorage>

Source§

fn dyn_hash(&self, _state: &mut dyn Hasher)

Source§

fn exotic_fact( &self, _shape: &[usize], ) -> TractResult<Option<Box<dyn ExoticFact>>>

Build the ExoticFact that describes this storage for use in TypedFact. Read more
Source§

fn is_exotic(&self) -> bool

True when the tensor’s datum type and shape do not describe it on their own, so a fact over it carries an ExoticFact. Read more
Source§

fn in_ram(&self) -> bool

True when the bytes are in host memory, readable without a transfer. Read more
Source§

fn materialize_plain_ram(&self) -> TractResult<&PlainStorage>

Plain storage for the tensor’s bytes, producing it if this storage can. 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
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynEq for T
where T: Eq + 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn dyn_eq(&self, other: &(dyn Any + 'static)) -> bool

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.