Skip to main content

TensorRef

Struct TensorRef 

Source
pub struct TensorRef<H, M>{ /* 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>

Source

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.

Source

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,

Source

pub fn wait(&self, map_type: MapType, finish: bool)

Try to wait for the device tensor to finish processing

Source

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>

Source

pub fn fill(&mut self, value: T) -> Result<()>
where T: Copy,

Fill the tensor with the specified value

Fails if the tensor has a different element type, has not been resized yet (dynamic shape) or, for device tensors, if MNN refuses the copy (e.g. no backend is attached).

Source§

impl<T> TensorRef<T, Host>
where T: HalideType,

Source

pub fn try_host(&self) -> Result<&[T]>

Try to map the device tensor to the host memory and get the slice

Source

pub fn try_host_mut(&mut self) -> Result<&mut [T]>

Try to map the device tensor to the host memory and get the mutable slice

Source

pub fn host(&self) -> &[T]

Get the host memory slice of the tensor

Source

pub fn host_mut(&mut self) -> &mut [T]

Get the mutable host memory slice of the tensor

Methods from Deref<Target = AnyTensorRef>§

Source

pub fn device_id(&self) -> u64

Get the device id of the tensor

Source

pub fn shape(&self) -> TensorShape

Get the shape of the tensor

Source

pub fn dimensions(&self) -> usize

Get the dimensions of the tensor

Source

pub fn width(&self) -> u32

Get the width of the tensor

Source

pub fn height(&self) -> u32

Get the height of the tensor

Source

pub fn channel(&self) -> u32

Get the channel size of the tensor

Source

pub fn batch(&self) -> u32

Get the batch size of the tensor

Source

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.

Source

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.

Source

pub fn get_type(&self) -> halide_type_t

Get the halide data type of the tensor

Source

pub fn is_type_of<Ha: HalideType>(&self) -> bool

Check if the tensor is of the specified data type

Source

pub fn is_same_type(&self, other: &AnyTensorRef) -> bool

Check if both tensors have the same halide data type

Source

pub fn get_dimension_type(&self) -> DimensionType

Get the dimension type of the tensor

Source

pub fn is_dynamic_unsized(&self) -> bool

Check if the tensor is dynamic and needs resizing

Source

pub fn copy_from_host_tensor(&mut self, tensor: &AnyTensorRef) -> Result<()>

Copies the data from a host tensor to the self.as_ptr()

Source

pub fn copy_to_host_tensor(&self, tensor: &mut AnyTensorRef) -> Result<()>

Copies the data from the self.as_ptr() to a host tensor

Source

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.

Trait Implementations§

Source§

impl<H, M> Debug for TensorRef<H, M>

Source§

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

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

impl<H, M> Deref for TensorRef<H, M>

Source§

type Target = AnyTensorRef

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<H, M> DerefMut for TensorRef<H, M>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<H, M> Freeze for TensorRef<H, M>

§

impl<H, M> RefUnwindSafe for TensorRef<H, M>

§

impl<H, M> Send for TensorRef<H, M>
where M: Send, H: Send,

§

impl<H, M> Sync for TensorRef<H, M>
where M: Sync, H: Sync,

§

impl<H, M> Unpin for TensorRef<H, M>
where M: Unpin, H: Unpin,

§

impl<H, M> UnsafeUnpin for TensorRef<H, M>

§

impl<H, M> UnwindSafe for TensorRef<H, M>
where M: UnwindSafe, H: UnwindSafe,

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<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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> MaybeDebug for T
where T: Debug,

§

impl<T> OpaqueAttachment for T
where T: Send + Sync + 'static,