pub enum DeviceTensor {
Owned(Box<dyn OwnedDeviceTensor>),
View(DeviceView),
}Expand description
A GPU tensor: either a buffer of its own, or a window into someone else’s.
Variants§
Owned(Box<dyn OwnedDeviceTensor>)
View(DeviceView)
Implementations§
Source§impl DeviceTensor
impl DeviceTensor
pub const SUPPORTED_DT: [DatumType; 11]
pub fn tname(dt: DatumType) -> TractResult<&'static str>
Sourcepub fn uninitialized_dt(
dt: DatumType,
shape: &[usize],
) -> TractResult<DeviceTensor>
pub fn uninitialized_dt( dt: DatumType, shape: &[usize], ) -> TractResult<DeviceTensor>
Create an uninitialized DeviceTensor
pub fn uninitialized<T: Datum>(shape: &[usize]) -> TractResult<DeviceTensor>
pub fn uninitialized_exotic( exotic_fact: Box<dyn ExoticFact>, ) -> TractResult<DeviceTensor>
pub fn from_shape<T: Copy + Datum>( shape: &[usize], data: &[T], ) -> TractResult<DeviceTensor>
pub fn is_supported_dt(dt: DatumType) -> bool
Sourcepub fn datum_type(&self) -> DatumType
pub fn datum_type(&self) -> DatumType
Get the datum type of the tensor.
Sourcepub fn device_buffer(&self) -> &dyn DeviceBuffer
pub fn device_buffer(&self) -> &dyn DeviceBuffer
Get underlying inner buffer.
Sourcepub fn buffer_offset<I: Copy + 'static>(&self) -> Iwhere
usize: AsPrimitive<I>,
pub fn buffer_offset<I: Copy + 'static>(&self) -> Iwhere
usize: AsPrimitive<I>,
Get underlying inner buffer offset
pub fn device_buffer_ptr(&self) -> *const c_void
Sourcepub fn description(&self) -> String
pub fn description(&self) -> String
Returns short description of the inner tensor.
Sourcepub fn reshaped(&self, shape: TVec<usize>) -> TractResult<Self>
pub fn reshaped(&self, shape: TVec<usize>) -> TractResult<Self>
Reshaped tensor with given shape.
pub fn restrided(&self, strides: TVec<isize>) -> TractResult<Self>
Sourcepub fn into_tensor(self) -> Tensor
pub fn into_tensor(self) -> Tensor
Convert device tensor to a Tensor backed by device storage.
The resulting tensor carries the real datum type and shape from the device tensor (e.g. F32 / [2,3]), rather than an exotic scalar wrapper.
Sourcepub fn prefix_window(
&self,
axis: usize,
len: usize,
) -> TractResult<DeviceTensor>
pub fn prefix_window( &self, axis: usize, len: usize, ) -> TractResult<DeviceTensor>
The first len along axis, as a view keeping this tensor’s strides.
What a buffer holding spare capacity hands out: the live prefix costs
nothing to describe, and the tail it leaves behind is simply not part of
the shape. A DeviceView is turn-scoped, so this is for a reader
downstream of the producer, never for the application.
The result is strided wherever axis is not the outermost: a consumer
has to read shape and strides rather than assume a packed tensor.
Sourcepub fn to_host(&self) -> TractResult<Arc<Tensor>>
pub fn to_host(&self) -> TractResult<Arc<Tensor>>
Synchronize the GPU Tensor by completing all current commands on GPU and returns the inner tensor.
Trait Implementations§
Source§impl Clone for DeviceTensor
impl Clone for DeviceTensor
Source§impl Debug for DeviceTensor
impl Debug for DeviceTensor
Source§impl Display for DeviceTensor
impl Display for DeviceTensor
impl Eq for DeviceTensor
Source§impl From<DeviceView> for DeviceTensor
impl From<DeviceView> for DeviceTensor
Source§fn from(view: DeviceView) -> Self
fn from(view: DeviceView) -> Self
Source§impl Hash for DeviceTensor
impl Hash for DeviceTensor
Source§impl IntoDevice<DeviceTensor> for Tensor
impl IntoDevice<DeviceTensor> for Tensor
fn into_device(self) -> TractResult<DeviceTensor>
Source§impl IntoDevice<DeviceTensor> for Arc<Tensor>
impl IntoDevice<DeviceTensor> for Arc<Tensor>
fn into_device(self) -> TractResult<DeviceTensor>
Source§impl PartialEq for DeviceTensor
impl PartialEq for DeviceTensor
impl StructuralPartialEq for DeviceTensor
Source§impl TensorStorage for DeviceTensor
impl TensorStorage for DeviceTensor
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 is_exotic(&self) -> bool
fn is_exotic(&self) -> bool
ExoticFact. Read moreSource§fn in_ram(&self) -> bool
fn in_ram(&self) -> bool
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>>
axis, if this storage can serve it in its own memory –
for free where the slice is already a range it holds, by a copy it can
make where it is otherwise. Read moreSource§fn exotic_fact(
&self,
_shape: &[usize],
) -> TractResult<Option<Box<dyn ExoticFact>>>
fn exotic_fact( &self, _shape: &[usize], ) -> TractResult<Option<Box<dyn ExoticFact>>>
Source§fn materialize_plain_ram(&self) -> Result<&PlainStorage, Error>
fn materialize_plain_ram(&self) -> Result<&PlainStorage, Error>
Auto Trait Implementations§
impl !RefUnwindSafe for DeviceTensor
impl !UnwindSafe for DeviceTensor
impl Freeze for DeviceTensor
impl Send for DeviceTensor
impl Sync for DeviceTensor
impl Unpin for DeviceTensor
impl UnsafeUnpin for DeviceTensor
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
impl<T> CloneAny for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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