tract_gpu/tensor/
owned.rs

1use downcast_rs::{Downcast, impl_downcast};
2use dyn_clone::DynClone;
3use std::fmt::Debug;
4use tract_core::dyn_clone;
5use tract_core::internal::*;
6
7use crate::device::DeviceBuffer;
8
9use super::DeviceTensor;
10
11#[allow(clippy::len_without_is_empty)]
12pub trait OwnedDeviceTensor: Downcast + DynClone + Send + Sync + Debug {
13    fn datum_type(&self) -> DatumType;
14
15    fn shape(&self) -> &[usize];
16
17    fn strides(&self) -> &[isize];
18
19    #[inline]
20    fn len(&self) -> usize {
21        self.shape().iter().product()
22    }
23
24    fn reshaped(&self, shape: TVec<usize>) -> TractResult<DeviceTensor>;
25    fn restrided(&self, shape: TVec<isize>) -> TractResult<DeviceTensor>;
26
27    fn as_arc_tensor(&self) -> Option<&Arc<Tensor>>;
28    fn device_buffer(&self) -> &dyn DeviceBuffer;
29    fn to_host(&self) -> TractResult<Arc<Tensor>>;
30    fn view(&self) -> TensorView<'_>;
31}
32
33impl_downcast!(OwnedDeviceTensor);
34dyn_hash::hash_trait_object!(OwnedDeviceTensor);
35dyn_clone::clone_trait_object!(OwnedDeviceTensor);