Caffe2 - C++ API
A deep learning, cross platform ML framework
dlpack.h
Go to the documentation of this file.
1 
6 #ifndef DLPACK_DLPACK_H_
7 #define DLPACK_DLPACK_H_
8 
9 #ifdef __cplusplus
10 #define DLPACK_EXTERN_C extern "C"
11 #else
12 #define DLPACK_EXTERN_C
13 #endif
14 
16 #define DLPACK_VERSION 010
17 
19 #ifdef _WIN32
20 #ifdef DLPACK_EXPORTS
21 #define DLPACK_DLL __declspec(dllexport)
22 #else
23 #define DLPACK_DLL __declspec(dllimport)
24 #endif
25 #else
26 #define DLPACK_DLL
27 #endif
28 
29 #include <stdint.h>
30 #include <stddef.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
38 typedef enum {
39  kDLCPU = 1,
40  kDLGPU = 2,
41  // kDLCPUPinned = kDLCPU | kDLGPU
42  kDLCPUPinned = 3,
43  kDLOpenCL = 4,
44  kDLMetal = 8,
45  kDLVPI = 9,
46  kDLROCM = 10,
47 } DLDeviceType;
48 
52 typedef struct {
56  int device_id;
57 } DLContext;
58 
62 typedef enum {
63  kDLInt = 0U,
64  kDLUInt = 1U,
65  kDLFloat = 2U,
67 
76 typedef struct {
82  uint8_t code;
86  uint8_t bits;
88  uint16_t lanes;
89 } DLDataType;
90 
94 typedef struct {
100  void* data;
104  int ndim;
108  int64_t* shape;
113  int64_t* strides;
115  uint64_t byte_offset;
116 } DLTensor;
117 
125 typedef struct DLManagedTensor {
131  void * manager_ctx;
136  void (*deleter)(struct DLManagedTensor * self);
138 #ifdef __cplusplus
139 } // DLPACK_EXTERN_C
140 #endif
141 #endif // DLPACK_DLPACK_H_
C Tensor object, manage memory of DLTensor. This data structure is intended to faciliate the borrowin...
Definition: dlpack.h:125
int64_t * shape
The shape of the tensor.
Definition: dlpack.h:108
void * manager_ctx
the context of the original host framework of DLManagedTensor in which DLManagedTensor is used in the...
Definition: dlpack.h:131
uint16_t lanes
Number of lanes in the type, used for vector types.
Definition: dlpack.h:88
int device_id
The device index.
Definition: dlpack.h:56
DLDataType dtype
The data type of the pointer.
Definition: dlpack.h:106
int64_t * strides
strides of the tensor, can be NULL, indicating tensor is compact.
Definition: dlpack.h:113
struct DLManagedTensor DLManagedTensor
C Tensor object, manage memory of DLTensor. This data structure is intended to faciliate the borrowin...
int ndim
Number of dimensions.
Definition: dlpack.h:104
void * data
The opaque data pointer points to the allocated data. This will be CUDA device pointer or cl_mem hand...
Definition: dlpack.h:100
A Device context for Tensor and operator.
Definition: dlpack.h:52
DLDeviceType device_type
The device type used in the device.
Definition: dlpack.h:54
uint8_t bits
Number of bits, common choices are 8, 16, 32.
Definition: dlpack.h:86
DLDeviceType
The device type in DLContext.
Definition: dlpack.h:38
DLTensor dl_tensor
DLTensor which is being memory managed.
Definition: dlpack.h:127
DLDataTypeCode
The type code options DLDataType.
Definition: dlpack.h:62
uint64_t byte_offset
The offset in bytes to the beginning pointer to data.
Definition: dlpack.h:115
DLContext ctx
The device context of the tensor.
Definition: dlpack.h:102
The data type the tensor can hold.
Definition: dlpack.h:76
uint8_t code
Type code of base types. We keep it uint8_t instead of DLDataTypeCode for minimal memory footprint...
Definition: dlpack.h:82
void(* deleter)(struct DLManagedTensor *self)
Destructor signature void (*)(void*) - this should be called to destruct manager_ctx which holds the ...
Definition: dlpack.h:136
Plain C Tensor object, does not manage memory.
Definition: dlpack.h:94