24#ifndef DLPACK_DLPACK_H_
25#define DLPACK_DLPACK_H_
31#define DLPACK_EXTERN_C extern "C"
33#define DLPACK_EXTERN_C
37#define DLPACK_MAJOR_VERSION 1
40#define DLPACK_MINOR_VERSION 2
45#define DLPACK_DLL __declspec(dllexport)
47#define DLPACK_DLL __declspec(dllimport)
90typedef enum : int32_t {
338#define DLPACK_FLAG_BITMASK_READ_ONLY (1UL << 0UL)
346#define DLPACK_FLAG_BITMASK_IS_COPIED (1UL << 1UL)
354#define DLPACK_FLAG_BITMASK_IS_SUBBYTE_TYPE_PADDED (1UL << 2UL)
433 void (*SetError)(
void* error_ctx,
515 void** out_current_stream
676#include <fmt/format.h>
682 template <
typename FormatContext>
684 FormatContext& ctx)
const ->
decltype(ctx.out()) {
685 const char* text =
nullptr;
694 text =
"kDLCUDAHost";
712 text =
"kDLROCMHost";
718 text =
"kDLCUDAManaged";
736 return format_to(ctx.out(), text);
739 template <
typename ParseContext>
740 constexpr auto parse(ParseContext& ctx) ->
decltype(ctx.begin()) {
DLDataTypeCode
The type code options DLDataType.
Definition DLPack.h:160
@ kDLFloat8_e5m2fnuz
Definition DLPack.h:189
@ kDLInt
signed integer
Definition DLPack.h:162
@ kDLComplex
complex number (C/C++/Python layout: compact struct per complex number)
Definition DLPack.h:179
@ kDLFloat8_e4m3b11fnuz
Definition DLPack.h:185
@ kDLFloat8_e4m3
Definition DLPack.h:184
@ kDLFloat6_e2m3fn
FP6 data types Setting bits != 6 is currently unspecified, and the producer must ensure it is set whi...
Definition DLPack.h:196
@ kDLFloat8_e3m4
FP8 data types.
Definition DLPack.h:183
@ kDLFloat8_e5m2
Definition DLPack.h:188
@ kDLFloat4_e2m1fn
FP4 data types Setting bits != 4 is currently unspecified, and the producer must ensure it is set whi...
Definition DLPack.h:203
@ kDLFloat8_e8m0fnu
Definition DLPack.h:190
@ kDLBfloat
bfloat16
Definition DLPack.h:174
@ kDLFloat8_e4m3fn
Definition DLPack.h:186
@ kDLFloat8_e4m3fnuz
Definition DLPack.h:187
@ kDLFloat
IEEE floating point.
Definition DLPack.h:166
@ kDLUInt
unsigned integer
Definition DLPack.h:164
@ kDLOpaqueHandle
Opaque handle type, reserved for testing purposes. Frameworks need to agree on the handle data type f...
Definition DLPack.h:172
@ kDLBool
boolean
Definition DLPack.h:181
@ kDLFloat6_e3m2fn
Definition DLPack.h:197
int(* DLPackCurrentWorkStream)(DLDeviceType device_type, int32_t device_id, void **out_current_stream)
Obtain the current work stream of a device.
Definition DLPack.h:512
int(* DLPackManagedTensorToPyObjectNoSync)(DLManagedTensorVersioned *tensor, void **out_py_object)
Imports a DLManagedTensorVersioned to a PyObject* Tensor/NDArray.
Definition DLPack.h:535
int(* DLPackManagedTensorAllocator)(DLTensor *prototype, DLManagedTensorVersioned **out, void *error_ctx, void(*SetError)(void *error_ctx, const char *kind, const char *message))
Request a producer library to create a new tensor.
Definition DLPack.h:429
int(* DLPackDLTensorFromPyObjectNoSync)(void *py_object, DLTensor *out)
Exports a PyObject* Tensor/NDArray to a provided DLTensor.
Definition DLPack.h:486
DLDeviceType
The device type in DLDevice.
Definition DLPack.h:92
@ kDLTrn
AWS Trainium.
Definition DLPack.h:140
@ kDLVulkan
Vulkan buffer for next generation graphics.
Definition DLPack.h:105
@ kDLMetal
Metal for Apple GPU.
Definition DLPack.h:107
@ kDLCUDAManaged
CUDA managed/unified memory allocated by cudaMallocManaged.
Definition DLPack.h:125
@ kDLCUDA
CUDA GPU device.
Definition DLPack.h:97
@ kDLCUDAHost
Pinned CUDA CPU memory by cudaMallocHost.
Definition DLPack.h:101
@ kDLOneAPI
Unified shared memory allocated on a oneAPI non-partititioned device. Call to oneAPI runtime is requi...
Definition DLPack.h:132
@ kDLWebGPU
GPU support for next generation WebGPU standard.
Definition DLPack.h:134
@ kDLOpenCL
OpenCL devices.
Definition DLPack.h:103
@ kDLROCMHost
Pinned ROCm CPU memory allocated by hipMallocHost.
Definition DLPack.h:115
@ kDLHexagon
Qualcomm Hexagon DSP.
Definition DLPack.h:136
@ kDLCPU
CPU device.
Definition DLPack.h:95
@ kDLMAIA
Microsoft MAIA devices.
Definition DLPack.h:138
@ kDLROCM
ROCm GPUs for AMD GPUs.
Definition DLPack.h:111
@ kDLExtDev
Reserved extension device type, used for quickly test extension device The semantics can differ depen...
Definition DLPack.h:121
@ kDLVPI
Verilog simulator buffer.
Definition DLPack.h:109
int(* DLPackManagedTensorFromPyObjectNoSync)(void *py_object, DLManagedTensorVersioned **out)
Exports a PyObject* Tensor/NDArray to a DLManagedTensorVersioned.
Definition DLPack.h:456
The data type the tensor can hold. The data type is assumed to follow the native endian-ness....
Definition DLPack.h:226
uint16_t lanes
Number of lanes in the type, used for vector types.
Definition DLPack.h:238
uint8_t bits
Number of bits, common choices are 8, 16, 32.
Definition DLPack.h:236
uint8_t code
Type code of base types. We keep it uint8_t instead of DLDataTypeCode for minimal memory footprint,...
Definition DLPack.h:232
A Device for Tensor and operator.
Definition DLPack.h:146
DLDeviceType device_type
The device type used in the device.
Definition DLPack.h:148
int32_t device_id
The device index. For vanilla CPU memory, pinned memory, or managed memory, this is set to 0.
Definition DLPack.h:154
C Tensor object, manage memory of DLTensor. This data structure is intended to facilitate the borrowi...
Definition DLPack.h:319
void(* deleter)(struct DLManagedTensor *self)
Destructor - this should be called to destruct the manager_ctx which backs the DLManagedTensor....
Definition DLPack.h:332
DLTensor dl_tensor
DLTensor which is being memory managed.
Definition DLPack.h:321
void * manager_ctx
the context of the original host framework of DLManagedTensor in which DLManagedTensor is used in the...
Definition DLPack.h:325
A versioned and managed C Tensor object, manage memory of DLTensor.
Definition DLPack.h:366
DLPackVersion version
The API and ABI version of the current managed Tensor.
Definition DLPack.h:370
void * manager_ctx
the context of the original host framework.
Definition DLPack.h:377
void(* deleter)(struct DLManagedTensorVersioned *self)
Destructor.
Definition DLPack.h:386
DLTensor dl_tensor
DLTensor which is being memory managed.
Definition DLPack.h:400
uint64_t flags
Additional bitmask flags information about the tensor.
Definition DLPack.h:398
Framework-specific function pointers table for DLPack exchange.
Definition DLPack.h:634
DLPackExchangeAPIHeader header
The header that remains stable across versions.
Definition DLPack.h:638
DLPackManagedTensorToPyObjectNoSync managed_tensor_to_py_object_no_sync
Producer function pointer for DLPackManagedTensorToPyObject This function must be not NULL.
Definition DLPack.h:656
DLPackCurrentWorkStream current_work_stream
Producer function pointer for DLPackCurrentWorkStream This function must be not NULL.
Definition DLPack.h:668
DLPackManagedTensorAllocator managed_tensor_allocator
Producer function pointer for DLPackManagedTensorAllocator This function must not be NULL.
Definition DLPack.h:644
DLPackManagedTensorFromPyObjectNoSync managed_tensor_from_py_object_no_sync
Producer function pointer for DLPackManagedTensorFromPyObject This function must be not NULL.
Definition DLPack.h:650
DLPackDLTensorFromPyObjectNoSync dltensor_from_py_object_no_sync
Producer function pointer for DLPackDLTensorFromPyObject This function can be NULL when the producer ...
Definition DLPack.h:662
The DLPack version.
Definition DLPack.h:79
uint32_t minor
DLPack minor version.
Definition DLPack.h:83
uint32_t major
DLPack major version.
Definition DLPack.h:81
Plain C Tensor object, does not manage memory.
Definition DLPack.h:244
int32_t ndim
Number of dimensions.
Definition DLPack.h:278
int64_t * strides
strides of the tensor (in number of elements, not bytes), can not be NULL if ndim !...
Definition DLPack.h:300
DLDevice device
The device of the tensor.
Definition DLPack.h:276
uint64_t byte_offset
The offset in bytes to the beginning pointer to data.
Definition DLPack.h:302
void * data
The data pointer points to the allocated data. This will be CUDA device pointer or cl_mem handle in O...
Definition DLPack.h:274
int64_t * shape
The shape of the tensor.
Definition DLPack.h:286
DLDataType dtype
The data type of the pointer.
Definition DLPack.h:280