Skip to main content

TensorDesc

Struct TensorDesc 

Source
#[repr(C)]
pub struct TensorDesc {
Show 14 fields pub version: u32, pub kind: u32, pub handle: i64, pub ptr: SendPtr, pub ndim: u32, pub dtype: u32, pub shape: [u64; 8], pub strides: [i64; 8], pub fourcc: u32, pub format: u32, pub colorimetry: u32, pub flags: u32, pub capacity: u64, pub sync: u64,
}
Expand description

The cross-package descriptor. Layout is part of the contract: it is #[repr(C)] and its size is pinned by test.

Fields§

§version: u32

ABI_VERSION. Checked, never assumed.

§kind: u32

One of the kind constants.

§handle: i64

dma-buf fd, IOSurface id or GL buffer id; -1 when unused.

§ptr: SendPtr

Host pointer when addressable, else null – except under kind::PBO, where it instead carries a *const crate::pbo::PboOpsVtable, or null if the producer attached none. Interpretation is keyed by Self::kind, the same established pattern Self::sync’s own doc comment already documents for that field: a PBO tensor never takes a HostPin (PboTensor refuses pin_host — the address cannot outlive the map), so this field is otherwise permanently unused for that kind, which is exactly why it is the field that carries the vtable instead of a new one requiring a layout change. Valid under the exact same borrow contract as the host-pointer case: only while the producer’s own keepalive (for the capsule protocol, the capsule’s) keeps the owning tensor alive.

§ndim: u32

Number of significant entries in shape and strides.

§dtype: u32

Element type, one of the [dtype] constants.

Deliberately placed here: ndim leaves a 4-byte hole before the 8-aligned shape, so this field costs nothing. Without it strides — documented in elements — cannot be converted to bytes by a consumer, and a Tensor<f32> is indistinguishable from a Tensor<u8> of the same shape.

§shape: [u64; 8]

Logical shape, most-significant dimension first.

§strides: [i64; 8]

Strides in bytes, signed so a consumer can express flips.

Bytes rather than elements so a hardware row pitch is always representable: a pitch need not be a whole number of dtype elements (and a sub-byte dtype has no element size to divide by). Multiply a coordinate by the stride directly; do not scale by dtype size.

§fourcc: u32

DRM FourCC of the pixel format, or 0 for a non-image tensor. Kept for third-party/DRM interop; a HAL-aware consumer should prefer Self::format and fall back to this only when format is 0 (see format’s doc for why fourcc alone is insufficient).

§format: u32

One of the format constants, or 0 for a non-image tensor.

§colorimetry: u32

Packed colorimetry, or 0 when unspecified.

§flags: u32

Bit flags; see flags. Zero when nothing applies.

Occupies what was a 4-byte alignment hole before capacity, so it cost nothing to add.

§capacity: u64

Bytes available in the producer’s underlying allocation, from this tensor’s window start (its TensorTrait::capacity_bytes ) – may exceed the byte size shape/strides imply when the producer over-allocated: a pool tensor sized for its largest expected image but holding a smaller one today, or row-pitch/MCU-alignment padding a decoder needs beyond the logical width. Without this, a consumer importing a HOST descriptor has no way to learn that headroom exists and must treat the declared shape as the allocation’s exact size – which starves a later configure_image/set_logical_shape of capacity the producer actually has. DMABUF/IOSURFACE consumers query their real capacity from the handle itself and do not depend on this field, but it is populated for every kind for consistency.

§sync: u64

Completion handle for work still in flight against this tensor, or 0 when flags::SYNC_PRESENT is clear.

Reserved: producers in this build always leave it clear. It is declared now because the field has to exist before the first release or adding it later costs a capsule-name bump, and it is the one gap the synchronous-at-the-boundary contract cannot close: a foreign producer with queued GPU work has no other way to say “wait on this first”.

Interpretation is keyed by Self::kind, since each backing already implies its own fence flavour and a separate discriminant would be redundant:

  • kind::DMABUF – a sync_file fd from DMA_BUF_IOCTL_EXPORT_SYNC_FILE. The consumer owns it and must close it.
  • kind::PBO – a GLsync from glFenceSync, valid only in the producer’s share group.
  • kind::CUDA_DEVICE – a cudaEvent_t.
  • kind::HOST, kind::IOSURFACE – no fence flavour defined; SYNC_PRESENT must be clear.

Implementations§

Source§

impl TensorDesc

Source

pub const MAX_NDIM: usize = 8

Maximum rank the fixed-size shape/strides arrays can carry.

Source

pub fn shape(&self) -> &[u64]

The logical shape as a slice.

Source

pub fn strides(&self) -> &[i64]

The strides as a slice, in bytes.

Source

pub fn len(&self) -> u64

Total element count.

Source

pub fn is_empty(&self) -> bool

True when the descriptor addresses no elements.

Trait Implementations§

Source§

impl Clone for TensorDesc

Source§

fn clone(&self) -> TensorDesc

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for TensorDesc

Source§

impl Debug for TensorDesc

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more