HIP: Heterogenous-computing Interface for Portability
driver_types.h
1 /*
2 Copyright (c) 2015 - 2021 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_DRIVER_TYPES_H
24 #define HIP_INCLUDE_HIP_DRIVER_TYPES_H
25 
26 #include <hip/hip_common.h>
27 
28 #if !(defined(__HIP_PLATFORM_HCC__) || defined(__HIP_PLATFORM_AMD__)) && (defined(__HIP_PLATFORM_NVCC__) || defined(__HIP_PLATFORM_NVIDIA__))
29 #include "driver_types.h"
30 #elif (defined(__HIP_PLATFORM_HCC__) || defined(__HIP_PLATFORM_AMD__)) && !(defined(__HIP_PLATFORM_NVCC__) || defined(__HIP_PLATFORM_NVIDIA__))
31 
32 // The follow macro should be removed after upstream updation.
33 // It's defined here for workarround of rocThrust building failure.
34 #define HIP_INCLUDE_HIP_HCC_DETAIL_DRIVER_TYPES_H
35 #if !defined(__HIPCC_RTC__)
36 #ifndef __cplusplus
37 #include <stdbool.h>
38 #endif
39 #endif // !defined(__HIPCC_RTC__)
40 typedef void* hipDeviceptr_t;
41 typedef enum hipChannelFormatKind {
42  hipChannelFormatKindSigned = 0,
43  hipChannelFormatKindUnsigned = 1,
44  hipChannelFormatKindFloat = 2,
45  hipChannelFormatKindNone = 3
46 }hipChannelFormatKind;
47 typedef struct hipChannelFormatDesc {
48  int x;
49  int y;
50  int z;
51  int w;
52  enum hipChannelFormatKind f;
54 #define HIP_TRSA_OVERRIDE_FORMAT 0x01
55 #define HIP_TRSF_READ_AS_INTEGER 0x01
56 #define HIP_TRSF_NORMALIZED_COORDINATES 0x02
57 #define HIP_TRSF_SRGB 0x10
58 typedef enum hipArray_Format {
59  HIP_AD_FORMAT_UNSIGNED_INT8 = 0x01,
60  HIP_AD_FORMAT_UNSIGNED_INT16 = 0x02,
61  HIP_AD_FORMAT_UNSIGNED_INT32 = 0x03,
62  HIP_AD_FORMAT_SIGNED_INT8 = 0x08,
63  HIP_AD_FORMAT_SIGNED_INT16 = 0x09,
64  HIP_AD_FORMAT_SIGNED_INT32 = 0x0a,
65  HIP_AD_FORMAT_HALF = 0x10,
66  HIP_AD_FORMAT_FLOAT = 0x20
67 }hipArray_Format;
68 typedef struct HIP_ARRAY_DESCRIPTOR {
69  size_t Width;
70  size_t Height;
71  enum hipArray_Format Format;
72  unsigned int NumChannels;
74 typedef struct HIP_ARRAY3D_DESCRIPTOR {
75  size_t Width;
76  size_t Height;
77  size_t Depth;
78  enum hipArray_Format Format;
79  unsigned int NumChannels;
80  unsigned int Flags;
82 typedef struct hipArray {
83  void* data; // FIXME: generalize this
84  struct hipChannelFormatDesc desc;
85  unsigned int type;
86  unsigned int width;
87  unsigned int height;
88  unsigned int depth;
89  enum hipArray_Format Format;
90  unsigned int NumChannels;
91  bool isDrv;
92  unsigned int textureType;
93  unsigned int flags;
94 }hipArray;
95 #if !defined(__HIPCC_RTC__)
96 typedef struct hip_Memcpy2D {
97  size_t srcXInBytes;
98  size_t srcY;
99  hipMemoryType srcMemoryType;
100  const void* srcHost;
101  hipDeviceptr_t srcDevice;
102  hipArray* srcArray;
103  size_t srcPitch;
104  size_t dstXInBytes;
105  size_t dstY;
106  hipMemoryType dstMemoryType;
107  void* dstHost;
108  hipDeviceptr_t dstDevice;
109  hipArray* dstArray;
110  size_t dstPitch;
111  size_t WidthInBytes;
112  size_t Height;
113 } hip_Memcpy2D;
114 #endif // !defined(__HIPCC_RTC__)
115 typedef struct hipArray* hipArray_t;
116 typedef hipArray_t hiparray;
117 typedef const struct hipArray* hipArray_const_t;
118 typedef struct hipMipmappedArray {
119  void* data;
120  struct hipChannelFormatDesc desc;
121  unsigned int type;
122  unsigned int width;
123  unsigned int height;
124  unsigned int depth;
125  unsigned int min_mipmap_level;
126  unsigned int max_mipmap_level;
127  unsigned int flags;
128  enum hipArray_Format format;
130 typedef struct hipMipmappedArray* hipMipmappedArray_t;
131 typedef const struct hipMipmappedArray* hipMipmappedArray_const_t;
135 typedef enum hipResourceType {
136  hipResourceTypeArray = 0x00,
137  hipResourceTypeMipmappedArray = 0x01,
138  hipResourceTypeLinear = 0x02,
139  hipResourceTypePitch2D = 0x03
140 }hipResourceType;
141 typedef enum HIPresourcetype_enum {
142  HIP_RESOURCE_TYPE_ARRAY = 0x00,
143  HIP_RESOURCE_TYPE_MIPMAPPED_ARRAY = 0x01,
144  HIP_RESOURCE_TYPE_LINEAR = 0x02,
145  HIP_RESOURCE_TYPE_PITCH2D = 0x03
146 } HIPresourcetype, hipResourcetype;
150 typedef enum HIPaddress_mode_enum {
151  HIP_TR_ADDRESS_MODE_WRAP = 0,
152  HIP_TR_ADDRESS_MODE_CLAMP = 1,
153  HIP_TR_ADDRESS_MODE_MIRROR = 2,
154  HIP_TR_ADDRESS_MODE_BORDER = 3
155 } HIPaddress_mode;
159 typedef enum HIPfilter_mode_enum {
160  HIP_TR_FILTER_MODE_POINT = 0,
161  HIP_TR_FILTER_MODE_LINEAR = 1
162 } HIPfilter_mode;
166 typedef struct HIP_TEXTURE_DESC_st {
167  HIPaddress_mode addressMode[3];
168  HIPfilter_mode filterMode;
169  unsigned int flags;
170  unsigned int maxAnisotropy;
171  HIPfilter_mode mipmapFilterMode;
175  float borderColor[4];
176  int reserved[12];
181 typedef enum hipResourceViewFormat {
182  hipResViewFormatNone = 0x00,
183  hipResViewFormatUnsignedChar1 = 0x01,
184  hipResViewFormatUnsignedChar2 = 0x02,
185  hipResViewFormatUnsignedChar4 = 0x03,
186  hipResViewFormatSignedChar1 = 0x04,
187  hipResViewFormatSignedChar2 = 0x05,
188  hipResViewFormatSignedChar4 = 0x06,
189  hipResViewFormatUnsignedShort1 = 0x07,
190  hipResViewFormatUnsignedShort2 = 0x08,
191  hipResViewFormatUnsignedShort4 = 0x09,
192  hipResViewFormatSignedShort1 = 0x0a,
193  hipResViewFormatSignedShort2 = 0x0b,
194  hipResViewFormatSignedShort4 = 0x0c,
195  hipResViewFormatUnsignedInt1 = 0x0d,
196  hipResViewFormatUnsignedInt2 = 0x0e,
197  hipResViewFormatUnsignedInt4 = 0x0f,
198  hipResViewFormatSignedInt1 = 0x10,
199  hipResViewFormatSignedInt2 = 0x11,
200  hipResViewFormatSignedInt4 = 0x12,
201  hipResViewFormatHalf1 = 0x13,
202  hipResViewFormatHalf2 = 0x14,
203  hipResViewFormatHalf4 = 0x15,
204  hipResViewFormatFloat1 = 0x16,
205  hipResViewFormatFloat2 = 0x17,
206  hipResViewFormatFloat4 = 0x18,
207  hipResViewFormatUnsignedBlockCompressed1 = 0x19,
208  hipResViewFormatUnsignedBlockCompressed2 = 0x1a,
209  hipResViewFormatUnsignedBlockCompressed3 = 0x1b,
210  hipResViewFormatUnsignedBlockCompressed4 = 0x1c,
211  hipResViewFormatSignedBlockCompressed4 = 0x1d,
212  hipResViewFormatUnsignedBlockCompressed5 = 0x1e,
213  hipResViewFormatSignedBlockCompressed5 = 0x1f,
214  hipResViewFormatUnsignedBlockCompressed6H = 0x20,
215  hipResViewFormatSignedBlockCompressed6H = 0x21,
216  hipResViewFormatUnsignedBlockCompressed7 = 0x22
217 }hipResourceViewFormat;
218 typedef enum HIPresourceViewFormat_enum
219 {
220  HIP_RES_VIEW_FORMAT_NONE = 0x00,
221  HIP_RES_VIEW_FORMAT_UINT_1X8 = 0x01,
222  HIP_RES_VIEW_FORMAT_UINT_2X8 = 0x02,
223  HIP_RES_VIEW_FORMAT_UINT_4X8 = 0x03,
224  HIP_RES_VIEW_FORMAT_SINT_1X8 = 0x04,
225  HIP_RES_VIEW_FORMAT_SINT_2X8 = 0x05,
226  HIP_RES_VIEW_FORMAT_SINT_4X8 = 0x06,
227  HIP_RES_VIEW_FORMAT_UINT_1X16 = 0x07,
228  HIP_RES_VIEW_FORMAT_UINT_2X16 = 0x08,
229  HIP_RES_VIEW_FORMAT_UINT_4X16 = 0x09,
230  HIP_RES_VIEW_FORMAT_SINT_1X16 = 0x0a,
231  HIP_RES_VIEW_FORMAT_SINT_2X16 = 0x0b,
232  HIP_RES_VIEW_FORMAT_SINT_4X16 = 0x0c,
233  HIP_RES_VIEW_FORMAT_UINT_1X32 = 0x0d,
234  HIP_RES_VIEW_FORMAT_UINT_2X32 = 0x0e,
235  HIP_RES_VIEW_FORMAT_UINT_4X32 = 0x0f,
236  HIP_RES_VIEW_FORMAT_SINT_1X32 = 0x10,
237  HIP_RES_VIEW_FORMAT_SINT_2X32 = 0x11,
238  HIP_RES_VIEW_FORMAT_SINT_4X32 = 0x12,
239  HIP_RES_VIEW_FORMAT_FLOAT_1X16 = 0x13,
240  HIP_RES_VIEW_FORMAT_FLOAT_2X16 = 0x14,
241  HIP_RES_VIEW_FORMAT_FLOAT_4X16 = 0x15,
242  HIP_RES_VIEW_FORMAT_FLOAT_1X32 = 0x16,
243  HIP_RES_VIEW_FORMAT_FLOAT_2X32 = 0x17,
244  HIP_RES_VIEW_FORMAT_FLOAT_4X32 = 0x18,
245  HIP_RES_VIEW_FORMAT_UNSIGNED_BC1 = 0x19,
246  HIP_RES_VIEW_FORMAT_UNSIGNED_BC2 = 0x1a,
247  HIP_RES_VIEW_FORMAT_UNSIGNED_BC3 = 0x1b,
248  HIP_RES_VIEW_FORMAT_UNSIGNED_BC4 = 0x1c,
249  HIP_RES_VIEW_FORMAT_SIGNED_BC4 = 0x1d,
250  HIP_RES_VIEW_FORMAT_UNSIGNED_BC5 = 0x1e,
251  HIP_RES_VIEW_FORMAT_SIGNED_BC5 = 0x1f,
252  HIP_RES_VIEW_FORMAT_UNSIGNED_BC6H = 0x20,
253  HIP_RES_VIEW_FORMAT_SIGNED_BC6H = 0x21,
254  HIP_RES_VIEW_FORMAT_UNSIGNED_BC7 = 0x22
255 } HIPresourceViewFormat;
259 typedef struct hipResourceDesc {
260  enum hipResourceType resType;
261  union {
262  struct {
263  hipArray_t array;
264  } array;
265  struct {
266  hipMipmappedArray_t mipmap;
267  } mipmap;
268  struct {
269  void* devPtr;
270  struct hipChannelFormatDesc desc;
271  size_t sizeInBytes;
272  } linear;
273  struct {
274  void* devPtr;
275  struct hipChannelFormatDesc desc;
276  size_t width;
277  size_t height;
278  size_t pitchInBytes;
279  } pitch2D;
280  } res;
282 typedef struct HIP_RESOURCE_DESC_st
283 {
284  HIPresourcetype resType;
285  union {
286  struct {
288  } array;
289  struct {
291  } mipmap;
292  struct {
293  hipDeviceptr_t devPtr;
294  hipArray_Format format;
295  unsigned int numChannels;
296  size_t sizeInBytes;
297  } linear;
298  struct {
299  hipDeviceptr_t devPtr;
300  hipArray_Format format;
301  unsigned int numChannels;
302  size_t width;
303  size_t height;
304  size_t pitchInBytes;
305  } pitch2D;
306  struct {
307  int reserved[32];
308  } reserved;
309  } res;
310  unsigned int flags;
316  enum hipResourceViewFormat format;
317  size_t width;
318  size_t height;
319  size_t depth;
320  unsigned int firstMipmapLevel;
321  unsigned int lastMipmapLevel;
322  unsigned int firstLayer;
323  unsigned int lastLayer;
324 };
329 {
330  HIPresourceViewFormat format;
331  size_t width;
332  size_t height;
333  size_t depth;
334  unsigned int firstMipmapLevel;
335  unsigned int lastMipmapLevel;
336  unsigned int firstLayer;
337  unsigned int lastLayer;
338  unsigned int reserved[16];
344 #if !defined(__HIPCC_RTC__)
345 typedef enum hipMemcpyKind {
346  hipMemcpyHostToHost = 0,
347  hipMemcpyHostToDevice = 1,
348  hipMemcpyDeviceToHost = 2,
349  hipMemcpyDeviceToDevice = 3,
350  hipMemcpyDefault =
351  4
352 } hipMemcpyKind;
353 typedef struct hipPitchedPtr {
354  void* ptr;
355  size_t pitch;
356  size_t xsize;
357  size_t ysize;
359 typedef struct hipExtent {
360  size_t width; // Width in elements when referring to array memory, in bytes when referring to
361  // linear memory
362  size_t height;
363  size_t depth;
364 }hipExtent;
365 typedef struct hipPos {
366  size_t x;
367  size_t y;
368  size_t z;
369 }hipPos;
370 typedef struct hipMemcpy3DParms {
371  hipArray_t srcArray;
372  struct hipPos srcPos;
373  struct hipPitchedPtr srcPtr;
374  hipArray_t dstArray;
375  struct hipPos dstPos;
376  struct hipPitchedPtr dstPtr;
377  struct hipExtent extent;
378  enum hipMemcpyKind kind;
380 typedef struct HIP_MEMCPY3D {
381  unsigned int srcXInBytes;
382  unsigned int srcY;
383  unsigned int srcZ;
384  unsigned int srcLOD;
385  hipMemoryType srcMemoryType;
386  const void* srcHost;
387  hipDeviceptr_t srcDevice;
388  hipArray_t srcArray;
389  unsigned int srcPitch;
390  unsigned int srcHeight;
391  unsigned int dstXInBytes;
392  unsigned int dstY;
393  unsigned int dstZ;
394  unsigned int dstLOD;
395  hipMemoryType dstMemoryType;
396  void* dstHost;
397  hipDeviceptr_t dstDevice;
398  hipArray_t dstArray;
399  unsigned int dstPitch;
400  unsigned int dstHeight;
401  unsigned int WidthInBytes;
402  unsigned int Height;
403  unsigned int Depth;
404 } HIP_MEMCPY3D;
405 static inline struct hipPitchedPtr make_hipPitchedPtr(void* d, size_t p, size_t xsz,
406  size_t ysz) {
407  struct hipPitchedPtr s;
408  s.ptr = d;
409  s.pitch = p;
410  s.xsize = xsz;
411  s.ysize = ysz;
412  return s;
413 }
414 static inline struct hipPos make_hipPos(size_t x, size_t y, size_t z) {
415  struct hipPos p;
416  p.x = x;
417  p.y = y;
418  p.z = z;
419  return p;
420 }
421 static inline struct hipExtent make_hipExtent(size_t w, size_t h, size_t d) {
422  struct hipExtent e;
423  e.width = w;
424  e.height = h;
425  e.depth = d;
426  return e;
427 }
428 typedef enum hipFunction_attribute {
429  HIP_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK,
430  HIP_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES,
431  HIP_FUNC_ATTRIBUTE_CONST_SIZE_BYTES,
432  HIP_FUNC_ATTRIBUTE_LOCAL_SIZE_BYTES,
433  HIP_FUNC_ATTRIBUTE_NUM_REGS,
434  HIP_FUNC_ATTRIBUTE_PTX_VERSION,
435  HIP_FUNC_ATTRIBUTE_BINARY_VERSION,
436  HIP_FUNC_ATTRIBUTE_CACHE_MODE_CA,
437  HIP_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES,
438  HIP_FUNC_ATTRIBUTE_PREFERRED_SHARED_MEMORY_CARVEOUT,
439  HIP_FUNC_ATTRIBUTE_MAX
440 } hipFunction_attribute;
441 
442 typedef enum hipPointer_attribute {
443  HIP_POINTER_ATTRIBUTE_CONTEXT = 1,
445  HIP_POINTER_ATTRIBUTE_MEMORY_TYPE,
446  HIP_POINTER_ATTRIBUTE_DEVICE_POINTER,
447  HIP_POINTER_ATTRIBUTE_HOST_POINTER,
448  HIP_POINTER_ATTRIBUTE_P2P_TOKENS,
450  HIP_POINTER_ATTRIBUTE_SYNC_MEMOPS,
452  HIP_POINTER_ATTRIBUTE_BUFFER_ID,
453  HIP_POINTER_ATTRIBUTE_IS_MANAGED,
454  HIP_POINTER_ATTRIBUTE_DEVICE_ORDINAL,
456  HIP_POINTER_ATTRIBUTE_IS_LEGACY_HIP_IPC_CAPABLE,
459  HIP_POINTER_ATTRIBUTE_RANGE_START_ADDR,
460  HIP_POINTER_ATTRIBUTE_RANGE_SIZE,
461  HIP_POINTER_ATTRIBUTE_MAPPED,
463  HIP_POINTER_ATTRIBUTE_ALLOWED_HANDLE_TYPES,
465  HIP_POINTER_ATTRIBUTE_IS_GPU_DIRECT_RDMA_CAPABLE,
468  HIP_POINTER_ATTRIBUTE_ACCESS_FLAGS,
470  HIP_POINTER_ATTRIBUTE_MEMPOOL_HANDLE
473 } hipPointer_attribute;
474 
475 #endif // !defined(__HIPCC_RTC__)
476 #else
477 #error("Must define exactly one of __HIP_PLATFORM_AMD__ or __HIP_PLATFORM_NVIDIA__");
478 #endif
479 #endif
hipMemoryType
Definition: hip_runtime_api.h:161
Definition: driver_types.h:74
Definition: driver_types.h:68
Definition: driver_types.h:380
Definition: driver_types.h:283
hipArray_t hArray
Definition: driver_types.h:287
HIPresourcetype resType
Definition: driver_types.h:284
unsigned int numChannels
Definition: driver_types.h:295
hipMipmappedArray_t hMipmappedArray
Definition: driver_types.h:290
hipArray_Format format
Definition: driver_types.h:294
unsigned int flags
Definition: driver_types.h:310
size_t pitchInBytes
Definition: driver_types.h:304
size_t width
Definition: driver_types.h:302
size_t height
Definition: driver_types.h:303
size_t sizeInBytes
Definition: driver_types.h:296
hipDeviceptr_t devPtr
Definition: driver_types.h:293
Definition: driver_types.h:329
size_t width
Definition: driver_types.h:331
unsigned int firstLayer
Definition: driver_types.h:336
unsigned int lastMipmapLevel
Definition: driver_types.h:335
size_t depth
Definition: driver_types.h:333
unsigned int lastLayer
Definition: driver_types.h:337
unsigned int firstMipmapLevel
Definition: driver_types.h:334
size_t height
Definition: driver_types.h:332
HIPresourceViewFormat format
Definition: driver_types.h:330
Definition: driver_types.h:166
float maxMipmapLevelClamp
Definition: driver_types.h:174
unsigned int maxAnisotropy
Definition: driver_types.h:170
float mipmapLevelBias
Definition: driver_types.h:172
unsigned int flags
Definition: driver_types.h:169
float borderColor[4]
Definition: driver_types.h:175
HIPaddress_mode addressMode[3]
Definition: driver_types.h:167
HIPfilter_mode mipmapFilterMode
Definition: driver_types.h:171
float minMipmapLevelClamp
Definition: driver_types.h:173
HIPfilter_mode filterMode
Definition: driver_types.h:168
Definition: driver_types.h:82
Definition: driver_types.h:47
Definition: driver_types.h:359
Definition: driver_types.h:370
Definition: driver_types.h:118
Definition: driver_types.h:353
Definition: driver_types.h:365
Definition: driver_types.h:259
Definition: driver_types.h:315
Definition: driver_types.h:96