dlpackrs
This crate provides a safe idiomatic Rust binding to DLPack which is the standard in-memory, (mostly) hardware agnosnic data exchange interface and is recognized by major Deep Learning frameworks such as PyTorch, Tensorflow, MXNet, TVM and major array processing frameworks such as NumPy and CuPy. An important feature of this standard is to provide zero-cost tensor conversion across frameworks on a particular supported hardware.
The Minimum Supported Rust Version (MSRV) is the stable toolchain 1.57.0.
Usage
There are two usages related to where the owner of the underlying data / storage of a tensor resides. The main distinction is when the underlying data gets dropped and which framework is responsible for it.
Rust as the owner
In this case, ManagedTensor is built from ManagedTensorProxy which is the same proxy for ffi::DLManagedTensor.
Non-Rust owner
In this case, either ffi::DLTensor or its (invariant) Rust wrapper Tensor can be used.
Example
For when ownership is not concerned, one can use Tensor. Here is an example on how the bi-directional converion
can happen at zero-cost.
And when ownership is concerned, one can use the ManagedTensor. Here is an example on how the conversion
can happen at zero-cost.
See the complete examples/sample where the above cases have been simulated for the Rust ndarray conversion.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.