Expand description
DLPack integration for Rust.
This crate provides wrappers around the DLPack C API, allowing to exchange tensors with other libraries that support DLPack, such as PyTorch, TensorFlow, MXNet, CuPy, JAX, etc.
The C API is available in the sys module, and the following higher-level
wrappers are provided:
DLPackTensor: an owned DLPack tensorDLPackTensorRef: a borrowed DLPack tensor (immutable)DLPackTensorRefMut: a borrowed DLPack tensor (mutable)
We also provide tools to convert from and to other rust types, using the
TryFrom trait. Conversions to and from std::vec::Vec and slices are
always enabled, in the [vec] module.
§Features
- [
sync]: enable sharing data behindArc<Mutex<_>>andArc<RwLock<_>>with DLPack, enforcing Rust’s borrowing rules at runtime through the locks. - [
ndarray]: enable conversion from and tondarray::Array - [
pyo3]: enable passing data from and to python, following the dlpack protocol (the data is passed through aPyCapsuleobject).
Re-exports§
pub use self::sys::DLDataType;pub use self::sys::DLDataTypeCode;pub use self::sys::DLDevice;pub use self::sys::DLDeviceType;pub use self::sys::DLPackVersion;
Modules§
- sys
- This module contains the low-level API for dlpack. It was manually
translated from
dlpack.hheader at version 1.3; and contains types suitable for use in C FFI. - vec
- Conversion of standard
Vecand slices to and from dlpack.
Structs§
- DLPack
Tensor - A managed DLPack tensor, carrying ownership of the data.
- DLPack
Tensor Ref - A reference to a DLPack tensor, with data borrowed from some owner, potentially in another language.
- DLPack
Tensor RefMut - A mutable reference to a DLPack tensor, with data borrowed from some owner, potentially in another language.
- Read
Only - Small wrapper type to mark a tensor as read-only when there is a choice between a read-only and a read-write implementation.
- Read
Write - Small wrapper type to mark a tensor as read-write when there is a choice between a read-only and a read-write implementation.
Enums§
- Cast
Error - Error that can happen when casting a DLPack pointer to a Rust pointer
Traits§
- DLPack
Pointer Cast - Trait to cast a DLPack pointer to a Rust pointer
- GetDL
Pack Data Type - Trait to get the DLPack datatype corresponding to a Rust datatype