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
impl LazyHostStorage
Sourcepub fn new(device: DeviceTensor) -> TractResult<Self>
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.
Sourcepub fn device(&self) -> Option<&DeviceTensor>
pub fn device(&self) -> Option<&DeviceTensor>
The device tensor still backing this storage, if it has not been detached by a host-side mutation.
Sourcepub fn is_materialized(&self) -> bool
pub fn is_materialized(&self) -> bool
True once the bytes have been brought back to host.
pub fn datum_type(&self) -> DatumType
pub fn shape(&self) -> TVec<usize>
Sourcepub fn into_tensor(self) -> Tensor
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
impl Debug for LazyHostStorage
Source§impl Display for LazyHostStorage
impl Display for LazyHostStorage
impl Eq for LazyHostStorage
Source§impl PartialEq for LazyHostStorage
impl PartialEq for LazyHostStorage
Source§impl TensorStorage for LazyHostStorage
impl TensorStorage for LazyHostStorage
Source§fn slice(
&self,
dt: DatumType,
shape: &[usize],
axis: usize,
start: usize,
end: usize,
) -> TractResult<Option<Tensor>>
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.
fn byte_len(&self) -> usize
fn is_empty(&self) -> bool
fn deep_clone(&self) -> Box<dyn TensorStorage>
fn as_plain_ram(&self) -> Option<&PlainStorage>
fn as_plain_ram_mut(&mut self) -> Option<&mut PlainStorage>
fn into_plain_ram(self: Box<Self>) -> Option<PlainStorage>
fn dyn_hash(&self, _state: &mut dyn Hasher)
Source§fn exotic_fact(
&self,
_shape: &[usize],
) -> TractResult<Option<Box<dyn ExoticFact>>>
fn exotic_fact( &self, _shape: &[usize], ) -> TractResult<Option<Box<dyn ExoticFact>>>
Source§fn is_exotic(&self) -> bool
fn is_exotic(&self) -> bool
ExoticFact. Read moreSource§fn in_ram(&self) -> bool
fn in_ram(&self) -> bool
Source§fn materialize_plain_ram(&self) -> TractResult<&PlainStorage>
fn materialize_plain_ram(&self) -> TractResult<&PlainStorage>
Auto Trait Implementations§
impl !Freeze for LazyHostStorage
impl !RefUnwindSafe for LazyHostStorage
impl !UnwindSafe for LazyHostStorage
impl Send for LazyHostStorage
impl Sync for LazyHostStorage
impl Unpin for LazyHostStorage
impl UnsafeUnpin for LazyHostStorage
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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