|
Open3D (C++ API)
0.19.0
|
The common header of DLPack. More...
#include <stddef.h>#include <stdint.h>#include <fmt/core.h>#include <fmt/format.h>Go to the source code of this file.
Data Structures | |
| struct | DLPackVersion |
| The DLPack version. More... | |
| struct | DLDevice |
| A Device for Tensor and operator. More... | |
| struct | DLDataType |
| The data type the tensor can hold. The data type is assumed to follow the native endian-ness. An explicit error message should be raised when attempting to export an array with non-native endianness. More... | |
| struct | DLTensor |
| Plain C Tensor object, does not manage memory. More... | |
| struct | DLManagedTensor |
| C Tensor object, manage memory of DLTensor. This data structure is intended to facilitate the borrowing of DLTensor by another framework. It is not meant to transfer the tensor. When the borrowing framework doesn't need the tensor, it should call the deleter to notify the host that the resource is no longer needed. More... | |
| struct | DLManagedTensorVersioned |
| A versioned and managed C Tensor object, manage memory of DLTensor. More... | |
| struct | DLPackExchangeAPIHeader |
| DLPackExchangeAPI stable header. More... | |
| struct | DLPackExchangeAPI |
| Framework-specific function pointers table for DLPack exchange. More... | |
| struct | fmt::formatter< DLDeviceType > |
Namespaces | |
| fmt | |
Macros | |
| #define | DLPACK_EXTERN_C |
| Compatibility with C++. More... | |
| #define | DLPACK_MAJOR_VERSION 1 |
| The current major version of dlpack. More... | |
| #define | DLPACK_MINOR_VERSION 2 |
| The current minor version of dlpack. More... | |
| #define | DLPACK_DLL |
| DLPACK_DLL prefix for windows. More... | |
| #define | DLPACK_FLAG_BITMASK_READ_ONLY (1UL << 0UL) |
| bit mask to indicate that the tensor is read only. More... | |
| #define | DLPACK_FLAG_BITMASK_IS_COPIED (1UL << 1UL) |
| bit mask to indicate that the tensor is a copy made by the producer. More... | |
| #define | DLPACK_FLAG_BITMASK_IS_SUBBYTE_TYPE_PADDED (1UL << 2UL) |
| bit mask to indicate that whether a sub-byte type is packed or padded. More... | |
Typedefs | |
| typedef struct DLManagedTensor | DLManagedTensor |
| C Tensor object, manage memory of DLTensor. This data structure is intended to facilitate the borrowing of DLTensor by another framework. It is not meant to transfer the tensor. When the borrowing framework doesn't need the tensor, it should call the deleter to notify the host that the resource is no longer needed. More... | |
| typedef struct DLManagedTensorVersioned | DLManagedTensorVersioned |
| A versioned and managed C Tensor object, manage memory of DLTensor. More... | |
| typedef 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. More... | |
| typedef int(* | DLPackManagedTensorFromPyObjectNoSync) (void *py_object, DLManagedTensorVersioned **out) |
| Exports a PyObject* Tensor/NDArray to a DLManagedTensorVersioned. More... | |
| typedef int(* | DLPackDLTensorFromPyObjectNoSync) (void *py_object, DLTensor *out) |
| Exports a PyObject* Tensor/NDArray to a provided DLTensor. More... | |
| typedef int(* | DLPackCurrentWorkStream) (DLDeviceType device_type, int32_t device_id, void **out_current_stream) |
| Obtain the current work stream of a device. More... | |
| typedef int(* | DLPackManagedTensorToPyObjectNoSync) (DLManagedTensorVersioned *tensor, void **out_py_object) |
| Imports a DLManagedTensorVersioned to a PyObject* Tensor/NDArray. More... | |
| typedef struct DLPackExchangeAPIHeader | DLPackExchangeAPIHeader |
| DLPackExchangeAPI stable header. More... | |
| typedef struct DLPackExchangeAPI | DLPackExchangeAPI |
| Framework-specific function pointers table for DLPack exchange. More... | |
Enumerations | |
| enum | DLDeviceType { kDLCPU = 1 , kDLCUDA = 2 , kDLCUDAHost = 3 , kDLOpenCL = 4 , kDLVulkan = 7 , kDLMetal = 8 , kDLVPI = 9 , kDLROCM = 10 , kDLROCMHost = 11 , kDLExtDev = 12 , kDLCUDAManaged = 13 , kDLOneAPI = 14 , kDLWebGPU = 15 , kDLHexagon = 16 , kDLMAIA = 17 , kDLTrn = 18 } |
| The device type in DLDevice. More... | |
| enum | DLDataTypeCode { kDLInt = 0U , kDLUInt = 1U , kDLFloat = 2U , kDLOpaqueHandle = 3U , kDLBfloat = 4U , kDLComplex = 5U , kDLBool = 6U , kDLFloat8_e3m4 = 7U , kDLFloat8_e4m3 = 8U , kDLFloat8_e4m3b11fnuz = 9U , kDLFloat8_e4m3fn = 10U , kDLFloat8_e4m3fnuz = 11U , kDLFloat8_e5m2 = 12U , kDLFloat8_e5m2fnuz = 13U , kDLFloat8_e8m0fnu = 14U , kDLFloat6_e2m3fn = 15U , kDLFloat6_e3m2fn = 16U , kDLFloat4_e2m1fn = 17U } |
| The type code options DLDataType. More... | |
The common header of DLPack.
Copyright (c) 2017 - by Contributors
| #define DLPACK_DLL |
DLPACK_DLL prefix for windows.
| #define DLPACK_EXTERN_C |
Compatibility with C++.
| #define DLPACK_FLAG_BITMASK_IS_COPIED (1UL << 1UL) |
bit mask to indicate that the tensor is a copy made by the producer.
If set, the tensor is considered solely owned throughout its lifetime by the consumer, until the producer-provided deleter is invoked.
| #define DLPACK_FLAG_BITMASK_IS_SUBBYTE_TYPE_PADDED (1UL << 2UL) |
bit mask to indicate that whether a sub-byte type is packed or padded.
The default for sub-byte types (ex: fp4/fp6) is assumed packed. This flag can be set by the producer to signal that a tensor of sub-byte type is padded.
| #define DLPACK_FLAG_BITMASK_READ_ONLY (1UL << 0UL) |
bit mask to indicate that the tensor is read only.
| #define DLPACK_MAJOR_VERSION 1 |
The current major version of dlpack.
| #define DLPACK_MINOR_VERSION 2 |
The current minor version of dlpack.
| typedef struct DLManagedTensor DLManagedTensor |
C Tensor object, manage memory of DLTensor. This data structure is intended to facilitate the borrowing of DLTensor by another framework. It is not meant to transfer the tensor. When the borrowing framework doesn't need the tensor, it should call the deleter to notify the host that the resource is no longer needed.
| typedef struct DLManagedTensorVersioned DLManagedTensorVersioned |
A versioned and managed C Tensor object, manage memory of DLTensor.
This data structure is intended to facilitate the borrowing of DLTensor by another framework. It is not meant to transfer the tensor. When the borrowing framework doesn't need the tensor, it should call the deleter to notify the host that the resource is no longer needed.
| typedef int(* DLPackCurrentWorkStream) ( DLDeviceType device_type, int32_t device_id, void **out_current_stream) |
Obtain the current work stream of a device.
Obtain the current work stream of a device from the producer framework. For example, it should map to torch.cuda.current_stream in PyTorch.
When device_type is kDLCPU, the consumer do not have to query the stream and the producer can simply return NULL when queried. The consumer do not have to do anything on stream sync or setting. So CPU only framework can just provide a dummy implementation that always set out_current_stream[0] to NULL.
| device_type | The device type. |
| device_id | The device id. |
| out_current_stream | The output current work stream. |
| typedef int(* DLPackDLTensorFromPyObjectNoSync) ( void *py_object, DLTensor *out) |
Exports a PyObject* Tensor/NDArray to a provided DLTensor.
This function provides a faster interface for temporary, non-owning, exchange. The producer (implementor) still owns the memory of data, strides, shape. The liveness of the DLTensor and the data it views is only guaranteed until control is returned.
This function currently assumes that the producer (implementor) can fill in the DLTensor shape and strides without the need for temporary allocations.
This function does not perform any stream synchronization. The consumer should query DLPackCurrentWorkStream to get the current work stream and launch kernels on it.
This function is exposed by the framework through the DLPackExchangeAPI.
| py_object | The Python object to convert. Must have the same type as the one the DLPackExchangeAPI was discovered from. |
| out | The output DLTensor, whose space is pre-allocated on stack. |
| typedef struct DLPackExchangeAPI DLPackExchangeAPI |
Framework-specific function pointers table for DLPack exchange.
Additionally to __dlpack__() we define a C function table sharable by Python implementations via __c_dlpack_exchange_api__. This attribute must be set on the type as a Python integer compatible with PyLong_FromVoidPtr/PyLong_AsVoidPtr.
A consumer library may use a pattern such as:
Note that this must be defined on the type. The consumer should look up the attribute on the type and may cache the result for each unique type.
The precise API table is given by:
Guidelines for leveraging DLPackExchangeAPI:
There are generally two kinds of consumer needs for DLPack exchange:
Note that obj.__dlpack__() API should provide useful ways for N1. The primary focus of the current DLPackExchangeAPI is to enable faster exchange N0 with the support of the function pointer current_work_stream.
Array/Tensor libraries should statically create and initialize this structure then return a pointer to DLPackExchangeAPI as an int value in Tensor/Array. The DLPackExchangeAPI* must stay alive throughout the lifetime of the process.
One simple way to do so is to create a static instance of DLPackExchangeAPI within the framework and return a pointer to it. The following code shows an example to do so in C++. It should also be reasonably easy to do so in other languages.
| typedef struct DLPackExchangeAPIHeader DLPackExchangeAPIHeader |
DLPackExchangeAPI stable header.
| typedef 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.
Create a new DLManagedTensorVersioned within the context of the producer library. The allocation is defined via the prototype DLTensor.
This function is exposed by the framework through the DLPackExchangeAPI.
| prototype | The prototype DLTensor. Only the dtype, ndim, shape, and device fields are used. |
| out | The output DLManagedTensorVersioned. |
| error_ctx | Context for SetError. |
| SetError | The function to set the error. |
SetError may have to ensure the GIL is held since it will presumably set a Python error.| typedef int(* DLPackManagedTensorFromPyObjectNoSync) ( void *py_object, DLManagedTensorVersioned **out) |
Exports a PyObject* Tensor/NDArray to a DLManagedTensorVersioned.
This function does not perform any stream synchronization. The consumer should query DLPackCurrentWorkStream to get the current work stream and launch kernels on it.
This function is exposed by the framework through the DLPackExchangeAPI.
| py_object | The Python object to convert. Must have the same type as the one the DLPackExchangeAPI was discovered from. |
| typedef int(* DLPackManagedTensorToPyObjectNoSync) ( DLManagedTensorVersioned *tensor, void **out_py_object) |
Imports a DLManagedTensorVersioned to a PyObject* Tensor/NDArray.
Convert an owning DLManagedTensorVersioned* to the Python tensor of the producer (implementor) library with the correct type.
This function does not perform any stream synchronization.
This function is exposed by the framework through the DLPackExchangeAPI.
| tensor | The DLManagedTensorVersioned to convert the ownership of the tensor is stolen. |
| out_py_object | The output Python object. |
| enum DLDataTypeCode |
The type code options DLDataType.
| enum DLDeviceType |
The device type in DLDevice.