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 
62 typedef enum hipFuncCache {
67 } hipFuncCache;
68 
69 
73 typedef enum hipSharedMemConfig {
78 
79 
80 
85 typedef struct dim3 {
86  uint32_t x;
87  uint32_t y;
88  uint32_t z;
89 
90  dim3(uint32_t _x=1, uint32_t _y=1, uint32_t _z=1) : x(_x), y(_y), z(_z) {};
91 } dim3;
92 
93 
94 
105 } ;
106 
107 
108 // Doxygen end group GlobalDefs
112 //-------------------------------------------------------------------------------------------------
113 
114 
115 // The handle allows the async commands to use the stream even if the parent hipStream_t goes out-of-scope.
116 typedef struct ihipStream_t * hipStream_t;
117 
118 
119 /*
120  * Opaque structure allows the true event (pointed at by the handle) to remain "live" even if the surrounding hipEvent_t goes out-of-scope.
121  * 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 */
122 typedef struct hipEvent_t {
123  struct ihipEvent_t *_handle;
124 } hipEvent_t;
125 
126 
127 
128 
129 
130 
131 #ifdef __cplusplus
132 } /* extern "C" */
133 #endif
134 
135 
136 
137 
138 //==================================================================================================
139 #ifdef __cplusplus
140 extern "C" {
141 #endif
142 
167 
168 
169 
181 
182 
207 hipError_t hipSetDevice(int device);
208 
209 
221 hipError_t hipGetDevice(int *device);
222 
223 
231 hipError_t hipGetDeviceCount(int *count);
232 
239 hipError_t hipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device);
240 
250 
251 
252 
253 //Cache partitioning functions:
254 
262 
263 
271 
272 
280 
281 //---
282 //Shared bank config functions:
283 
291 
292 
300 
301 
302 // end doxygen Device
323 
324 
337 
338 
339 
348 const char *hipGetErrorName(hipError_t hip_error);
349 
350 
361 const char *hipGetErrorString(hipError_t hip_error);
362 
363 // end doxygen Error
393 hipError_t hipStreamCreateWithFlags(hipStream_t *stream, unsigned int flags);
394 
395 
396 
406 static inline hipError_t hipStreamCreate(hipStream_t *stream)
407 {
409 }
410 
411 
427 hipError_t hipStreamWaitEvent(hipStream_t stream, hipEvent_t event, unsigned int flags);
428 
429 
442 
443 
458 
459 
473 hipError_t hipStreamGetFlags(hipStream_t stream, unsigned int *flags);
474 
475 
476 // end doxygen Stream
501 hipError_t hipEventCreateWithFlags(hipEvent_t* event, unsigned flags);
502 
503 
510 static inline hipError_t hipEventCreate(hipEvent_t* event)
511 {
512  return hipEventCreateWithFlags(event, 0);
513 }
514 
515 
541 hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream = NULL);
542 
543 
555 
556 
571 
572 
597 hipError_t hipEventElapsedTime(float *ms, hipEvent_t start, hipEvent_t stop);
598 
599 
613 
614 
615 // end doxygen Events
645 hipError_t hipMalloc(void** ptr, size_t size) ;
646 
647 
655 hipError_t hipMallocHost(void** ptr, size_t size) ;
656 
657 
665 hipError_t hipFree(void* ptr);
666 
667 
668 
675 hipError_t hipFreeHost(void* ptr);
676 
677 
678 
693 hipError_t hipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind);
694 
695 
710 hipError_t hipMemcpyToSymbol(const char* symbolName, const void *src, size_t sizeBytes, size_t offset, hipMemcpyKind kind);
711 
712 
724 hipError_t hipMemcpyAsync(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind, hipStream_t stream=0);
725 
726 
739 hipError_t hipMemset(void* dst, int value, size_t sizeBytes );
740 
741 
755 hipError_t hipMemsetAsync(void* dst, int value, size_t sizeBytes, hipStream_t = 0 );
756 
757 
758 /*
759  * @brief Query memory info.
760  * Return snapshot of free memory, and total allocatable memory on the device.
761  *
762  * Returns in *free a snapshot of the current free memory o
763  **/
764 hipError_t hipMemGetInfo (size_t * free, size_t * total) ;
765 
766 // doxygen end Memory
791 hipError_t hipDeviceCanAccessPeer ( int* canAccessPeer, int device, int peerDevice );
792 
793 
794 
805 hipError_t hipDeviceDisablePeerAccess ( int peerDevice );
806 
816 hipError_t hipDeviceEnablePeerAccess ( int peerDevice, unsigned int flags );
817 
829 hipError_t hipMemcpyPeer ( void* dst, int dstDevice, const void* src, int srcDevice, size_t sizeBytes );
830 
843 hipError_t hipMemcpyPeerAsync ( void* dst, int dstDevice, const void* src, int srcDevice, size_t sizeBytes, hipStream_t stream=0 );
844 // doxygen end PeerToPeer
868 hipError_t hipDriverGetVersion(int *driverVersion) ;
869 
870 
871 
872 // doxygen end Version Management
899 #ifdef __cplusplus
900 } /* extern "c" */
901 #endif
902 
903 
921 #ifdef __HCC__
922 #include <hc.hpp>
926 hipError_t hipHccGetAccelerator(int deviceId, hc::accelerator *acc);
927 
931 hipError_t hipHccGetAcceleratorView(hipStream_t stream, hc::accelerator_view **av);
932 #endif
933 
934 
935 // end-group HCC_Specific
942 // doxygen end HIP API
hipError_t hipDeviceEnablePeerAccess(int peerDevice, unsigned int flags)
Enables registering memory on peerDevice for direct access from the current device.
Definition: hip_hcc.cpp:1658
hipError_t hipDeviceCanAccessPeer(int *canAccessPeer, int device, int peerDevice)
Determine if a device can access a peer's memory.
Definition: hip_hcc.cpp:1634
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:1730
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:1513
hipError_t hipFreeHost(void *ptr)
Free memory allocated by the hcc hip host memory allocation API.
Definition: hip_hcc.cpp:1612
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:1410
hipError_t hipFuncSetCacheConfig(hipFuncCache config)
Set Cache configuration for a specific function.
Definition: hip_hcc.cpp:721
no preference for shared memory or L1 (default)
Definition: hip_runtime_api.h:63
uint32_t x
x
Definition: hip_runtime_api.h:86
Host-to-Device Copy.
Definition: hip_runtime_api.h:101
hipError_t hipDeviceGetSharedMemConfig(hipSharedMemConfig *pConfig)
Get Shared memory bank configuration.
Definition: hip_hcc.cpp:751
hipError_t hipSetDevice(int device)
Set default device to be used for subsequent hip API calls from this thread.
Definition: hip_hcc.cpp:764
Device-to-Host Copy.
Definition: hip_runtime_api.h:102
hipError_t hipEventSynchronize(hipEvent_t event)
: Wait for an event to complete.
Definition: hip_hcc.cpp:1157
hipError_t hipDeviceGetProperties(hipDeviceProp_t *prop, int device)
Returns device properties.
Definition: hip_hcc.cpp:884
hipFuncCache
Definition: hip_runtime_api.h:62
hipError_t hipEventQuery(hipEvent_t event)
Query event status.
Definition: hip_hcc.cpp:1252
hipError_t hipDeviceGetCacheConfig(hipFuncCache *cacheConfig)
Set Cache configuration for a specific function.
Definition: hip_hcc.cpp:707
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:1667
hipError_t hipDeviceGetAttribute(int *pi, hipDeviceAttribute_t attr, int device)
Query device attribute.
Definition: hip_hcc.cpp:812
hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream=NULL)
Record an event in the specified stream.
Definition: hip_hcc.cpp:1108
hipError_t hipGetDevice(int *device)
Return the default device id for the calling host thread.
Definition: hip_hcc.cpp:662
hipDeviceAttribute_t
Definition: hip_runtime_api.h:134
hipError_t hipEventDestroy(hipEvent_t event)
Destroy the specified event.
Definition: hip_hcc.cpp:1142
hipError_t hipStreamCreateWithFlags(hipStream_t *stream, unsigned int flags)
Create an asynchronous stream.
Definition: hip_hcc.cpp:974
hipError_t hipDeviceDisablePeerAccess(int peerDevice)
Disables registering memory on peerDevice for direct access from the current device.
Definition: hip_hcc.cpp:1646
Definition: hip_runtime_api.h:85
uint32_t y
y
Definition: hip_runtime_api.h:87
prefer equal size L1 cache and shared memory
Definition: hip_runtime_api.h:66
hipError_t hipEventCreateWithFlags(hipEvent_t *event, unsigned flags)
Create an event with the specified flags.
Definition: hip_hcc.cpp:1085
hipError_t hipMallocHost(void **ptr, size_t size)
Allocate pinned host memory.
Definition: hip_hcc.cpp:1372
hipError_t hipEventElapsedTime(float *ms, hipEvent_t start, hipEvent_t stop)
Return the elapsed time between two events.
Definition: hip_hcc.cpp:1207
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:1679
hipError_t hipGetDeviceCount(int *count)
Return number of compute-capable devices.
Definition: hip_hcc.cpp:675
hipError_t hipMemset(void *dst, int value, size_t sizeBytes)
Copy data from src to dst asynchronously.
Definition: hip_hcc.cpp:1558
hipError_t hipStreamDestroy(hipStream_t stream)
Destroys the specified stream.
Definition: hip_hcc.cpp:1038
hipError_t hipStreamSynchronize(hipStream_t stream)
Wait for all commands in stream to complete.
Definition: hip_hcc.cpp:1015
Definition: hip_hcc.cpp:82
Shared mem is banked at 4-bytes intervals and performs best when adjacent threads access data 4 bytes...
Definition: hip_runtime_api.h:75
hipError_t
Definition: hip_runtime_api.h:114
hipMemcpyKind
Definition: hip_runtime_api.h:99
prefer larger L1 cache and smaller shared memory
Definition: hip_runtime_api.h:65
hipError_t hipDriverGetVersion(int *driverVersion)
Returns the approximate HIP driver version.
Definition: hip_hcc.cpp:1691
hipError_t hipDeviceSynchronize(void)
Blocks until the default device has completed all preceding requested tasks.
Definition: hip_hcc.cpp:781
Definition: hip_runtime_api.h:122
hipError_t hipDeviceSetCacheConfig(hipFuncCache cacheConfig)
Set L1/Shared cache partition.
Definition: hip_hcc.cpp:693
hipError_t hipMalloc(void **ptr, size_t size)
Allocate memory on the default accelerator.
Definition: hip_hcc.cpp:1351
const char * hipGetErrorName(hipError_t hip_error)
Return name of the specified error code in text form.
Definition: hip_hcc.cpp:931
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:912
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:998
hipError_t hipStreamGetFlags(hipStream_t stream, unsigned int *flags)
Return flags associated with this stream.
Definition: hip_hcc.cpp:1062
#define hipStreamDefault
Flags that can be used with hipStreamCreateWithFlags.
Definition: hip_runtime_api.h:48
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:1596
uint32_t z
z
Definition: hip_runtime_api.h:88
hipError_t hipDeviceReset(void)
Destroy all resources and reset all state on the default device in the current process.
Definition: hip_hcc.cpp:796
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:1471
The compiler selects a device-specific value for the banking.
Definition: hip_runtime_api.h:74
Device-to-Device Copy.
Definition: hip_runtime_api.h:103
Definition: hip_hcc.cpp:107
Runtime will automatically determine copy-kind based on virtual addresses.
Definition: hip_runtime_api.h:104
hipSharedMemConfig
Definition: hip_runtime_api.h:73
hipError_t hipMemcpy(void *dst, const void *src, size_t sizeBytes, hipMemcpyKind kind)
Copy data from src to dst.
Definition: hip_hcc.cpp:1429
hipError_t hipDeviceSetSharedMemConfig(hipSharedMemConfig config)
Set Shared memory bank configuration.
Definition: hip_hcc.cpp:736
prefer larger shared memory and smaller L1 cache
Definition: hip_runtime_api.h:64
Host-to-Host Copy.
Definition: hip_runtime_api.h:100
hipError_t hipHccGetAccelerator(int deviceId, hc::accelerator *acc)
Return hc::accelerator associated with the specified deviceId.
Definition: hip_hcc.cpp:1710
Shared mem is banked at 8-byte intervals and performs best when adjacent threads access data 4 bytes ...
Definition: hip_runtime_api.h:76
const char * hipGetErrorString(hipError_t hip_error)
Return handy text string message to explain the error which occurred.
Definition: hip_hcc.cpp:958