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_v1 wrapping TensorDesc; 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§

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§

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).