Open3D (C++ API)  0.18.0+fcf98ee
DLPack.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 //
8 // This file is retrieved from:
9 // https://github.com/dmlc/dlpack/blob/master/include/dlpack/dlpack.h
10 // Commit: 3ec0443, Feb 16 2020
11 //
12 // License:
13 // https://github.com/dmlc/dlpack/blob/master/LICENSE
14 //
15 // Open3D changes:
16 // No changes except for automatic style changed by clang-format.
17 
23 #ifndef DLPACK_DLPACK_H_
24 #define DLPACK_DLPACK_H_
25 
26 #ifdef __cplusplus
27 #define DLPACK_EXTERN_C extern "C"
28 #else
29 #define DLPACK_EXTERN_C
30 #endif
31 
33 #define DLPACK_VERSION 020
34 
36 #ifdef _WIN32
37 #ifdef DLPACK_EXPORTS
38 #define DLPACK_DLL __declspec(dllexport)
39 #else
40 #define DLPACK_DLL __declspec(dllimport)
41 #endif
42 #else
43 #define DLPACK_DLL
44 #endif
45 
46 #include <stddef.h>
47 #include <stdint.h>
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
55 typedef enum {
57  kDLCPU = 1,
59  kDLGPU = 2,
66  kDLOpenCL = 4,
68  kDLVulkan = 7,
70  kDLMetal = 8,
72  kDLVPI = 9,
74  kDLROCM = 10,
80  kDLExtDev = 12,
81 } DLDeviceType;
82 
86 typedef struct {
90  int device_id;
91 } DLContext;
92 
96 typedef enum {
97  kDLInt = 0U,
98  kDLUInt = 1U,
99  kDLFloat = 2U,
100  kDLBfloat = 4U,
102 
111 typedef struct {
117  uint8_t code;
121  uint8_t bits;
123  uint16_t lanes;
124 } DLDataType;
125 
129 typedef struct {
149  void* data;
153  int ndim;
157  int64_t* shape;
162  int64_t* strides;
165 } DLTensor;
166 
174 typedef struct DLManagedTensor {
180  void* manager_ctx;
186  void (*deleter)(struct DLManagedTensor* self);
188 #ifdef __cplusplus
189 } // DLPACK_EXTERN_C
190 #endif
191 
192 #include <fmt/core.h>
193 #include <fmt/format.h>
194 
195 namespace fmt {
196 
197 template <>
198 struct formatter<DLDeviceType> {
199  template <typename FormatContext>
200  auto format(const DLDeviceType& c, FormatContext& ctx) const
201  -> decltype(ctx.out()) {
202  const char* text = nullptr;
203  switch (c) {
204  case kDLCPU:
205  text = "kDLCPU";
206  break;
207  case kDLGPU:
208  text = "kDLGPU";
209  break;
210  case kDLCPUPinned:
211  text = "kDLCPUPinned";
212  break;
213  case kDLOpenCL:
214  text = "kDLOpenCL";
215  break;
216  case kDLVulkan:
217  text = "kDLVulkan";
218  break;
219  case kDLMetal:
220  text = "kDLMetal";
221  break;
222  case kDLVPI:
223  text = "kDLVPI";
224  break;
225  case kDLROCM:
226  text = "kDLROCM";
227  break;
228  case kDLExtDev:
229  text = "kDLExtDev";
230  break;
231  }
232  return format_to(ctx.out(), text);
233  }
234 
235  template <typename ParseContext>
236  constexpr auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
237  return ctx.begin();
238  }
239 };
240 
241 } // namespace fmt
242 
243 #endif // DLPACK_DLPACK_H_
DLDataTypeCode
The type code options DLDataType.
Definition: DLPack.h:96
@ kDLInt
Definition: DLPack.h:97
@ kDLBfloat
Definition: DLPack.h:100
@ kDLFloat
Definition: DLPack.h:99
@ kDLUInt
Definition: DLPack.h:98
DLDeviceType
The device type in DLContext.
Definition: DLPack.h:55
@ kDLVulkan
Vulkan buffer for next generation graphics.
Definition: DLPack.h:68
@ kDLMetal
Metal for Apple GPU.
Definition: DLPack.h:70
@ kDLCPUPinned
Pinned CUDA GPU device by cudaMallocHost.
Definition: DLPack.h:64
@ kDLOpenCL
OpenCL devices.
Definition: DLPack.h:66
@ kDLCPU
CPU device.
Definition: DLPack.h:57
@ kDLROCM
ROCm GPUs for AMD GPUs.
Definition: DLPack.h:74
@ kDLGPU
CUDA GPU device.
Definition: DLPack.h:59
@ kDLExtDev
Reserved extension device type, used for quickly test extension device The semantics can differ depen...
Definition: DLPack.h:80
@ kDLVPI
Verilog simulator buffer.
Definition: DLPack.h:72
struct DLManagedTensor DLManagedTensor
C Tensor object, manage memory of DLTensor. This data structure is intended to facilitate the borrowi...
Definition: DLPack.h:195
const char const char value recording_handle imu_sample void
Definition: K4aPlugin.cpp:250
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample uint64_t
Definition: K4aPlugin.cpp:343
A Device context for Tensor and operator.
Definition: DLPack.h:86
int device_id
The device index.
Definition: DLPack.h:90
DLDeviceType device_type
The device type used in the device.
Definition: DLPack.h:88
The data type the tensor can hold.
Definition: DLPack.h:111
uint16_t lanes
Number of lanes in the type, used for vector types.
Definition: DLPack.h:123
uint8_t bits
Number of bits, common choices are 8, 16, 32.
Definition: DLPack.h:121
uint8_t code
Type code of base types. We keep it uint8_t instead of DLDataTypeCode for minimal memory footprint,...
Definition: DLPack.h:117
C Tensor object, manage memory of DLTensor. This data structure is intended to facilitate the borrowi...
Definition: DLPack.h:174
void(* deleter)(struct DLManagedTensor *self)
Destructor signature void (*)(void*) - this should be called to destruct manager_ctx which holds the ...
Definition: DLPack.h:186
DLTensor dl_tensor
DLTensor which is being memory managed.
Definition: DLPack.h:176
void * manager_ctx
the context of the original host framework of DLManagedTensor in which DLManagedTensor is used in the...
Definition: DLPack.h:180
Plain C Tensor object, does not manage memory.
Definition: DLPack.h:129
int64_t * strides
strides of the tensor (in number of elements, not bytes) can be NULL, indicating tensor is compact an...
Definition: DLPack.h:162
DLContext ctx
The device context of the tensor.
Definition: DLPack.h:151
uint64_t byte_offset
The offset in bytes to the beginning pointer to data.
Definition: DLPack.h:164
void * data
The opaque data pointer points to the allocated data. This will be CUDA device pointer or cl_mem hand...
Definition: DLPack.h:149
int64_t * shape
The shape of the tensor.
Definition: DLPack.h:157
int ndim
Number of dimensions.
Definition: DLPack.h:153
DLDataType dtype
The data type of the pointer.
Definition: DLPack.h:155
auto format(const DLDeviceType &c, FormatContext &ctx) const -> decltype(ctx.out())
Definition: DLPack.h:200
constexpr auto parse(ParseContext &ctx) -> decltype(ctx.begin())
Definition: DLPack.h:236