Skip to main content

Crate dlpk

Crate dlpk 

Source
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:

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 behind Arc<Mutex<_>> and Arc<RwLock<_>> with DLPack, enforcing Rust’s borrowing rules at runtime through the locks.
  • [ndarray]: enable conversion from and to ndarray::Array
  • [pyo3]: enable passing data from and to python, following the dlpack protocol (the data is passed through a PyCapsule object).

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.h header at version 1.3; and contains types suitable for use in C FFI.
vec
Conversion of standard Vec and slices to and from dlpack.

Structs§

DLPackTensor
A managed DLPack tensor, carrying ownership of the data.
DLPackTensorRef
A reference to a DLPack tensor, with data borrowed from some owner, potentially in another language.
DLPackTensorRefMut
A mutable reference to a DLPack tensor, with data borrowed from some owner, potentially in another language.
ReadOnly
Small wrapper type to mark a tensor as read-only when there is a choice between a read-only and a read-write implementation.
ReadWrite
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§

CastError
Error that can happen when casting a DLPack pointer to a Rust pointer

Traits§

DLPackPointerCast
Trait to cast a DLPack pointer to a Rust pointer
GetDLPackDataType
Trait to get the DLPack datatype corresponding to a Rust datatype