Open3D (C++ API)  0.11.0
DLPack.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 //
27 // This file is retrived from:
28 // https://github.com/dmlc/dlpack/blob/master/include/dlpack/dlpack.h
29 // Commit: 3ec0443, Feb 16 2020
30 //
31 // License:
32 // https://github.com/dmlc/dlpack/blob/master/LICENSE
33 //
34 // Open3D changes:
35 // No changes except for automatic style changed by clang-format.
36 
42 #ifndef DLPACK_DLPACK_H_
43 #define DLPACK_DLPACK_H_
44 
45 #ifdef __cplusplus
46 #define DLPACK_EXTERN_C extern "C"
47 #else
48 #define DLPACK_EXTERN_C
49 #endif
50 
52 #define DLPACK_VERSION 020
53 
55 #ifdef _WIN32
56 #ifdef DLPACK_EXPORTS
57 #define DLPACK_DLL __declspec(dllexport)
58 #else
59 #define DLPACK_DLL __declspec(dllimport)
60 #endif
61 #else
62 #define DLPACK_DLL
63 #endif
64 
65 #include <stddef.h>
66 #include <stdint.h>
67 
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71 
74 typedef enum {
76  kDLCPU = 1,
78  kDLGPU = 2,
85  kDLOpenCL = 4,
87  kDLVulkan = 7,
89  kDLMetal = 8,
91  kDLVPI = 9,
93  kDLROCM = 10,
99  kDLExtDev = 12,
100 } DLDeviceType;
101 
105 typedef struct {
110 } DLContext;
111 
115 typedef enum {
116  kDLInt = 0U,
117  kDLUInt = 1U,
118  kDLFloat = 2U,
119  kDLBfloat = 4U,
121 
130 typedef struct {
136  uint8_t code;
140  uint8_t bits;
142  uint16_t lanes;
143 } DLDataType;
144 
148 typedef struct {
168  void* data;
172  int ndim;
176  int64_t* shape;
181  int64_t* strides;
184 } DLTensor;
185 
193 typedef struct DLManagedTensor {
199  void* manager_ctx;
205  void (*deleter)(struct DLManagedTensor* self);
207 #ifdef __cplusplus
208 } // DLPACK_EXTERN_C
209 #endif
210 #endif // DLPACK_DLPACK_H_
Definition: DLPack.h:119
Metal for Apple GPU.
Definition: DLPack.h:89
C Tensor object, manage memory of DLTensor. This data structure is intended to facilitate the borrowi...
Definition: DLPack.h:193
CUDA GPU device.
Definition: DLPack.h:78
int64_t * shape
The shape of the tensor.
Definition: DLPack.h:176
Pinned CUDA GPU device by cudaMallocHost.
Definition: DLPack.h:83
struct DLManagedTensor DLManagedTensor
C Tensor object, manage memory of DLTensor. This data structure is intended to facilitate the borrowi...
void * manager_ctx
the context of the original host framework of DLManagedTensor in which DLManagedTensor is used in the...
Definition: DLPack.h:199
DLDataTypeCode
The type code options DLDataType.
Definition: DLPack.h:115
uint16_t lanes
Number of lanes in the type, used for vector types.
Definition: DLPack.h:142
int device_id
The device index.
Definition: DLPack.h:109
DLDataType dtype
The data type of the pointer.
Definition: DLPack.h:174
Definition: DLPack.h:116
int64_t * strides
strides of the tensor (in number of elements, not bytes) can be NULL, indicating tensor is compact an...
Definition: DLPack.h:181
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:349
Verilog simulator buffer.
Definition: DLPack.h:91
ROCm GPUs for AMD GPUs.
Definition: DLPack.h:93
int ndim
Number of dimensions.
Definition: DLPack.h:172
void * data
The opaque data pointer points to the allocated data. This will be CUDA device pointer or cl_mem hand...
Definition: DLPack.h:168
const char const char value recording_handle imu_sample void
Definition: K4aPlugin.cpp:256
A Device context for Tensor and operator.
Definition: DLPack.h:105
DLDeviceType device_type
The device type used in the device.
Definition: DLPack.h:107
uint8_t bits
Number of bits, common choices are 8, 16, 32.
Definition: DLPack.h:140
DLDeviceType
The device type in DLContext.
Definition: DLPack.h:74
DLTensor dl_tensor
DLTensor which is being memory managed.
Definition: DLPack.h:195
Reserved extension device type, used for quickly test extension device The semantics can differ depen...
Definition: DLPack.h:99
uint64_t byte_offset
The offset in bytes to the beginning pointer to data.
Definition: DLPack.h:183
DLContext ctx
The device context of the tensor.
Definition: DLPack.h:170
The data type the tensor can hold.
Definition: DLPack.h:130
uint8_t code
Type code of base types. We keep it uint8_t instead of DLDataTypeCode for minimal memory footprint...
Definition: DLPack.h:136
Definition: DLPack.h:118
void(* deleter)(struct DLManagedTensor *self)
Destructor signature void (*)(void*) - this should be called to destruct manager_ctx which holds the ...
Definition: DLPack.h:205
Definition: DLPack.h:117
Vulkan buffer for next generation graphics.
Definition: DLPack.h:87
OpenCL devices.
Definition: DLPack.h:85
Plain C Tensor object, does not manage memory.
Definition: DLPack.h:148
CPU device.
Definition: DLPack.h:76