HIP: Heterogenous-computing Interface for Portability
hip_runtime_api.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 
30 #ifndef HIP_INCLUDE_HIP_HIP_RUNTIME_API_H
31 #define HIP_INCLUDE_HIP_HIP_RUNTIME_API_H
32 
33 
34 #include <string.h> // for getDeviceProp
35 #include <hip/hip_common.h>
36 
37 enum {
38 HIP_SUCCESS = 0,
39 HIP_ERROR_INVALID_VALUE,
40 HIP_ERROR_NOT_INITIALIZED,
41 HIP_ERROR_LAUNCH_OUT_OF_RESOURCES
42 };
43 
44 typedef struct {
45  // 32-bit Atomics
46  unsigned hasGlobalInt32Atomics : 1;
47  unsigned hasGlobalFloatAtomicExch : 1;
48  unsigned hasSharedInt32Atomics : 1;
49  unsigned hasSharedFloatAtomicExch : 1;
50  unsigned hasFloatAtomicAdd : 1;
51 
52  // 64-bit Atomics
53  unsigned hasGlobalInt64Atomics : 1;
54  unsigned hasSharedInt64Atomics : 1;
55 
56  // Doubles
57  unsigned hasDoubles : 1;
58 
59  // Warp cross-lane operations
60  unsigned hasWarpVote : 1;
61  unsigned hasWarpBallot : 1;
62  unsigned hasWarpShuffle : 1;
63  unsigned hasFunnelShift : 1;
64 
65  // Sync
66  unsigned hasThreadFenceSystem : 1;
67  unsigned hasSyncThreadsExt : 1;
68 
69  // Misc
70  unsigned hasSurfaceFuncs : 1;
71  unsigned has3dGrid : 1;
72  unsigned hasDynamicParallelism : 1;
74 
75 
76 //---
77 // Common headers for both NVCC and HCC paths:
78 
83 typedef struct hipDeviceProp_t {
84  char name[256];
85  size_t totalGlobalMem;
88  int warpSize;
90  int maxThreadsDim[3];
91  int maxGridSize[3];
92  int clockRate;
95  size_t totalConstMem;
96  int major;
97  int minor;
105  int pciBusID;
110  int gcnArch;
111  } hipDeviceProp_t;
112 
113 
117 enum hipMemoryType {
118  hipMemoryTypeHost,
119  hipMemoryTypeDevice
120 };
121 
122 
123 
127 typedef struct hipPointerAttribute_t {
128  enum hipMemoryType memoryType;
129  int device;
130  void *devicePointer;
131  void *hostPointer;
132  int isManaged;
133  unsigned allocationFlags; /* flags specified when memory was allocated*/
134  /* peers? */
136 
137 
138 // hack to get these to show up in Doxygen:
146 /*
147  * @brief hipError_t
148  * @enum
149  * @ingroup Enumerations
150  */
151 // Developer note - when updating these, update the hipErrorName and hipErrorString functions in NVCC and HCC paths
152 // Also update the hipCUDAErrorTohipError function in NVCC path.
153 
154 typedef enum hipError_t {
156  hipErrorOutOfMemory = 2,
157  hipErrorNotInitialized = 3,
158  hipErrorDeinitialized = 4,
159  hipErrorProfilerDisabled = 5,
160  hipErrorProfilerNotInitialized = 6,
161  hipErrorProfilerAlreadyStarted = 7,
162  hipErrorProfilerAlreadyStopped = 8,
163  hipErrorInvalidImage = 200,
165  hipErrorContextAlreadyCurrent = 202,
166  hipErrorMapFailed = 205,
167  hipErrorUnmapFailed = 206,
168  hipErrorArrayIsMapped = 207,
169  hipErrorAlreadyMapped = 208,
170  hipErrorNoBinaryForGpu = 209,
171  hipErrorAlreadyAcquired = 210,
172  hipErrorNotMapped = 211,
173  hipErrorNotMappedAsArray = 212,
174  hipErrorNotMappedAsPointer = 213,
175  hipErrorECCNotCorrectable = 214,
176  hipErrorUnsupportedLimit = 215,
177  hipErrorContextAlreadyInUse = 216,
178  hipErrorPeerAccessUnsupported = 217,
180  hipErrorInvalidGraphicsContext = 219,
181  hipErrorInvalidSource = 300,
182  hipErrorFileNotFound = 301,
183  hipErrorSharedObjectSymbolNotFound = 302,
184  hipErrorSharedObjectInitFailed = 303,
185  hipErrorOperatingSystem = 304,
186  hipErrorSetOnActiveProcess = 305,
187  hipErrorInvalidHandle = 400,
188  hipErrorNotFound = 500,
189  hipErrorIllegalAddress = 700,
190  hipErrorInvalidSymbol = 701,
191 // Runtime Error Codes start here.
192  hipErrorMissingConfiguration = 1001,
196  hipErrorPriorLaunchFailure = 1005,
197  hipErrorLaunchTimeOut = 1006,
199  hipErrorInvalidDeviceFunction = 1008,
200  hipErrorInvalidConfiguration = 1009,
210 
218 } hipError_t;
219 
220 /*
221  * @brief hipDeviceAttribute_t
222  * @enum
223  * @ingroup Enumerations
224  */
225 typedef enum hipDeviceAttribute_t {
252 
253 
258 #if defined(__HIP_PLATFORM_HCC__) && !defined (__HIP_PLATFORM_NVCC__)
260 #elif defined(__HIP_PLATFORM_NVCC__) && !defined (__HIP_PLATFORM_HCC__)
261 #include "hip/nvcc_detail/hip_runtime_api.h"
262 #else
263 #error("Must define exactly one of __HIP_PLATFORM_HCC__ or __HIP_PLATFORM_NVCC__");
264 #endif
265 
266 
274 #ifdef __cplusplus
275 template<class T>
276 static inline hipError_t hipMalloc ( T** devPtr, size_t size)
277 {
278  return hipMalloc((void**)devPtr, size);
279 }
280 
281 // Provide an override to automatically typecast the pointer type from void**, and also provide a default for the flags.
282 template<class T>
283 static inline hipError_t hipHostMalloc( T** ptr, size_t size, unsigned int flags = hipHostMallocDefault)
284 {
285  return hipHostMalloc((void**)ptr, size, flags);
286 }
287 #endif
288 
289 #endif
Call to hipGetDeviceCount returned 0 devices.
Definition: hip_runtime_api.h:208
size_t totalConstMem
Size of shared memory region (in bytes).
Definition: hip_runtime_api.h:95
Maximum Shared Memory Per Multiprocessor.
Definition: hip_runtime_api.h:249
Maximum x-dimension of a block.
Definition: hip_runtime_api.h:227
Maximum x-dimension of a grid.
Definition: hip_runtime_api.h:230
Peer access was already enabled from the current device.
Definition: hip_runtime_api.h:209
HSA runtime memory call returned error. Typically not seen in production systems. ...
Definition: hip_runtime_api.h:212
Global memory bus width in bits.
Definition: hip_runtime_api.h:239
Produced when the IPC memory attach failed from ROCr.
Definition: hip_runtime_api.h:216
Successful completion.
Definition: hip_runtime_api.h:155
int minor
Minor compute capability. On HCC, this is an approximation and features may differ from CUDA CC...
Definition: hip_runtime_api.h:97
In CUDA DRV, it is CUDA_ERROR_INVALID_PTX.
Definition: hip_runtime_api.h:179
int canMapHostMemory
Check whether HIP can map host memory.
Definition: hip_runtime_api.h:109
Maximum number of 32-bit registers available to a thread block. This number is shared by all thread b...
Definition: hip_runtime_api.h:236
int regsPerBlock
Registers per block.
Definition: hip_runtime_api.h:87
Size of L2 cache in bytes. 0 if the device doesn&#39;t have L2 cache.
Definition: hip_runtime_api.h:242
#define hipHostMallocDefault
Flags that can be used with hipHostMalloc.
Definition: hip_runtime_api.h:114
HSA runtime call other than memory returned error. Typically not seen in production systems...
Definition: hip_runtime_api.h:213
int isMultiGpuBoard
1 if device is on a multi-GPU board, 0 if not.
Definition: hip_runtime_api.h:108
DeviceID must be in range 0...#compute-devices.
Definition: hip_runtime_api.h:201
Peak clock frequency in kilohertz.
Definition: hip_runtime_api.h:237
Definition: hip_runtime_api.h:127
int clockRate
Max clock frequency of the multiProcessors in khz.
Definition: hip_runtime_api.h:92
Maximum z-dimension of a grid.
Definition: hip_runtime_api.h:232
Minor compute capability version number.
Definition: hip_runtime_api.h:245
Maximum shared memory available per block in bytes.
Definition: hip_runtime_api.h:233
int pciBusID
PCI Bus ID.
Definition: hip_runtime_api.h:105
Maximum y-dimension of a grid.
Definition: hip_runtime_api.h:231
Multiple GPU devices.
Definition: hip_runtime_api.h:250
Unknown error.
Definition: hip_runtime_api.h:205
int maxThreadsPerBlock
Max work items per work group or workgroup max size.
Definition: hip_runtime_api.h:89
Maximum y-dimension of a block.
Definition: hip_runtime_api.h:228
hipError_t hipHostMalloc(void **ptr, size_t size, unsigned int flags)
Allocate device accessible page locked host memory.
Definition: hip_memory.cpp:247
size_t sharedMemPerBlock
Size of shared memory region (in bytes).
Definition: hip_runtime_api.h:86
int maxThreadsPerMultiProcessor
Maximum resident threads per multi-processor.
Definition: hip_runtime_api.h:100
Produced when trying to lock a page-locked memory.
Definition: hip_runtime_api.h:214
int l2CacheSize
L2 cache size.
Definition: hip_runtime_api.h:99
hipDeviceAttribute_t
Definition: hip_runtime_api.h:225
Major compute capability version number.
Definition: hip_runtime_api.h:244
Peer access was never enabled from the current device.
Definition: hip_runtime_api.h:211
Maximum number of threads per block.
Definition: hip_runtime_api.h:226
Resource handle (hipEvent_t or hipStream_t) invalid.
Definition: hip_runtime_api.h:206
int gcnArch
AMD GCN Arch Value. Eg: 803, 701.
Definition: hip_runtime_api.h:110
Memory allocation error.
Definition: hip_runtime_api.h:193
hipDeviceArch_t arch
Architectural feature flags. New for HIP.
Definition: hip_runtime_api.h:103
int maxGridSize[3]
Max grid dimensions (XYZ).
Definition: hip_runtime_api.h:91
int computeMode
Compute mode.
Definition: hip_runtime_api.h:101
Maximum z-dimension of a block.
Definition: hip_runtime_api.h:229
PCI Bus ID.
Definition: hip_runtime_api.h:247
Invalid memory copy direction.
Definition: hip_runtime_api.h:204
Marker that more error codes are needed.
Definition: hip_runtime_api.h:217
Warp size in threads.
Definition: hip_runtime_api.h:235
int major
Major compute capability. On HCC, this is an approximation and features may differ from CUDA CC...
Definition: hip_runtime_api.h:96
Peak memory clock frequency in kilohertz.
Definition: hip_runtime_api.h:238
Maximum resident threads per multiprocessor.
Definition: hip_runtime_api.h:243
hipError_t
Definition: hip_runtime_api.h:154
int clockInstructionRate
Frequency in khz of the timer used by the device-side "clock*" instructions. New for HIP...
Definition: hip_runtime_api.h:102
Constant memory size in bytes.
Definition: hip_runtime_api.h:234
int warpSize
Warp size.
Definition: hip_runtime_api.h:88
int concurrentKernels
Device can possibly execute multiple kernels concurrently.
Definition: hip_runtime_api.h:104
size_t totalGlobalMem
Size of global memory region (in bytes).
Definition: hip_runtime_api.h:85
Invalid Device Pointer.
Definition: hip_runtime_api.h:203
An exception occurred on the device while executing a kernel.
Definition: hip_runtime_api.h:195
hipError_t hipMalloc(void **ptr, size_t size)
Allocate memory on the default accelerator.
Definition: hip_memory.cpp:215
Compute mode that device is currently in.
Definition: hip_runtime_api.h:241
PCI Device ID.
Definition: hip_runtime_api.h:248
int maxThreadsDim[3]
Max number of threads in each dimension (XYZ) of a block.
Definition: hip_runtime_api.h:90
Number of multiprocessors on the device.
Definition: hip_runtime_api.h:240
int memoryBusWidth
Global memory bus width in bits.
Definition: hip_runtime_api.h:94
One or more of the parameters passed to the API call is NULL or not in an acceptable range...
Definition: hip_runtime_api.h:202
Definition: hip_runtime_api.h:83
Indicates that asynchronous operations enqueued earlier are not ready. This is not actually an error...
Definition: hip_runtime_api.h:207
size_t maxSharedMemoryPerMultiProcessor
Maximum Shared Memory Per Multiprocessor.
Definition: hip_runtime_api.h:107
int pciDeviceID
PCI Device ID.
Definition: hip_runtime_api.h:106
char name[256]
Device name.
Definition: hip_runtime_api.h:84
Produced when trying to unlock a non-page-locked memory.
Definition: hip_runtime_api.h:215
Definition: hip_runtime_api.h:44
Contains C function APIs for HIP runtime. This file does not use any HCC builtin or special language ...
int memoryClockRate
Max global memory clock frequency in khz.
Definition: hip_runtime_api.h:93
TODO comment from hipErrorInitializationError.
Definition: hip_runtime_api.h:194
Produced when input context is invalid.
Definition: hip_runtime_api.h:164
Device can possibly execute multiple kernels concurrently.
Definition: hip_runtime_api.h:246
int multiProcessorCount
Number of multi-processors (compute units).
Definition: hip_runtime_api.h:98
Out of resources error.
Definition: hip_runtime_api.h:198