HIP: Heterogenous-computing Interface for Portability
driver_types.h
1 /*
2 Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved.
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21 */
22 
23 #ifndef HIP_INCLUDE_HIP_HCC_DETAIL_DRIVER_TYPES_H
24 #define HIP_INCLUDE_HIP_HCC_DETAIL_DRIVER_TYPES_H
25 
26 #ifndef __cplusplus
27 #include <stdbool.h>
28 #endif
29 
30 typedef void* hipDeviceptr_t;
31 typedef enum hipChannelFormatKind {
32  hipChannelFormatKindSigned = 0,
33  hipChannelFormatKindUnsigned = 1,
34  hipChannelFormatKindFloat = 2,
35  hipChannelFormatKindNone = 3
36 }hipChannelFormatKind;
37 
38 typedef struct hipChannelFormatDesc {
39  int x;
40  int y;
41  int z;
42  int w;
43  enum hipChannelFormatKind f;
45 
46 #define HIP_TRSA_OVERRIDE_FORMAT 0x01
47 #define HIP_TRSF_READ_AS_INTEGER 0x01
48 #define HIP_TRSF_NORMALIZED_COORDINATES 0x02
49 #define HIP_TRSF_SRGB 0x10
50 
51 typedef enum hipArray_Format {
52  HIP_AD_FORMAT_UNSIGNED_INT8 = 0x01,
53  HIP_AD_FORMAT_UNSIGNED_INT16 = 0x02,
54  HIP_AD_FORMAT_UNSIGNED_INT32 = 0x03,
55  HIP_AD_FORMAT_SIGNED_INT8 = 0x08,
56  HIP_AD_FORMAT_SIGNED_INT16 = 0x09,
57  HIP_AD_FORMAT_SIGNED_INT32 = 0x0a,
58  HIP_AD_FORMAT_HALF = 0x10,
59  HIP_AD_FORMAT_FLOAT = 0x20
60 }hipArray_Format;
61 
62 typedef struct HIP_ARRAY_DESCRIPTOR {
63  size_t Width;
64  size_t Height;
65  enum hipArray_Format Format;
66  unsigned int NumChannels;
68 
69 typedef struct HIP_ARRAY3D_DESCRIPTOR {
70  size_t Width;
71  size_t Height;
72  size_t Depth;
73  enum hipArray_Format Format;
74  unsigned int NumChannels;
75  unsigned int Flags;
77 
78 typedef struct hipArray {
79  void* data; // FIXME: generalize this
80  struct hipChannelFormatDesc desc;
81  unsigned int type;
82  unsigned int width;
83  unsigned int height;
84  unsigned int depth;
85  enum hipArray_Format Format;
86  unsigned int NumChannels;
87  bool isDrv;
88  unsigned int textureType;
89 }hipArray;
90 
91 typedef struct hip_Memcpy2D {
92  size_t srcXInBytes;
93  size_t srcY;
94  hipMemoryType srcMemoryType;
95  const void* srcHost;
96  hipDeviceptr_t srcDevice;
97  hipArray* srcArray;
98  size_t srcPitch;
99  size_t dstXInBytes;
100  size_t dstY;
101  hipMemoryType dstMemoryType;
102  void* dstHost;
103  hipDeviceptr_t dstDevice;
104  hipArray* dstArray;
105  size_t dstPitch;
106  size_t WidthInBytes;
107  size_t Height;
108 } hip_Memcpy2D;
109 
110 
111 typedef struct hipArray* hipArray_t;
112 
113 typedef const struct hipArray* hipArray_const_t;
114 
115 // TODO: It needs to be modified since it was just copied from hipArray.
117  void* data; // FIXME: generalize this
118  struct hipChannelFormatDesc desc;
119  unsigned int width;
120  unsigned int height;
121  unsigned int depth;
122 };
123 
124 typedef struct hipMipmappedArray* hipMipmappedArray_t;
125 
126 typedef const struct hipMipmappedArray* hipMipmappedArray_const_t;
127 
131 typedef enum hipResourceType {
132  hipResourceTypeArray = 0x00,
133  hipResourceTypeMipmappedArray = 0x01,
134  hipResourceTypeLinear = 0x02,
135  hipResourceTypePitch2D = 0x03
136 }hipResourceType;
137 
141 typedef enum hipResourceViewFormat {
142  hipResViewFormatNone = 0x00,
143  hipResViewFormatUnsignedChar1 = 0x01,
144  hipResViewFormatUnsignedChar2 = 0x02,
145  hipResViewFormatUnsignedChar4 = 0x03,
146  hipResViewFormatSignedChar1 = 0x04,
147  hipResViewFormatSignedChar2 = 0x05,
148  hipResViewFormatSignedChar4 = 0x06,
149  hipResViewFormatUnsignedShort1 = 0x07,
150  hipResViewFormatUnsignedShort2 = 0x08,
151  hipResViewFormatUnsignedShort4 = 0x09,
152  hipResViewFormatSignedShort1 = 0x0a,
153  hipResViewFormatSignedShort2 = 0x0b,
154  hipResViewFormatSignedShort4 = 0x0c,
155  hipResViewFormatUnsignedInt1 = 0x0d,
156  hipResViewFormatUnsignedInt2 = 0x0e,
157  hipResViewFormatUnsignedInt4 = 0x0f,
158  hipResViewFormatSignedInt1 = 0x10,
159  hipResViewFormatSignedInt2 = 0x11,
160  hipResViewFormatSignedInt4 = 0x12,
161  hipResViewFormatHalf1 = 0x13,
162  hipResViewFormatHalf2 = 0x14,
163  hipResViewFormatHalf4 = 0x15,
164  hipResViewFormatFloat1 = 0x16,
165  hipResViewFormatFloat2 = 0x17,
166  hipResViewFormatFloat4 = 0x18,
167  hipResViewFormatUnsignedBlockCompressed1 = 0x19,
168  hipResViewFormatUnsignedBlockCompressed2 = 0x1a,
169  hipResViewFormatUnsignedBlockCompressed3 = 0x1b,
170  hipResViewFormatUnsignedBlockCompressed4 = 0x1c,
171  hipResViewFormatSignedBlockCompressed4 = 0x1d,
172  hipResViewFormatUnsignedBlockCompressed5 = 0x1e,
173  hipResViewFormatSignedBlockCompressed5 = 0x1f,
174  hipResViewFormatUnsignedBlockCompressed6H = 0x20,
175  hipResViewFormatSignedBlockCompressed6H = 0x21,
176  hipResViewFormatUnsignedBlockCompressed7 = 0x22
177 }hipResourceViewFormat;
178 
182 typedef struct hipResourceDesc {
183  enum hipResourceType resType;
184 
185  union {
186  struct {
187  hipArray_t array;
188  } array;
189  struct {
190  hipMipmappedArray_t mipmap;
191  } mipmap;
192  struct {
193  void* devPtr;
194  struct hipChannelFormatDesc desc;
195  size_t sizeInBytes;
196  } linear;
197  struct {
198  void* devPtr;
199  struct hipChannelFormatDesc desc;
200  size_t width;
201  size_t height;
202  size_t pitchInBytes;
203  } pitch2D;
204  } res;
206 
211  enum hipResourceViewFormat format;
212  size_t width;
213  size_t height;
214  size_t depth;
215  unsigned int firstMipmapLevel;
216  unsigned int lastMipmapLevel;
217  unsigned int firstLayer;
218  unsigned int lastLayer;
219 };
220 
225 typedef enum hipMemcpyKind {
226  hipMemcpyHostToHost = 0,
227  hipMemcpyHostToDevice = 1,
228  hipMemcpyDeviceToHost = 2,
229  hipMemcpyDeviceToDevice = 3,
230  hipMemcpyDefault =
231  4
232 } hipMemcpyKind;
233 
234 typedef struct hipPitchedPtr {
235  void* ptr;
236  size_t pitch;
237  size_t xsize;
238  size_t ysize;
240 
241 typedef struct hipExtent {
242  size_t width; // Width in elements when referring to array memory, in bytes when referring to
243  // linear memory
244  size_t height;
245  size_t depth;
246 }hipExtent;
247 
248 typedef struct hipPos {
249  size_t x;
250  size_t y;
251  size_t z;
252 }hipPos;
253 
254 typedef struct hipMemcpy3DParms {
255  hipArray_t srcArray;
256  struct hipPos srcPos;
257  struct hipPitchedPtr srcPtr;
258  hipArray_t dstArray;
259  struct hipPos dstPos;
260  struct hipPitchedPtr dstPtr;
261  struct hipExtent extent;
262  enum hipMemcpyKind kind;
264 
265 typedef struct HIP_MEMCPY3D {
266  size_t Depth;
267  size_t Height;
268  size_t WidthInBytes;
269  hipDeviceptr_t dstDevice;
270  size_t dstHeight;
271  void* dstHost;
272  size_t dstLOD;
273  hipMemoryType dstMemoryType;
274  size_t dstPitch;
275  size_t dstXInBytes;
276  size_t dstY;
277  size_t dstZ;
278  void* reserved0;
279  void* reserved1;
280  hipDeviceptr_t srcDevice;
281  size_t srcHeight;
282  const void* srcHost;
283  size_t srcLOD;
284  hipMemoryType srcMemoryType;
285  size_t srcPitch;
286 } HIP_MEMCPY3D;
287 
288 static inline struct hipPitchedPtr make_hipPitchedPtr(void* d, size_t p, size_t xsz,
289  size_t ysz) {
290  struct hipPitchedPtr s;
291 
292  s.ptr = d;
293  s.pitch = p;
294  s.xsize = xsz;
295  s.ysize = ysz;
296 
297  return s;
298 }
299 
300 static inline struct hipPos make_hipPos(size_t x, size_t y, size_t z) {
301  struct hipPos p;
302 
303  p.x = x;
304  p.y = y;
305  p.z = z;
306 
307  return p;
308 }
309 
310 static inline struct hipExtent make_hipExtent(size_t w, size_t h, size_t d) {
311  struct hipExtent e;
312 
313  e.width = w;
314  e.height = h;
315  e.depth = d;
316 
317  return e;
318 }
319 
320 typedef enum hipFunction_attribute {
321  HIP_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK,
322  HIP_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES,
323  HIP_FUNC_ATTRIBUTE_CONST_SIZE_BYTES,
324  HIP_FUNC_ATTRIBUTE_LOCAL_SIZE_BYTES,
325  HIP_FUNC_ATTRIBUTE_NUM_REGS,
326  HIP_FUNC_ATTRIBUTE_PTX_VERSION,
327  HIP_FUNC_ATTRIBUTE_BINARY_VERSION,
328  HIP_FUNC_ATTRIBUTE_CACHE_MODE_CA,
329  HIP_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES,
330  HIP_FUNC_ATTRIBUTE_PREFERRED_SHARED_MEMORY_CARVEOUT,
331  HIP_FUNC_ATTRIBUTE_MAX
332 }hipFunction_attribute;
333 
334 #endif
Definition: driver_types.h:248
Definition: driver_types.h:241
Definition: driver_types.h:182
Definition: driver_types.h:116
Definition: driver_types.h:78
Definition: driver_types.h:69
Definition: driver_types.h:254
Definition: driver_types.h:62
Definition: driver_types.h:234
Definition: driver_types.h:38
Definition: driver_types.h:265
Definition: driver_types.h:91
Definition: driver_types.h:210