HIP: Heterogenous-computing Interface for Portability
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
hip_runtime_api.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2015-2016 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 //#pragma once
23 #ifndef HIP_RUNTIME_API_H
24 #define HIP_RUNTIME_API_H
25 
30 #include <stdint.h>
31 #include <stddef.h>
32 
33 #include <hip/hcc_detail/host_defines.h>
34 #include <hip/hip_runtime_api.h>
35 //#include "hip/hip_hcc.h"
36 
37 #if defined (__HCC__) && (__hcc_workweek__ < 16155)
38 #error("This version of HIP requires a newer version of HCC.");
39 #endif
40 
41 // Structure definitions:
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 typedef struct ihipStream_t *hipStream_t;
47 typedef struct hipEvent_t {
48  struct ihipEvent_t *_handle;
49 } hipEvent_t;
50 
51 
56 #define hipStreamDefault 0x00
58 #define hipStreamNonBlocking 0x01
59 
60 
62 #define hipEventDefault 0x0
63 #define hipEventBlockingSync 0x1
64 #define hipEventDisableTiming 0x2
65 #define hipEventInterprocess 0x4
66 
67 
69 #define hipHostMallocDefault 0x0
70 #define hipHostMallocPortable 0x1
71 #define hipHostMallocMapped 0x2
72 #define hipHostMallocWriteCombined 0x4
73 
75 #define hipHostRegisterDefault 0x0
76 #define hipHostRegisterPortable 0x1
77 #define hipHostRegisterMapped 0x2
78 #define hipHostRegisterIoMemory 0x4
79 
80 
81 #define hipDeviceScheduleAuto 0x0
82 #define hipDeviceScheduleSpin 0x1
83 #define hipDeviceScheduleYield 0x2
84 #define hipDeviceBlockingSync 0x4
85 #define hipDeviceMapHost 0x8
86 #define hipDeviceLmemResizeToMax 0x16
87 
91 typedef enum hipFuncCache {
96 } hipFuncCache;
97 
98 
102 typedef enum hipSharedMemConfig {
107 
108 
109 
114 typedef struct dim3 {
115  uint32_t x;
116  uint32_t y;
117  uint32_t z;
118 #ifdef __cplusplus
119  dim3(uint32_t _x=1, uint32_t _y=1, uint32_t _z=1) : x(_x), y(_y), z(_z) {};
120 #endif
121 } dim3;
122 
123 
124 
129 typedef enum hipMemcpyKind {
135 } hipMemcpyKind;
136 
137 
138 
139 
140 // Doxygen end group GlobalDefs
144 //-------------------------------------------------------------------------------------------------
145 
146 
147 // The handle allows the async commands to use the stream even if the parent hipStream_t goes out-of-scope.
148 //typedef class ihipStream_t * hipStream_t;
149 
150 
151 /*
152  * Opaque structure allows the true event (pointed at by the handle) to remain "live" even if the surrounding hipEvent_t goes out-of-scope.
153  * This is handy for cases where the hipEvent_t goes out-of-scope but the true event is being written by some async queue or device */
154 //typedef struct hipEvent_t {
155 // struct ihipEvent_t *_handle;
156 //} hipEvent_t;
157 
158 
159 
160 
161 
162 
163 
188 
189 
190 
202 
203 
228 hipError_t hipSetDevice(int device);
229 
230 
242 hipError_t hipGetDevice(int *device);
243 
244 
252 hipError_t hipGetDeviceCount(int *count);
253 
260 hipError_t hipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device);
261 
271 
272 
273 
274 //Cache partitioning functions:
275 
283 
284 
292 
293 
301 
302 //---
303 //Shared bank config functions:
304 
312 
313 
321 
328 hipError_t hipSetDeviceFlags ( unsigned flags);
329 
330 // end doxygen Device
351 
352 
365 
366 
367 
376 const char *hipGetErrorName(hipError_t hip_error);
377 
378 
389 const char *hipGetErrorString(hipError_t hip_error);
390 
391 // end doxygen Error
424 hipError_t hipStreamCreateWithFlags(hipStream_t *stream, unsigned int flags);
425 
426 
427 
442 hipError_t hipStreamCreate(hipStream_t *stream);
443 
444 
460 hipError_t hipStreamWaitEvent(hipStream_t stream, hipEvent_t event, unsigned int flags);
461 
462 
474 hipError_t hipStreamSynchronize(hipStream_t stream);
475 
476 
490 hipError_t hipStreamDestroy(hipStream_t stream);
491 
492 
506 hipError_t hipStreamGetFlags(hipStream_t stream, unsigned int *flags);
507 
508 
509 // end doxygen Stream
534 hipError_t hipEventCreateWithFlags(hipEvent_t* event, unsigned flags);
535 
536 
544 
545 
570 #ifdef __cplusplus
571 hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream = NULL);
572 #else
573 hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream);
574 #endif
575 
587 
588 
603 
604 
629 hipError_t hipEventElapsedTime(float *ms, hipEvent_t start, hipEvent_t stop);
630 
631 
645 
646 
647 // end doxygen Events
673 
681 hipError_t hipMalloc(void** ptr, size_t size) ;
682 
683 
691 hipError_t hipMallocHost(void** ptr, size_t size) __attribute__((deprecated("use hipHostMalloc instead"))) ;
692 
701 hipError_t hipHostMalloc(void** ptr, size_t size, unsigned int flags) ;
702 hipError_t hipHostAlloc(void** ptr, size_t size, unsigned int flags) __attribute__((deprecated("use hipHostMalloc instead"))) ;;
703 
712 hipError_t hipHostGetDevicePointer(void** devPtr, void* hstPtr, unsigned int flags) ;
713 
721 hipError_t hipHostGetFlags(unsigned int* flagsPtr, void* hostPtr) ;
722 
753 hipError_t hipHostRegister(void* hostPtr, size_t sizeBytes, unsigned int flags) ;
754 
761 hipError_t hipHostUnregister(void* hostPtr) ;
762 
763 
771 hipError_t hipFree(void* ptr);
772 
773 
774 
781 hipError_t hipFreeHost(void* ptr) __attribute__((deprecated("use hipHostFree instead"))) ;
782 
783 
790 hipError_t hipHostFree(void* ptr);
791 
792 
793 
807 hipError_t hipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind);
808 
809 
824 hipError_t hipMemcpyToSymbol(const char* symbolName, const void *src, size_t sizeBytes, size_t offset, hipMemcpyKind kind);
825 
826 
839 #if __cplusplus
840 hipError_t hipMemcpyAsync(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind, hipStream_t stream=0);
841 #else
842 hipError_t hipMemcpyAsync(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind, hipStream_t stream);
843 #endif
844 
857 hipError_t hipMemset(void* dst, int value, size_t sizeBytes );
858 
859 
873 #if __cplusplus
874 hipError_t hipMemsetAsync(void* dst, int value, size_t sizeBytes, hipStream_t = 0 );
875 #else
876 hipError_t hipMemsetAsync(void* dst, int value, size_t sizeBytes, hipStream_t stream);
877 #endif
878 
885 hipError_t hipMemGetInfo (size_t * free, size_t * total) ;
886 
887 // doxygen end Memory
919 hipError_t hipDeviceCanAccessPeer (int* canAccessPeer, int deviceId, int peerDeviceId);
920 
921 
936 hipError_t hipDeviceEnablePeerAccess (int peerDeviceId, unsigned int flags);
937 
938 
948 hipError_t hipDeviceDisablePeerAccess (int peerDeviceId);
949 
950 
962 hipError_t hipMemcpyPeer (void* dst, int dstDeviceId, const void* src, int srcDeviceId, size_t sizeBytes);
963 
976 #if __cplusplus
977 hipError_t hipMemcpyPeerAsync ( void* dst, int dstDeviceId, const void* src, int srcDevice, size_t sizeBytes, hipStream_t stream=0 );
978 #else
979 hipError_t hipMemcpyPeerAsync(void* dst, int dstDevice, const void* src, int srcDevice, size_t sizeBytes, hipStream_t stream);
980 #endif
981 // doxygen end PeerToPeer
1005 hipError_t hipDriverGetVersion(int *driverVersion) ;
1006 
1007 
1008 
1009 // doxygen end Version Management
1036 #ifdef __cplusplus
1037 } /* extern "c" */
1038 #endif
1039 
1040 
1058 // end-group HCC_Specific
1065 // doxygen end HIP API
1070 #endif
hipError_t hipHostFree(void *ptr)
Free memory allocated by the hcc hip host memory allocation API.
Definition: hip_memory.cpp:488
hipError_t hipMemcpyAsync(void *dst, const void *src, size_t sizeBytes, hipMemcpyKind kind, hipStream_t stream)
Copy data from src to dst asynchronously.
Definition: hip_memory.cpp:343
hipError_t hipPeekAtLastError(void)
Return last error returned by any HIP runtime API call.
struct dim3 dim3
hipError_t hipGetDeviceProperties(hipDeviceProp_t *prop, int device)
Returns device properties.
Definition: hip_device.cpp:267
hipError_t hipMemcpyToSymbol(const char *symbolName, const void *src, size_t sizeBytes, size_t offset, hipMemcpyKind kind)
Copies sizeBytes bytes from the memory area pointed to by src to the memory area pointed to by offset...
Definition: hip_memory.cpp:291
hipError_t hipFuncSetCacheConfig(hipFuncCache config)
Set Cache configuration for a specific function.
Definition: hip_device.cpp:90
no preference for shared memory or L1 (default)
Definition: hip_runtime_api.h:92
uint32_t x
x
Definition: hip_runtime_api.h:115
Host-to-Device Copy.
Definition: hip_runtime_api.h:131
hipError_t hipDeviceEnablePeerAccess(int peerDeviceId, unsigned int flags)
Enable direct access from current device's virtual address space to memory allocations physically loc...
Definition: hip_peer.cpp:101
hipError_t hipDeviceGetSharedMemConfig(hipSharedMemConfig *pConfig)
Get Shared memory bank configuration.
Definition: hip_device.cpp:120
hipError_t hipSetDevice(int device)
Set default device to be used for subsequent hip API calls from this thread.
Definition: hip_device.cpp:133
Definition: hip_runtime_api.h:117
Device-to-Host Copy.
Definition: hip_runtime_api.h:132
hipError_t hipHostGetDevicePointer(void **devPtr, void *hstPtr, unsigned int flags)
Get Device pointer from Host Pointer allocated through hipHostAlloc.
hipError_t hipEventSynchronize(hipEvent_t event)
: Wait for an event to complete.
Definition: hip_event.cpp:121
hipError_t hipSetDeviceFlags(unsigned flags)
Set Device flags.
hipFuncCache
Definition: hip_runtime_api.h:91
hipError_t hipEventQuery(hipEvent_t event)
Query event status.
Definition: hip_event.cpp:199
hipError_t hipDeviceGetCacheConfig(hipFuncCache *cacheConfig)
Set Cache configuration for a specific function.
Definition: hip_device.cpp:76
hipError_t hipDeviceDisablePeerAccess(int peerDeviceId)
Disable direct access from current device's virtual address space to memory allocations physically lo...
Definition: hip_peer.cpp:61
hipError_t hipDeviceGetAttribute(int *pi, hipDeviceAttribute_t attr, int device)
Query device attribute.
Definition: hip_device.cpp:191
hipError_t hipMallocHost(void **ptr, size_t size) __attribute__((deprecated("use hipHostMalloc instead")))
Allocate pinned host memory.
Definition: hip_memory.cpp:203
hipError_t hipGetDevice(int *device)
Return the default device id for the calling host thread.
Definition: hip_device.cpp:31
hipError_t hipHostMalloc(void **ptr, size_t size, unsigned int flags)
Allocate device accessible page locked host memory.
Definition: hip_memory.cpp:152
hipDeviceAttribute_t
Definition: hip_runtime_api.h:170
hipError_t hipEventDestroy(hipEvent_t event)
Destroy the specified event.
Definition: hip_event.cpp:106
hipError_t hipStreamCreateWithFlags(hipStream_t *stream, unsigned int flags)
Create an asynchronous stream.
Definition: hip_stream.cpp:54
Definition: hip_runtime_api.h:114
uint32_t y
y
Definition: hip_runtime_api.h:116
prefer equal size L1 cache and shared memory
Definition: hip_runtime_api.h:95
hipError_t hipEventCreateWithFlags(hipEvent_t *event, unsigned flags)
Create an event with the specified flags.
Definition: hip_event.cpp:53
hipError_t hipEventElapsedTime(float *ms, hipEvent_t start, hipEvent_t stop)
Return the elapsed time between two events.
Definition: hip_event.cpp:154
hipError_t hipDeviceCanAccessPeer(int *canAccessPeer, int deviceId, int peerDeviceId)
Determine if a device can access a peer's memory.
Definition: hip_peer.cpp:30
hipError_t hipGetDeviceCount(int *count)
Return number of compute-capable devices.
Definition: hip_device.cpp:44
hipError_t hipMemset(void *dst, int value, size_t sizeBytes)
Copy data from src to dst asynchronously.
Definition: hip_memory.cpp:422
hipError_t hipStreamDestroy(hipStream_t stream)
Destroys the specified stream.
Definition: hip_stream.cpp:117
hipError_t hipHostGetFlags(unsigned int *flagsPtr, void *hostPtr)
Get flags associated with host pointer.
Definition: hip_memory.cpp:210
hipError_t hipStreamSynchronize(hipStream_t stream)
Wait for all commands in stream to complete.
Definition: hip_stream.cpp:94
Shared mem is banked at 4-bytes intervals and performs best when adjacent threads access data 4 bytes...
Definition: hip_runtime_api.h:104
hipError_t
Definition: hip_runtime_api.h:142
hipMemcpyKind
Definition: hip_runtime_api.h:129
prefer larger L1 cache and smaller shared memory
Definition: hip_runtime_api.h:94
hipError_t hipDriverGetVersion(int *driverVersion)
Returns the approximate HIP driver version.
Definition: hip_peer.cpp:156
hipError_t hipDeviceSynchronize(void)
Blocks until the default device has completed all preceding requested tasks.
Definition: hip_device.cpp:149
Definition: hip_runtime_api.h:47
hipError_t hipHostRegister(void *hostPtr, size_t sizeBytes, unsigned int flags)
Register host memory so it can be accessed from the current device.
Definition: hip_memory.cpp:236
hipError_t hipDeviceSetCacheConfig(hipFuncCache cacheConfig)
Set L1/Shared cache partition.
Definition: hip_device.cpp:62
hipError_t hipMalloc(void **ptr, size_t size)
Allocate memory on the default accelerator.
Definition: hip_memory.cpp:117
const char * hipGetErrorName(hipError_t hip_error)
Return name of the specified error code in text form.
Definition: hip_error.cpp:53
hipError_t hipGetLastError(void)
Return last error returned by any HIP runtime API call and resets the stored error code to hipSuccess...
Definition: hip_error.cpp:31
hipError_t hipStreamWaitEvent(hipStream_t stream, hipEvent_t event, unsigned int flags)
Make the specified compute stream wait for an event.
Definition: hip_stream.cpp:75
hipError_t hipStreamGetFlags(hipStream_t stream, unsigned int *flags)
Return flags associated with this stream.
Definition: hip_stream.cpp:146
hipError_t hipMemGetInfo(size_t *free, size_t *total)
Query memory info. Return snapshot of free memory, and total allocatable memory on the device...
Definition: hip_memory.cpp:435
hipError_t hipFree(void *ptr)
Free memory allocated by the hcc hip memory allocation API. This API performs an implicit hipDeviceSy...
Definition: hip_memory.cpp:463
uint32_t z
z
Definition: hip_runtime_api.h:117
hipError_t hipDeviceReset(void)
Destroy all resources and reset all state on the default device in the current process.
Definition: hip_device.cpp:163
Definition: hip_runtime_api.h:74
hipError_t hipMemsetAsync(void *dst, int value, size_t sizeBytes, hipStream_t stream)
Fills the first sizeBytes bytes of the memory area pointed to by dev with the constant byte value val...
Definition: hip_memory.cpp:372
The compiler selects a device-specific value for the banking.
Definition: hip_runtime_api.h:103
Device-to-Device Copy.
Definition: hip_runtime_api.h:133
Definition: hip_hcc.h:483
hipError_t hipMemcpyPeerAsync(void *dst, int dstDevice, const void *src, int srcDevice, size_t sizeBytes, hipStream_t stream)
Copies memory from one device to memory on another device.
Definition: hip_peer.cpp:144
Runtime will automatically determine copy-kind based on virtual addresses.
Definition: hip_runtime_api.h:134
hipSharedMemConfig
Definition: hip_runtime_api.h:102
hipError_t hipHostUnregister(void *hostPtr)
Un-register host pointer.
Definition: hip_memory.cpp:272
Definition: hip_hcc.h:399
hipError_t hipMemcpyPeer(void *dst, int dstDeviceId, const void *src, int srcDeviceId, size_t sizeBytes)
Copies memory from one device to memory on another device.
Definition: hip_peer.cpp:131
hipError_t hipStreamCreate(hipStream_t *stream)
Create an asynchronous stream.
Definition: hip_stream.cpp:63
hipError_t hipMemcpy(void *dst, const void *src, size_t sizeBytes, hipMemcpyKind kind)
Copy data from src to dst.
Definition: hip_memory.cpp:312
hipError_t hipEventCreate(hipEvent_t *event)
Definition: hip_event.cpp:61
hipError_t hipFreeHost(void *ptr) __attribute__((deprecated("use hipHostFree instead")))
Free memory allocated by the hcc hip host memory allocation API.
Definition: hip_memory.cpp:513
hipError_t hipDeviceSetSharedMemConfig(hipSharedMemConfig config)
Set Shared memory bank configuration.
Definition: hip_device.cpp:105
hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream)
Record an event in the specified stream.
Definition: hip_event.cpp:70
prefer larger shared memory and smaller L1 cache
Definition: hip_runtime_api.h:93
Host-to-Host Copy.
Definition: hip_runtime_api.h:130
hipError_t hipPointerGetAttributes(hipPointerAttribute_t *attributes, void *ptr)
Return attributes for the specified pointer.
Definition: hip_memory.cpp:37
Shared mem is banked at 8-byte intervals and performs best when adjacent threads access data 4 bytes ...
Definition: hip_runtime_api.h:105
const char * hipGetErrorString(hipError_t hip_error)
Return handy text string message to explain the error which occurred.
Definition: hip_error.cpp:66