Skip to main content

Module protocol

Module protocol 

Source
Expand description

The cross-package tensor protocol.

Independently-linked EdgeFirst packages cannot share a Rust type: each Python extension module statically links its own copy of this crate, and PyO3 caches every #[pyclass]’s type object in a static belonging to the module that defined it. Two modules therefore see two distinct Python classes even when the Rust types are identical.

So the contract between packages is a descriptor, not a type. A producer exposes __edgefirst_tensor__() returning a PyCapsule named edgefirst_tensor_v2 whose payload leads with TensorDesc (followed by the quantization metadata TensorDesc deliberately does not carry – see edgefirst-python-common’s QuantDesc); a consumer reads the descriptor and never performs an isinstance check. That duck typing is what makes the protocol survive independent release cadences, and it is the same pattern numpy, pyarrow and DLPack use.

DLPack cannot serve this role alone: it has no device type for dma-buf, IOSurface or PBO, which are precisely the zero-copy cases this library exists for.

Modules§

flags
Bit flags, as reported in TensorDesc::flags.
format
HAL pixel format, as reported in TensorDesc::format.
kind
Backing store kind, as reported in TensorDesc::kind.

Structs§

QuantDesc
Quantization metadata, in a form that can cross an .so boundary.
SendConstPtr
A *const T that may cross a PyCapsule.
SendPtr
A raw pointer that may cross a PyCapsule.
TensorDesc
The cross-package descriptor. Layout is part of the contract: it is #[repr(C)] and its size is pinned by test.

Constants§

ABI_VERSION
Protocol version, checked by TensorDyn::import_descriptor after the payload has already been read as this build’s TensorDesc.

Functions§

c_byte_strides
Row-major byte strides for shape, with the row dimension replaced by row_stride when one is recorded.
dtype_to_dtype
Map a wire [dtype] code back to a crate::DType. Inverse of [dtype_of]. None for a code this build does not recognise (e.g. a dtype added by a newer producer this build predates) — the caller rejects rather than guessing.
format_from_code
Map a format wire code back to a crate::PixelFormat. None for format::NONE or a code this build does not recognise (e.g. a format added by a newer producer).