SunDoge/dlpark
SunDoge/dlpark has 66 GitHub stars and 5 forks. GitHot measured 0 stars in 24 hours, 0 in 7 days, and 0 in 15 days. Last checked 2026-11-15 20:54 UTC. Last push 2026-10-26.
What you can do
- pyo3 - Python capsule protocol and C Exchange API - zero-copy protocol layer
- image - ImageBuffer producer and consumer - zero-copy
- ndarray - owned arrays and borrowed views - zero-copy
- half - f16 and bf16 element types - —
Measured star growth
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- Update delayed
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
About
Pure Rust DLPack implementation for zero-copy tensor interoperability
Machine LearningREADME.md
Originaldlpark
A pure Rust implementation of DLPack for zero-copy tensor exchange. It supports the legacy and versioned ABIs, Rust container adapters, the Python Array API protocol, and DLPack 1.3 C Exchange.
Installation
No features are enabled by default. Enable only the integrations you use:
cargo add dlpark --features "ndarray half"
cargo add dlpark --features "pyo3 image"
cargo add dlpark --features "cudarc"
cargo add dlpark --features "safetensors"
Quick start
A producer owns its container through the managed tensor's deleter. The versioned ABI is recommended for new code:
use dlpark::{allocation::dynamic, ffi::DLManagedTensorVersioned, versioned};
use ndarray::arr2;
let initialized: dynamic::Initialized<DLManagedTensorVersioned> =
Box::new(arr2(&[[1_i32, 2, 3], [4, 5, 6]])).try_into()?;
let dlpack: versioned::Dlpack = unsafe { initialized.finish() };
let tensor = dlpack.validate()?;
assert_eq!(tensor.shape(), &[2, 3]);
assert_eq!(unsafe { tensor.cpu_slice::<i32>()? }, &[1, 2, 3, 4, 5, 6]);
# Ok::<(), Box<dyn std::error::Error>>(())
finish is unsafe because the caller must ensure that the completed
descriptor obeys the DLPack lifetime, pointer, layout, and flag requirements.
Imported descriptors should be checked with Managed::validate() before their
metadata is used.
Features
| Feature | Integration | Data movement |
|---|---|---|
pyo3 |
Python capsule protocol and C Exchange API | zero-copy protocol layer |
image |
ImageBuffer producer and consumer |
zero-copy |
ndarray |
owned arrays and borrowed views | zero-copy |
half |
f16 and bf16 element types |
— |
candle |
CPU Tensor |
zero-copy export, copying import |
cudarc |
CudaSlice<T> |
zero-copy |
safetensors |
file/mmap export and serialization views | zero-copy |
Raw CUDA and Metal runtime policy remains application-specific. The
demos/cuda-python and demos/metal-python projects show complete native
buffer implementations.
Guides
- Ownership, validation, metadata, and versioning
- Python import, reusable export, streams, and C Exchange
- Interop backend behavior
- Development and binding regeneration
Runnable demos live under demos/:
cuda-python: CuPy and Torch exchange through a Rust-owned CUDA buffer.metal-python: MLX exchange through a sharedMTLBuffer.image-python: Torch exchange withimage::RgbImage.ndarray-candle: anndarray → DLPack → candle → DLPack → ndarrayround trip.
The API reference is available on docs.rs.