DLPack.DLPack
— ModuleDLPack
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.DELETER
— ConstantDELETER
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.Capsule
— TypeCapsule
Data type for holding the shape, strides and associated DLManagedTensor
of a Julia array being shared.
DLPack.DLDataType
— TypeDLDataType
See dtypes_to_jltypes
for its mapping to Julia types.
DLPack.DLManagedTensor
— TypeDLManagedTensor
This is the main C-API data structure of the DLPack protocol.
DLPack.DLManager
— TypeDLManager{T, N}
Wrapper around DLManagedTensor
to pass the type T
and dimension N
in a type-inference friendly manner.
Base.unsafe_wrap
— Methodunsafe_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_wrap
— Methodunsafe_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.dtypes_to_jltypes
— Methoddtypes_to_jltypes()
Inverse mapping of jltypes_to_dtypes
.
DLPack.from_dlpack
— Methodfrom_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_dtypes
— Methodjltypes_to_dtypes()
Mapping from Julia's numeric types to their DLDataType
representation.
DLPack.share
— Methodshare(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.