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 
29 #include <stdint.h>
30 #include <stddef.h>
31 
33 
34 #if defined (__HCC__) && (__hcc_workweek__ < 1602)
35 #error("This version of HIP requires a newer version of HCC.");
36 #endif
37 
38 // Structure definitions:
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
47 #define hipStreamDefault 0x00
49 #define hipStreamNonBlocking 0x01
50 
51 
53 #define hipEventDefault 0x0
54 #define hipEventBlockingSync 0x1
55 #define hipEventDisableTiming 0x2
56 #define hipEventInterprocess 0x4
57 
58 
60 #define hipHostMallocDefault 0x0
61 #define hipHostMallocPortable 0x1
62 #define hipHostMallocMapped 0x2
63 #define hipHostMallocWriteCombined 0x4
64 
66 #define hipHostRegisterDefault 0x0
67 #define hipHostRegisterPortable 0x1
68 #define hipHostRegisterMapped 0x2
69 #define hipHostRegisterIoMemory 0x4
70 
71 
74 typedef enum hipFuncCache {
79 } hipFuncCache;
80 
81 
85 typedef enum hipSharedMemConfig {
90 
91 
92 
97 typedef struct dim3 {
98  uint32_t x;
99  uint32_t y;
100  uint32_t z;
101 
102  dim3(uint32_t _x=1, uint32_t _y=1, uint32_t _z=1) : x(_x), y(_y), z(_z) {};
103 } dim3;
104 
105 
106 
117 } ;
118 
119 
120 
121 
122 // Doxygen end group GlobalDefs
126 //-------------------------------------------------------------------------------------------------
127 
128 
129 // The handle allows the async commands to use the stream even if the parent hipStream_t goes out-of-scope.
130 typedef class ihipStream_t * hipStream_t;
131 
132 
133 /*
134  * Opaque structure allows the true event (pointed at by the handle) to remain "live" even if the surrounding hipEvent_t goes out-of-scope.
135  * 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 */
136 typedef struct hipEvent_t {
137  struct ihipEvent_t *_handle;
138 } hipEvent_t;
139 
140 
141 
142 
143 
144 
145 
146 #ifdef __cplusplus
147 } /* extern "C" */
148 #endif
149 
150 
151 
152 
153 //==================================================================================================
154 #ifdef __cplusplus
155 extern "C" {
156 #endif
157 
182 
183 
184 
196 
197 
222 hipError_t hipSetDevice(int device);
223 
224 
236 hipError_t hipGetDevice(int *device);
237 
238 
246 hipError_t hipGetDeviceCount(int *count);
247 
254 hipError_t hipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device);
255 
265 
266 
267 
268 //Cache partitioning functions:
269 
277 
278 
286 
287 
295 
296 //---
297 //Shared bank config functions:
298 
306 
307 
315 
316 
317 // end doxygen Device
338 
339 
352 
353 
354 
363 const char *hipGetErrorName(hipError_t hip_error);
364 
365 
376 const char *hipGetErrorString(hipError_t hip_error);
377 
378 // end doxygen Error
411 hipError_t hipStreamCreateWithFlags(hipStream_t *stream, unsigned int flags);
412 
413 
414 
429 static inline hipError_t hipStreamCreate(hipStream_t *stream)
430 {
432 }
433 
434 
450 hipError_t hipStreamWaitEvent(hipStream_t stream, hipEvent_t event, unsigned int flags);
451 
452 
464 hipError_t hipStreamSynchronize(hipStream_t stream);
465 
466 
480 hipError_t hipStreamDestroy(hipStream_t stream);
481 
482 
496 hipError_t hipStreamGetFlags(hipStream_t stream, unsigned int *flags);
497 
498 
499 // end doxygen Stream
524 hipError_t hipEventCreateWithFlags(hipEvent_t* event, unsigned flags);
525 
526 
533 static inline hipError_t hipEventCreate(hipEvent_t* event)
534 {
535  return hipEventCreateWithFlags(event, 0);
536 }
537 
538 
564 hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream = NULL);
565 
566 
578 
579 
594 
595 
620 hipError_t hipEventElapsedTime(float *ms, hipEvent_t start, hipEvent_t stop);
621 
622 
636 
637 
638 // end doxygen Events
664 
665 
673 hipError_t hipMalloc(void** ptr, size_t size) ;
674 
675 
683 hipError_t hipMallocHost(void** ptr, size_t size) __attribute__((deprecated("use hipHostMalloc instead"))) ;
684 
693 hipError_t hipHostMalloc(void** ptr, size_t size, unsigned int flags) ;
694 hipError_t hipHostAlloc(void** ptr, size_t size, unsigned int flags) __attribute__((deprecated("use hipHostMalloc instead"))) ;;
695 
704 hipError_t hipHostGetDevicePointer(void** devPtr, void* hstPtr, unsigned int flags) ;
705 
713 hipError_t hipHostGetFlags(unsigned int* flagsPtr, void* hostPtr) ;
714 
745 hipError_t hipHostRegister(void* hostPtr, size_t sizeBytes, unsigned int flags) ;
746 
753 hipError_t hipHostUnregister(void* hostPtr) ;
754 
755 
763 hipError_t hipFree(void* ptr);
764 
765 
766 
773 hipError_t hipFreeHost(void* ptr) __attribute__((deprecated("use hipHostFree instead"))) ;
774 
775 
782 hipError_t hipHostFree(void* ptr);
783 
784 
785 
799 hipError_t hipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind);
800 
801 
816 hipError_t hipMemcpyToSymbol(const char* symbolName, const void *src, size_t sizeBytes, size_t offset, hipMemcpyKind kind);
817 
818 
831 hipError_t hipMemcpyAsync(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind, hipStream_t stream=0);
832 
833 
846 hipError_t hipMemset(void* dst, int value, size_t sizeBytes );
847 
848 
862 hipError_t hipMemsetAsync(void* dst, int value, size_t sizeBytes, hipStream_t = 0 );
863 
864 
871 hipError_t hipMemGetInfo (size_t * free, size_t * total) ;
872 
873 // doxygen end Memory
898 hipError_t hipDeviceCanAccessPeer ( int* canAccessPeer, int device, int peerDevice );
899 
900 
901 
912 hipError_t hipDeviceDisablePeerAccess ( int peerDevice );
913 
923 hipError_t hipDeviceEnablePeerAccess ( int peerDevice, unsigned int flags );
924 
936 hipError_t hipMemcpyPeer ( void* dst, int dstDevice, const void* src, int srcDevice, size_t sizeBytes );
937 
950 hipError_t hipMemcpyPeerAsync ( void* dst, int dstDevice, const void* src, int srcDevice, size_t sizeBytes, hipStream_t stream=0 );
951 // doxygen end PeerToPeer
975 hipError_t hipDriverGetVersion(int *driverVersion) ;
976 
977 
978 
979 // doxygen end Version Management
1006 #ifdef __cplusplus
1007 } /* extern "c" */
1008 #endif
1009 
1010 
1028 #ifdef __HCC__
1029 #include <hc.hpp>
1033 hipError_t hipHccGetAccelerator(int deviceId, hc::accelerator *acc);
1034 
1038 hipError_t hipHccGetAcceleratorView(hipStream_t stream, hc::accelerator_view **av);
1039 #endif
1040 
1041 
1042 // end-group HCC_Specific
1049 // doxygen end HIP API
hipError_t hipHostFree(void *ptr)
Free memory allocated by the hcc hip host memory allocation API.
Definition: hip_hcc.cpp:2750
hipError_t hipDeviceEnablePeerAccess(int peerDevice, unsigned int flags)
Enables registering memory on peerDevice for direct access from the current device.
Definition: hip_hcc.cpp:2812
hipError_t hipDeviceCanAccessPeer(int *canAccessPeer, int device, int peerDevice)
Determine if a device can access a peer's memory.
Definition: hip_hcc.cpp:2786
hipError_t hipPeekAtLastError(void)
Return last error returned by any HIP runtime API call.
hipError_t hipHccGetAcceleratorView(hipStream_t stream, hc::accelerator_view **av)
Return hc::accelerator_view associated with the specified stream.
Definition: hip_hcc.cpp:2886
struct dim3 dim3
TODO-doc.
hipError_t hipMemsetAsync(void *dst, int value, size_t sizeBytes, hipStream_t=0)
Fills the first sizeBytes bytes of the memory area pointed to by dev with the constant byte value val...
Definition: hip_hcc.cpp:2632
hipError_t hipGetDeviceProperties(hipDeviceProp_t *prop, int device)
Returns device properties.
Definition: hip_hcc.cpp:1586
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_hcc.cpp:2326
hipError_t hipFuncSetCacheConfig(hipFuncCache config)
Set Cache configuration for a specific function.
Definition: hip_hcc.cpp:1405
no preference for shared memory or L1 (default)
Definition: hip_runtime_api.h:75
uint32_t x
x
Definition: hip_runtime_api.h:98
Host-to-Device Copy.
Definition: hip_runtime_api.h:113
hipError_t hipDeviceGetSharedMemConfig(hipSharedMemConfig *pConfig)
Get Shared memory bank configuration.
Definition: hip_hcc.cpp:1435
hipError_t hipSetDevice(int device)
Set default device to be used for subsequent hip API calls from this thread.
Definition: hip_hcc.cpp:1448
Definition: hip_runtime_api.h:117
Device-to-Host Copy.
Definition: hip_runtime_api.h:114
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_hcc.cpp:1886
hipFuncCache
Definition: hip_runtime_api.h:74
hipError_t hipEventQuery(hipEvent_t event)
Query event status.
Definition: hip_hcc.cpp:1983
hipError_t hipDeviceGetCacheConfig(hipFuncCache *cacheConfig)
Set Cache configuration for a specific function.
Definition: hip_hcc.cpp:1391
hipError_t hipMemcpyPeer(void *dst, int dstDevice, const void *src, int srcDevice, size_t sizeBytes)
Copies memory from one device to memory on another device.
Definition: hip_hcc.cpp:2821
hipError_t hipDeviceGetAttribute(int *pi, hipDeviceAttribute_t attr, int device)
Query device attribute.
Definition: hip_hcc.cpp:1510
hipError_t hipMallocHost(void **ptr, size_t size) __attribute__((deprecated("use hipHostMalloc instead")))
Allocate pinned host memory.
Definition: hip_hcc.cpp:2190
hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream=NULL)
Record an event in the specified stream.
Definition: hip_hcc.cpp:1836
hipError_t hipGetDevice(int *device)
Return the default device id for the calling host thread.
Definition: hip_hcc.cpp:1346
hipError_t hipHostMalloc(void **ptr, size_t size, unsigned int flags)
Allocate device accessible page locked host memory.
Definition: hip_hcc.cpp:2214
hipDeviceAttribute_t
Definition: hip_runtime_api.h:168
hipError_t hipEventDestroy(hipEvent_t event)
Destroy the specified event.
Definition: hip_hcc.cpp:1871
hipError_t hipStreamCreateWithFlags(hipStream_t *stream, unsigned int flags)
Create an asynchronous stream.
Definition: hip_hcc.cpp:1690
hipError_t hipDeviceDisablePeerAccess(int peerDevice)
Disables registering memory on peerDevice for direct access from the current device.
Definition: hip_hcc.cpp:2799
Definition: hip_runtime_api.h:97
uint32_t y
y
Definition: hip_runtime_api.h:99
prefer equal size L1 cache and shared memory
Definition: hip_runtime_api.h:78
hipError_t hipEventCreateWithFlags(hipEvent_t *event, unsigned flags)
Create an event with the specified flags.
Definition: hip_hcc.cpp:1811
hipError_t hipEventElapsedTime(float *ms, hipEvent_t start, hipEvent_t stop)
Return the elapsed time between two events.
Definition: hip_hcc.cpp:1938
hipError_t hipMemcpyPeerAsync(void *dst, int dstDevice, const void *src, int srcDevice, size_t sizeBytes, hipStream_t stream=0)
Copies memory from one device to memory on another device.
Definition: hip_hcc.cpp:2833
hipError_t hipGetDeviceCount(int *count)
Return number of compute-capable devices.
Definition: hip_hcc.cpp:1359
hipError_t hipMemset(void *dst, int value, size_t sizeBytes)
Copy data from src to dst asynchronously.
Definition: hip_hcc.cpp:2682
hipError_t hipStreamDestroy(hipStream_t stream)
Destroys the specified stream.
Definition: hip_hcc.cpp:1759
hipError_t hipHostGetFlags(unsigned int *flagsPtr, void *hostPtr)
Get flags associated with host pointer.
Definition: hip_hcc.cpp:2252
hipError_t hipStreamSynchronize(hipStream_t stream)
Wait for all commands in stream to complete.
Definition: hip_hcc.cpp:1736
Shared mem is banked at 4-bytes intervals and performs best when adjacent threads access data 4 bytes...
Definition: hip_runtime_api.h:87
hipError_t
Definition: hip_runtime_api.h:142
hipMemcpyKind
Definition: hip_runtime_api.h:111
prefer larger L1 cache and smaller shared memory
Definition: hip_runtime_api.h:77
hipError_t hipDriverGetVersion(int *driverVersion)
Returns the approximate HIP driver version.
Definition: hip_hcc.cpp:2845
hipError_t hipDeviceSynchronize(void)
Blocks until the default device has completed all preceding requested tasks.
Definition: hip_hcc.cpp:1465
Definition: hip_runtime_api.h:136
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_hcc.cpp:2276
hipError_t hipDeviceSetCacheConfig(hipFuncCache cacheConfig)
Set L1/Shared cache partition.
Definition: hip_hcc.cpp:1377
hipError_t hipMalloc(void **ptr, size_t size)
Allocate memory on the default accelerator.
Definition: hip_hcc.cpp:2165
const char * hipGetErrorName(hipError_t hip_error)
Return name of the specified error code in text form.
Definition: hip_hcc.cpp:1661
hipError_t hipGetLastError(void)
Return last error returned by any HIP runtime API call and resets the stored error code to hipSuccess...
Definition: hip_hcc.cpp:1614
hipError_t hipStreamWaitEvent(hipStream_t stream, hipEvent_t event, unsigned int flags)
Make the specified compute stream wait for an event.
Definition: hip_hcc.cpp:1716
hipError_t hipStreamGetFlags(hipStream_t stream, unsigned int *flags)
Return flags associated with this stream.
Definition: hip_hcc.cpp:1788
#define hipStreamDefault
Flags that can be used with hipStreamCreateWithFlags.
Definition: hip_runtime_api.h:48
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_hcc.cpp:2695
hipError_t hipFree(void *ptr)
Free memory allocated by the hcc hip memory allocation API. This API performs an implicit hipDeviceSy...
Definition: hip_hcc.cpp:2725
uint32_t z
z
Definition: hip_runtime_api.h:100
hipError_t hipDeviceReset(void)
Destroy all resources and reset all state on the default device in the current process.
Definition: hip_hcc.cpp:1480
Definition: hip_runtime_api.h:74
hipError_t hipMemcpyAsync(void *dst, const void *src, size_t sizeBytes, hipMemcpyKind kind, hipStream_t stream=0)
Copy data from src to dst asynchronously.
Definition: hip_hcc.cpp:2603
The compiler selects a device-specific value for the banking.
Definition: hip_runtime_api.h:86
Device-to-Device Copy.
Definition: hip_runtime_api.h:115
Definition: hip_hcc.cpp:363
Runtime will automatically determine copy-kind based on virtual addresses.
Definition: hip_runtime_api.h:116
hipSharedMemConfig
Definition: hip_runtime_api.h:85
hipError_t hipHostUnregister(void *hostPtr)
Un-register host pointer.
Definition: hip_hcc.cpp:2307
Definition: hip_hcc.cpp:284
hipError_t hipMemcpy(void *dst, const void *src, size_t sizeBytes, hipMemcpyKind kind)
Copy data from src to dst.
Definition: hip_hcc.cpp:2569
hipError_t hipFreeHost(void *ptr) __attribute__((deprecated("use hipHostFree instead")))
Free memory allocated by the hcc hip host memory allocation API.
Definition: hip_hcc.cpp:2775
hipError_t hipDeviceSetSharedMemConfig(hipSharedMemConfig config)
Set Shared memory bank configuration.
Definition: hip_hcc.cpp:1420
prefer larger shared memory and smaller L1 cache
Definition: hip_runtime_api.h:76
Host-to-Host Copy.
Definition: hip_runtime_api.h:112
hipError_t hipHccGetAccelerator(int deviceId, hc::accelerator *acc)
Return hc::accelerator associated with the specified deviceId.
Definition: hip_hcc.cpp:2866
hipError_t hipPointerGetAttributes(hipPointerAttribute_t *attributes, void *ptr)
Return attributes for the specified pointer.
Definition: hip_hcc.cpp:2012
Shared mem is banked at 8-byte intervals and performs best when adjacent threads access data 4 bytes ...
Definition: hip_runtime_api.h:88
const char * hipGetErrorString(hipError_t hip_error)
Return handy text string message to explain the error which occurred.
Definition: hip_hcc.cpp:1674