Skip to main content

Python package Conda Version

pydlpack

PyDLPack is a Python library for exchanging data between different array libraries using [DLPack: Open In Memory Tensor Structure]((https://github.com/dmlc/dlpack/). The provider library does not need to implement the DLPack support, it will be sufficent if the provider library implements one of the following protocols:

Array Interface Protocol, version 2 support can be provided on request.

Currently, the package is tested with the following consumers

using the following provider objects with devices:

Install

Basic usage

>>> from dlpack import asdlpack
>>> import torch
>>> dl = asdlpack(b"Hello!")
>>> torch.from_dlpack(dl)
tensor([ 72, 101, 108, 108, 111,  33], dtype=torch.uint8)

that is, the Python package dlpack provides a function asdlpack that input can be any object that implements one of the above mentioned protocols and it will return a light-weight DLPackObject instance which implements the DLPack protocol methods __dlpack__(stream=None) and __dlpack_device__(). This DLPackObject instance can be used as an argument to a consumer.from_dlpack(obj) function of any DLPack-compatible consumer library (a partial list of such libraries is listed above). For example:

>>> from dlpack import asdlpack
>>> import numba.cuda
>>> import numpy
>>> arr = numba.cuda.to_device(numpy.array([[1, 2], [3, 4]]))
>>> arr
<numba.cuda.cudadrv.devicearray.DeviceNDArray object at 0x7fbed9c548b0>
>>> dl = asdlpack(arr)
>>> import torch
>>> torch.from_dlpack(dl)
tensor([[1, 2],
        [3, 4]], device='cuda:0')
>>> import jax
>>> jax.numpy.from_dlpack(dl)
Array([[1, 2],
       [3, 4]], dtype=int32)
>>> import cupy
>>> cupy.from_dlpack(dl)
array([[1, 2],
       [3, 4]])

that is, the DLPackObject instance can be efficiently used for exchanging the CUDA buffer created using Numba to_device functionality with different consumer objects such as torch.Tensor, jax.Array, and cupy.ndarray while all these array objects share the same CUDA memory.

Testing

It is a non-trivial task to install all dlpack-compatible libraries into the same environment. Therefore, dlpack tests are included the dlpack package so that one can import dlpack and run the tests on DLPack-compatible objects that are available in a particular environment. For example:

>>> import dlpack.tests
>>> dlpack.tests.run()

Metadata

Release files for pydlpack 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydlpack 0.2.1
File Size Uploaded Provenance Actions
pydlpack-0.2.1.tar.gz 22.2 kB Without provenance Details for pydlpack-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pydlpack 0.2.1
File Interpreter ABI Platform Actions
pydlpack-0.2.1-py3-none-any.whl Python 3 none any Details for pydlpack-0.2.1-py3-none-any.whl

Total release size: 41.6 kB

Release files / pydlpack-0.2.1.tar.gz

Download URL pydlpack-0.2.1.tar.gz
Size 22.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0b3b1b0dd2292fac72a020b8c191fdaf32be6f9471ec696c88f753fbc042c28f
BLAKE2b-256 checksum
How to use checksums
872348c707f166468bf116740b2922b5ff745fdfd72bb40304a0358ce495d4b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / pydlpack-0.2.1-py3-none-any.whl

Download URL pydlpack-0.2.1-py3-none-any.whl
Size 19.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b42ef189511e5ab4e1eafa42c5f0825d2b4349518020a3a9c33390890deb7cb2
BLAKE2b-256 checksum
How to use checksums
3df8ae765c0f3fac5f10119d51c9b82002ea709c1899190c4743e0b124e82149
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Security for pydlpack 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page