pub struct TensorRef<H, M>where
H: HalideType,
M: TensorMachine,{ /* private fields */ }Expand description
This is modeled as a reference to a tensor, you should never be able to dereference this. At any point you should only have &TensorRef or &mut TensorRef, never an owned TensorRef.
Implementations§
Source§impl<H: HalideType, M: TensorMachine> TensorRef<H, M>
impl<H: HalideType, M: TensorMachine> TensorRef<H, M>
Sourcepub fn copy_from_host_tensor(
&mut self,
tensor: &TensorRef<H, Host>,
) -> Result<()>
pub fn copy_from_host_tensor( &mut self, tensor: &TensorRef<H, Host>, ) -> Result<()>
Copies the data from a host tensor to the self.as_ptr()
The tensors must have the same logical shape; MNN converts between layouts (e.g. NCHW <-> NC4HW4) as part of the copy.
Sourcepub fn copy_to_host_tensor(&self, tensor: &mut TensorRef<H, Host>) -> Result<()>
pub fn copy_to_host_tensor(&self, tensor: &mut TensorRef<H, Host>) -> Result<()>
Copies the data from the self.as_ptr() to a host tensor
The tensors must have the same logical shape; MNN converts between layouts (e.g. NCHW <-> NC4HW4) as part of the copy.
Source§impl<T> TensorRef<T, Device>where
T: HalideType,
impl<T> TensorRef<T, Device>where
T: HalideType,
Sourcepub fn wait(&self, map_type: MapType, finish: bool)
pub fn wait(&self, map_type: MapType, finish: bool)
Try to wait for the device tensor to finish processing
Sourcepub fn create_host_tensor_from_device(
&self,
copy_data: bool,
) -> Tensor<Owned<T>, Host>
pub fn create_host_tensor_from_device( &self, copy_data: bool, ) -> Tensor<Owned<T>, Host>
Create a host tensor from the device tensor with same dimensions and data type and optionally copy the data from the device tensor
The host tensor uses the unpacked layout (NCHW / NHWC) even when the device tensor is
stored as NC4HW4, so host() yields the elements in logical order.
Source§impl<T, M> TensorRef<T, M>where
T: HalideType,
M: TensorMachine,
impl<T, M> TensorRef<T, M>where
T: HalideType,
M: TensorMachine,
Methods from Deref<Target = AnyTensorRef>§
Sourcepub fn shape(&self) -> TensorShape
pub fn shape(&self) -> TensorShape
Get the shape of the tensor
Sourcepub fn dimensions(&self) -> usize
pub fn dimensions(&self) -> usize
Get the dimensions of the tensor
Sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Get the size of the tensor when counted by bytes
Note that for packed layouts (NC4HW4) this includes the padding MNN adds to the channel dimension, so it can be larger than the product of the shape.
Sourcepub fn element_size(&self) -> usize
pub fn element_size(&self) -> usize
Get the size of the tensor when counted by elements
Note that for packed layouts (NC4HW4) this includes the padding MNN adds to the channel dimension, so it can be larger than the product of the shape.
Sourcepub fn get_type(&self) -> halide_type_t
pub fn get_type(&self) -> halide_type_t
Get the halide data type of the tensor
Sourcepub fn is_type_of<Ha: HalideType>(&self) -> bool
pub fn is_type_of<Ha: HalideType>(&self) -> bool
Check if the tensor is of the specified data type
Sourcepub fn is_same_type(&self, other: &AnyTensorRef) -> bool
pub fn is_same_type(&self, other: &AnyTensorRef) -> bool
Check if both tensors have the same halide data type
Sourcepub fn get_dimension_type(&self) -> DimensionType
pub fn get_dimension_type(&self) -> DimensionType
Get the dimension type of the tensor
Sourcepub fn is_dynamic_unsized(&self) -> bool
pub fn is_dynamic_unsized(&self) -> bool
Check if the tensor is dynamic and needs resizing
Sourcepub fn copy_from_host_tensor(&mut self, tensor: &AnyTensorRef) -> Result<()>
pub fn copy_from_host_tensor(&mut self, tensor: &AnyTensorRef) -> Result<()>
Copies the data from a host tensor to the self.as_ptr()
Sourcepub fn copy_to_host_tensor(&self, tensor: &mut AnyTensorRef) -> Result<()>
pub fn copy_to_host_tensor(&self, tensor: &mut AnyTensorRef) -> Result<()>
Copies the data from the self.as_ptr() to a host tensor
Sourcepub fn create_host_tensor_from_device<T: HalideType + Copy>(
&self,
copy_data: bool,
) -> Tensor<Owned<T>, Host>
pub fn create_host_tensor_from_device<T: HalideType + Copy>( &self, copy_data: bool, ) -> Tensor<Owned<T>, Host>
Create a host tensor from the device tensor with same dimensions and data type and optionally copy the data from the device tensor
§Panics
Panics if the tensor’s element type is not T or the copy fails.