Struct DLPackTensor
pub struct DLPackTensor { /* private fields */ }Expand description
A managed DLPack tensor, carrying ownership of the data.
Convertion from and to other array types is handled though the different
TryFrom implementations.
Implementations§
§impl DLPackTensor
impl DLPackTensor
pub unsafe fn from_ptr(tensor: *mut DLManagedTensorVersioned) -> DLPackTensor
pub unsafe fn from_ptr(tensor: *mut DLManagedTensorVersioned) -> DLPackTensor
Create a DLPackTensor from a pointer to DLManagedTensorVersioned.
§Safety
The DLManagedTensorVersioned should have a valid deleter that can
be called from Rust, or have the deleter set to None.
pub unsafe fn from_raw(
tensor: NonNull<DLManagedTensorVersioned>,
) -> DLPackTensor
pub unsafe fn from_raw( tensor: NonNull<DLManagedTensorVersioned>, ) -> DLPackTensor
Create a DLPackTensor from a non-null pointer to
DLManagedTensorVersioned.
§Safety
The same safety requirements as from_ptr apply.
pub fn as_ref(&self) -> DLPackTensorRef<'_>
pub fn as_ref(&self) -> DLPackTensorRef<'_>
Get a DLPack tensor reference from this owned tensor
pub fn as_mut(&mut self) -> DLPackTensorRefMut<'_>
pub fn as_mut(&mut self) -> DLPackTensorRefMut<'_>
Get a mutable DLPack tensor reference from this owned tensor
pub fn version(&self) -> DLPackVersion
pub fn version(&self) -> DLPackVersion
Get the ABI version of this DLPack tensor.
pub fn data_ptr<T>(&self) -> Result<*const T, CastError>where
T: DLPackPointerCast,
pub fn data_ptr<T>(&self) -> Result<*const T, CastError>where
T: DLPackPointerCast,
Get a pointer to data in this tensor. This pointer can be a device
pointer according to DLPackTensor::device.
pub fn data_ptr_mut<T>(&mut self) -> Result<*mut T, CastError>where
T: DLPackPointerCast,
pub fn data_ptr_mut<T>(&mut self) -> Result<*mut T, CastError>where
T: DLPackPointerCast,
Get a mutable pointer to data in this tensor. This pointer can be a
device pointer according to DLPackTensor::device.
pub fn dtype(&self) -> DLDataType
pub fn dtype(&self) -> DLDataType
Get the data type of this tensor
pub fn is_read_only(&self) -> bool
pub fn is_read_only(&self) -> bool
Check if the tensor is explicitly marked as read-only.
pub fn is_subbyte_type_padded(&self) -> bool
pub fn is_subbyte_type_padded(&self) -> bool
Check if the sub-byte types (fp4, fp6) are padded to the next byte, or packed together.
pub fn byte_offset(&self) -> usize
pub fn byte_offset(&self) -> usize
Get the byte offset of this tensor, i.e. how many bytes should be added
to DLPackTensor::data_ptr and DLPackTensor::data_ptr_mut to get
the first element of the tensor.
pub fn as_dltensor(&self) -> &DLTensor
pub fn as_dltensor(&self) -> &DLTensor
Get a reference to the underlying DLTensor
Trait Implementations§
§impl Debug for DLPackTensor
impl Debug for DLPackTensor
§impl<T, D> TryFrom<ArrayBase<OwnedArcRepr<T>, D>> for DLPackTensor
Convert a shared ArcArray into a DLPackTensor.
This is ZERO-COPY: it increments the reference count of the data.
impl<T, D> TryFrom<ArrayBase<OwnedArcRepr<T>, D>> for DLPackTensor
Convert a shared ArcArray into a DLPackTensor.
This is ZERO-COPY: it increments the reference count of the data.