pub struct TensorDesc<T: GpuFloat> {
pub ptr: CUdeviceptr,
pub dims: Vec<u32>,
pub strides: Vec<u32>,
pub layout: TensorLayout,
/* private fields */
}Expand description
Immutable tensor descriptor binding a device pointer to shape metadata.
TensorDesc does not own the device memory; it merely borrows the
raw pointer for the duration of a DNN operation. The caller must ensure
that the referenced DeviceBuffer outlives any computation that uses
this descriptor.
Fields§
§ptr: CUdeviceptrRaw device pointer to the first element.
dims: Vec<u32>Shape (one entry per dimension).
strides: Vec<u32>Strides (one entry per dimension, in elements not bytes).
layout: TensorLayoutMemory layout convention.
Implementations§
Source§impl<T: GpuFloat> TensorDesc<T>
impl<T: GpuFloat> TensorDesc<T>
Sourcepub fn nchw(
buf: &DeviceBuffer<T>,
n: u32,
c: u32,
h: u32,
w: u32,
) -> DnnResult<Self>
pub fn nchw( buf: &DeviceBuffer<T>, n: u32, c: u32, h: u32, w: u32, ) -> DnnResult<Self>
Creates an NCHW tensor descriptor from a device buffer.
§Errors
Returns DnnError::InvalidDimension if any dimension is zero.
Returns DnnError::BufferTooSmall if the buffer cannot hold
n * c * h * w elements.
Sourcepub fn ncdhw(
buf: &DeviceBuffer<T>,
n: u32,
c: u32,
d: u32,
h: u32,
w: u32,
) -> DnnResult<Self>
pub fn ncdhw( buf: &DeviceBuffer<T>, n: u32, c: u32, d: u32, h: u32, w: u32, ) -> DnnResult<Self>
Sourcepub fn matrix(buf: &DeviceBuffer<T>, rows: u32, cols: u32) -> DnnResult<Self>
pub fn matrix(buf: &DeviceBuffer<T>, rows: u32, cols: u32) -> DnnResult<Self>
Creates a 2-D matrix descriptor (rows x cols, row-major).
§Errors
Returns DnnError::InvalidDimension if either dimension is zero.
Returns DnnError::BufferTooSmall if the buffer is too small.
Sourcepub fn from_raw(
ptr: CUdeviceptr,
dims: Vec<u32>,
strides: Vec<u32>,
layout: TensorLayout,
) -> DnnResult<Self>
pub fn from_raw( ptr: CUdeviceptr, dims: Vec<u32>, strides: Vec<u32>, layout: TensorLayout, ) -> DnnResult<Self>
Constructs a descriptor from raw components without buffer validation.
The caller must ensure that ptr points to a valid device allocation
large enough for the described tensor.
Sourcepub fn validate_buffer_size(&self, buf: &DeviceBuffer<T>) -> DnnResult<()>
pub fn validate_buffer_size(&self, buf: &DeviceBuffer<T>) -> DnnResult<()>
Validates that buf is large enough to hold this tensor.
§Errors
Returns DnnError::BufferTooSmall if the buffer has fewer elements
than numel.