holoscan.payload
Registered Holoscan payload identities.
Submodules
Package Contents
Classes
Functions
Data
API
A registered payload identity token.
An n-dimensional array, interoperable with NumPy, CuPy, and PyTorch via DLPack and the array interface protocols. Wraps a DLPack managed tensor; instances are cheap handles that share the underlying memory and its access authority. Zero-copy imports are read-only; writable consumers must use an explicit allocation-and-copy path.
The NumPy __array_interface__ dict. Present only for host (CPU / pinned-host) tensors;
accessing it on a device tensor raises AttributeError. The dictionary carries no stream, so a
readiness-aware tensor first waits on the host for its producer’s work, such as a pinned-host
tensor written on a CUDA stream. A tensor written on the host returns at once.
The __cuda_array_interface__ dict. Present only for device (CUDA / managed) tensors; accessing
it on a host tensor raises AttributeError. Readiness-aware tensors are synchronized to the
legacy default stream before export because the returned dictionary reports stream=1.
Offset, in bytes, from the start of the underlying allocation to the tensor data (int).
Integer address of the tensor’s data pointer.
The DLDevice the tensor data resides on.
The DLDataType of the tensor elements.
Whether the tensor’s effective backing authority is permanently read-only.
Size of a single element, in bytes (int).
Total size of the elements, in bytes (int).
Number of dimensions (int).
Tuple of the tensor’s dimensions.
Total number of elements (int).
Tuple of the tensor’s strides, in bytes.
Export the tensor as a DLPack capsule (the array-API __dlpack__ protocol).
Parameters:
Consumer stream for synchronization. None/1 = legacy default stream, 2 = per-thread
default, -1 = no synchronization, a stream pointer as a positive integer, or an object with
callable __cuda_stream__() returning (0, stream_pointer). Ignored for host tensors.
Maximum supported DLPack (major, minor) version; a major >= 1 selects the versioned capsule.
Requested (device_type, device_id). A different device requests an explicit copy.
Request an owning contiguous copy before export. copy=False rejects a different
dl_device request.
Returns: PyCapsule
Raises:
BufferError: If the tensor is read-only andmax_versiondoes not select a versioned capsule. Legacy DLPack cannot carry read-only authority, so Holoscan rejects rather than widening access.
For imported CUDA storage, stream=2 and stream=-1 use conservative device retirement.
stream=-1 still skips producer-readiness ordering; the caller must establish it separately.
Prefer explicit streams for precise retirement.
Return the tensor’s (device_type, device_id) tuple (the array-API __dlpack_device__
protocol). Both values are ints. CUDA device tensors preserve the owning CUDA ordinal; CPU,
pinned-host, and managed tensors report device_id == 0.
Returns: tuple[int, int]
Create a Tensor from a tensor-like object (zero-copy).
References
.. [1] https://dmlc.github.io/dlpack/latest/python_spec.html .. [2] https://data-apis.org/array-api/latest/API_specification/generated/array_api.array.__dlpack__.html .. [3] https://numba.readthedocs.io/en/stable/cuda/cuda_array_interface.html .. [4] https://numpy.org/doc/stable/reference/arrays.interface.html
Parameters:
A NumPy array, CuPy array, PyTorch tensor, or any object supporting the DLPack protocol or an array interface.
CUDA import stream, as an integer or an object exposing __cuda_stream__().
Defaults to the activation stream inside compute() and the legacy default stream outside
a callback. DLPack producers negotiate directly on this stream. Array-interface and C exchange
producers retain their advertised readiness and order an explicitly supplied stream after it.
Integer 0 is invalid; use 1 or cupy.cuda.Stream.null for the default stream.
Returns: holoscan.Tensor
Examples:
Use with ctx.stream(): for CuPy work in compute(). Prefer as_=cupy on inputs or
cupy.from_dlpack(tensor) for conversion. Outside callbacks, keep external consumer streams
alive until their exported views are released.
Zero-copy imported storage is permanently read-only. The returned Tensor keeps its producer alive through queued consumer work, including release in a later callback and exception cleanup. Retained views may outlive the session. For work on the SDK callback stream, release a retained view in the operator that last used it, or synchronize that operator’s stream before release elsewhere, including another partition or cyclic garbage collection. Inside callbacks, keep a stream you create alive until the callback returns, and synchronize it before releasing a view you used on it. Keep that stream on the operator so it survives callback-exit completion recording. CUDA array-interface, no-sync C exchange, and no-sync or thread-relative DLPack exports require conservative device completion at final release.
Readiness is captured at import. Finish producing the array before importing it; after subsequent writes on other streams, import again or emit the array directly. Importing a read-only Tensor returns the same object; importing a writable Tensor creates a new read-only wrapper.
The interchange protocol is selected by precedence: the DLPack C exchange API [1]_ first, then the
Python DLPack protocol [1], [2], then __cuda_array_interface__ [3], then
__array_interface__ [4]. DLPack is preferred because it transfers ownership (so the imported
Tensor keeps its data alive independently of the source), has explicit stream-synchronization
semantics, and is the array-API-endorsed interchange path. The C exchange API avoids the per-call
Python capsule path when a producer type exposes __dlpack_c_exchange_api__.
Create a Tensor from an object supporting the DLPack protocol [1], [2] (zero-copy).
References
.. [1] https://dmlc.github.io/dlpack/latest/python_spec.html .. [2] https://data-apis.org/array-api/latest/API_specification/generated/array_api.array.__dlpack__.html
Parameters:
An object exposing __dlpack__ and __dlpack_device__.
CUDA import stream, as an integer or an object exposing __cuda_stream__().
Defaults to the activation stream inside compute() and the legacy default stream outside
a callback. stream=-1 is rejected because it supplies no readiness guarantee.
Integer 0 is invalid; use 1 or cupy.cuda.Stream.null for the default stream.
Returns: holoscan.Tensor
Examples:
Zero-copy imported storage is permanently read-only.
CUDA imports negotiate __dlpack__(stream=...) on the selected stream and record readiness
with a CUDA event. The Tensor retains the producer’s storage until its views and queued consumer
work have finished. SDK callbacks snapshot consumer completion before their streams are destroyed.
Outside callbacks, keep external consumer streams alive until their exported views are released.
For work on the SDK callback stream, release retained views in the operator that last used them,
or synchronize that operator’s stream before release elsewhere. Inside callbacks, keep a stream
you create alive until the callback returns, and synchronize it before releasing a view you used
on it. Keep that stream on the operator so it survives callback-exit completion recording.
Whether the tensor has a contiguous, row-major (C-contiguous) memory layout.
Returns: bool