DLPack.DLPackModule
DLPack

The DLPack module provides a Julia interface to facilitate bidirectional data exchange of tensor objects between Julia and Python libraries such as JAX, CuPy, PyTorch, among others (all python libraries supporting the [DLPack protocol][1]).

It can share and wrap CPU and CUDA arrays, and supports interfacing through both PyCall and PythonCall.

[1]: https://data-apis.org/array-api/latest/designtopics/datainterchange.html

DLPack.DELETERConstant
DELETER

Wraps a pointer to the function that will get called whenever any array that is shared with another library gets deleted. By default, DELETER wraps a C_NULL, but DELETER[] is set to @cfunction(release, Cvoid, (Ptr{Cvoid},)) during module initialization.

DLPack.CapsuleType
Capsule

Data type for holding the shape, strides and associated DLManagedTensor of a Julia array being shared.

DLPack.DLManagerType
DLManager{T, N}

Wrapper around DLManagedTensor to pass the type T and dimension N in a type-inference friendly manner.

Base.unsafe_wrapMethod
unsafe_wrap(manager::DLManagedTensor, foreign)

Takes a DLManagedTensor and a corresponding foreign tensor, and returns a zero-copy array::AbstractArray pointing to the same data in foreign. For tensors with row-major ordering the resulting array will have all dimensions reversed.

This method is unsafe as it does not verify that manager and foreign actually point to the same data.

Base.unsafe_wrapMethod
unsafe_wrap(::Type{A}, ::Type{M}, manager::DLManagedTensor, foreign) where {
    T, N, A <: AbstractArray{T, N}, M <: MemoryLayout
}

Takes a DLManagedTensor and a corresponding foreign tensor, and tries to return a zero-copy array::AbstractArray{T, N} pointing to the same data in foreign in a type-inferable way. If there is a mismatch between any of the types T, N, or memory layout M and the matching properties of foreign, an error is thrown. For tensors with row-major ordering the resulting array will have all dimensions reversed.

This method is unsafe as it does not verify that manager and foreign actually point to the same data.

DLPack.from_dlpackMethod
from_dlpack(o)

If o follows the DLPack specification, it returns a zero-copy array::AbstractArray pointing to the same data in o. For arrays with row-major ordering the resulting array will have all dimensions reversed.

DLPack.jltypes_to_dtypesMethod
jltypes_to_dtypes()

Mapping from Julia's numeric types to their DLDataType representation.

DLPack.shareMethod
share(A::StridedArray)

Returns a Capsule holding an DLManagedTensor that can be exported to external libraries supporting the DLPack protocol. The resulting tensor will have all dimensions reversed with respect to the Julia array.