Skip to main content

Module dlpack

Module dlpack 

Source
Expand description

DLPack protocol for zero-copy tensor exchange.

Implements __dlpack__ and __dlpack_device__ for arrays managed by this crate. DLPack is a standard open-source ABI used by PyTorch, JAX, TensorFlow, and other frameworks to exchange tensors without copying.

Reference: https://dmlc.github.io/dlpack/latest/

Structs§

DLDataType
DLPack data-type descriptor (ABI-compatible with the DLPack spec).
DLDevice
DLPack device descriptor.
DLManagedTensor
Managed DLPack tensor with associated deleter callback.
DLPackCapsule
Python class wrapping a DLPack-compatible tensor.
DLTensor
The core DLPack tensor structure (ABI-compatible).
DLTensorInfo
Structured information extracted from a validated DLTensor.

Enums§

DLDataTypeCode
Element type codes used in DLPack DLDataType.code.
DLDeviceType
Device type codes used by DLPack.
DlpackError
Errors produced by DLPack validation and conversion utilities.
JaxDeviceType
Known device types as reported by JAX DLPack tensors.

Constants§

DL_DEVICE_TYPE_TPU
Device type constant for JAX TPU tensors.

Functions§

array_from_dlpack_f32
Generic DLPack array construction — accepts f32 tensors from any framework.
array_from_dlpack_f64
Generic DLPack array construction — accepts f64 tensors from any framework.
check_tensor_contiguous
Check that a DLTensor’s strides represent a C-order (row-major) contiguous layout.
dlarray_from_torch_f32
Convert a raw DLTensor pointer (from a PyTorch DLPack capsule) to an ndarray dynamic array view of f32 elements.
dlarray_from_torch_f64
Convert a raw DLTensor pointer (from a PyTorch DLPack capsule) to an ndarray dynamic array view of f64 elements.
dlpack_from_slice
Create a DLTensor that borrows data and shape slices.
dlpack_to_vec_f64
Extract a Vec<f64> from a CPU float64 DLTensor.
jax_device_type
Classify the device reported by a DLTensor as a JaxDeviceType.
register_dlpack_module
Register DLPack classes into a PyO3 module.
validate_dlpack_tensor
Validate a DLTensor and extract structured metadata.
validate_jax_dlpack_tensor
Validate that a DLTensor is compatible with JAX DLPack interop.
validate_torch_dlpack_tensor
Validate that a DLTensor is compatible with PyTorch DLPack interop.