HIP: Heterogenous-computing Interface for Portability
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
hip_runtime_api.h
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 
24 
25 #include <stdint.h>
26 #include <stddef.h>
27 
28 #include <hcc_detail/host_defines.h>
29 
30 #if defined (__HCC__) && (__hcc_workweek__ < 1602)
31 #error("This version of HIP requires a newer version of HCC.");
32 #endif
33 
34 
35 // hip_api_hcc.h
36 // Contains C function APIs for HIP runtime.
37 // This file does not use any HCC builtins or special language extensions (-hc mode) ; those functions in hip_hcc.h.
38 
39 
40 // Structure definitions:
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
49 #define hipStreamDefault 0x00
51 #define hipStreamNonBlocking 0x01
52 
53 
55 #define hipEventDefault 0x0
56 #define hipEventBlockingSync 0x1
57 #define hipEventDisableTiming 0x2
58 #define hipEventInterprocess 0x4
59 
60 
64 typedef enum hipFuncCache {
69 } hipFuncCache;
70 
71 
75 typedef enum hipSharedMemConfig {
80 
81 
82 
87 typedef struct dim3 {
88  uint32_t x;
89  uint32_t y;
90  uint32_t z;
91 
92  dim3(uint32_t _x=1, uint32_t _y=1, uint32_t _z=1) : x(_x), y(_y), z(_z) {};
93 } dim3;
94 
95 
96 
107 } ;
108 
109 
110 // Doxygen end group GlobalDefs
114 //-------------------------------------------------------------------------------------------------
115 
116 
117 // The handle allows the async commands to use the stream even if the parent hipStream_t goes out-of-scope.
118 typedef struct ihipStream_t * hipStream_t;
119 
120 
121 /*
122  * Opaque structure allows the true event (pointed at by the handle) to remain "live" even if the surrounding hipEvent_t goes out-of-scope.
123  * 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 */
124 typedef struct hipEvent_t {
125  struct ihipEvent_t *_handle;
126 } hipEvent_t;
127 
128 
129 
130 
131 
132 
133 #ifdef __cplusplus
134 } /* extern "C" */
135 #endif
136 
137 
138 
139 
140 //==================================================================================================
141 #ifdef __cplusplus
142 extern "C" {
143 #endif
144 
169 
170 
171 
183 
184 
209 hipError_t hipSetDevice(int device);
210 
211 
223 hipError_t hipGetDevice(int *device);
224 
225 
233 hipError_t hipGetDeviceCount(int *count);
234 
235 
245 
246 
247 
248 //Cache partitioning functions:
249 
257 
258 
266 
267 
275 
276 //---
277 //Shared bank config functions:
278 
286 
287 
295 
296 
297 // end doxygen Device
318 
319 
332 
333 
334 
343 const char *hipGetErrorName(hipError_t hip_error);
344 
345 
356 const char *hipGetErrorString(hipError_t hip_error);
357 
358 // end doxygen Error
388 hipError_t hipStreamCreateWithFlags(hipStream_t *stream, unsigned int flags);
389 
390 
391 
401 static inline hipError_t hipStreamCreate(hipStream_t *stream)
402 {
404 }
405 
406 
422 hipError_t hipStreamWaitEvent(hipStream_t stream, hipEvent_t event, unsigned int flags);
423 
424 
437 
438 
453 
454 
468 hipError_t hipStreamGetFlags(hipStream_t stream, unsigned int *flags);
469 
470 
471 // end doxygen Stream
496 hipError_t hipEventCreateWithFlags(hipEvent_t* event, unsigned flags);
497 
498 
505 static inline hipError_t hipEventCreate(hipEvent_t* event)
506 {
507  return hipEventCreateWithFlags(event, 0);
508 }
509 
510 
536 hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream = NULL);
537 
538 
550 
551 
566 
567 
592 hipError_t hipEventElapsedTime(float *ms, hipEvent_t start, hipEvent_t stop);
593 
594 
608 
609 
610 // end doxygen Events
640 hipError_t hipMalloc(void** ptr, size_t size) ;
641 
642 
650 hipError_t hipMallocHost(void** ptr, size_t size) ;
651 
652 
653 
654 // TODO-doc (error codes)
662 hipError_t hipFree(void* ptr);
663 
664 
665 
666 // TODO-doc (error codes)
673 hipError_t hipFreeHost(void* ptr);
674 
675 
676 
677 
678 // TODO-doc (error codes)
694 hipError_t hipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind);
695 
696 
697 hipError_t hipMemcpyToSymbol(const char* symbolName, const void *src, size_t sizeBytes, size_t offset, hipMemcpyKind kind);
698 
699 
700 
701 // TODO-doc (error codes)
712 hipError_t hipMemcpyAsync(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind, hipStream_t stream=0);
713 
714 
715 // TODO-doc
716 /*
717  * This function is host-asynchronous and may return before the memset operation completes.
718  * Same as hipMemsetAsync with null stream.
719  *
720  * */
721 hipError_t hipMemset(void* dst, int value, size_t sizeBytes );
722 hipError_t hipMemsetAsync(void* dst, int value, size_t sizeBytes, hipStream_t = 0 );
723 
724 
725 /*
726  * @brief Query memory info. Return snapshot of free memory, and total allocatable memory on the device.
727  *
728  * Returns in *free a snapshot of the current free memory o
729  **/
730 hipError_t hipMemGetInfo (size_t * free, size_t * total) ;
731 
732 // doxygen end Memory
757 hipError_t hipDeviceCanAccessPeer ( int* canAccessPeer, int device, int peerDevice );
758 
759 // TODO-DOC
760 hipError_t hipDeviceDisablePeerAccess ( int peerDevice );
761 
762 // TODO-DOC
763 hipError_t hipDeviceEnablePeerAccess ( int peerDevice, unsigned int flags );
764 
765 // TODO-DOC
766 hipError_t hipMemcpyPeer ( void* dst, int dstDevice, const void* src, int srcDevice, size_t sizeBytes );
767 
768 // TODO-DOC
769 hipError_t hipMemcpyPeerAsync ( void* dst, int dstDevice, const void* src, int srcDevice, size_t sizeBytes, hipStream_t stream=0 );
770 // doxygen end PeerToPeer
794 hipError_t hipDriverGetVersion(int *driverVersion) ;
795 
796 
797 
798 // doxygen end Version Management
825 #ifdef __cplusplus
826 } /* extern "c" */
827 #endif
828 
829 
847 #ifdef __HCC__
848 #include <hc.hpp>
852 hipError_t hipHccGetAccelerator(int deviceId, hc::accelerator *acc);
853 
857 hipError_t hipHccGetAcceleratorView(hipStream_t stream, hc::accelerator_view **av);
858 #endif
859 
860 
861 // end-group HCC_Specific
868 // doxygen end HIP API
hipError_t hipDeviceEnablePeerAccess(int peerDevice, unsigned int flags)
Definition: hip_hcc.cpp:1575
hipError_t hipDeviceCanAccessPeer(int *canAccessPeer, int device, int peerDevice)
Determine if a device can access a peer's memory.
Definition: hip_hcc.cpp:1551
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::acclerator_view associated with the specified stream.
Definition: hip_hcc.cpp:1647
struct dim3 dim3
hipError_t hipFreeHost(void *ptr)
Definition: hip_hcc.cpp:1529
hipError_t hipFuncSetCacheConfig(hipFuncCache config)
Set Cache configuration for a specific function.
Definition: hip_hcc.cpp:704
no preference for shared memory or L1 (default)
Definition: hip_runtime_api.h:65
uint32_t x
x
Definition: hip_runtime_api.h:88
Host-to-Device Copy.
Definition: hip_runtime_api.h:103
hipError_t hipDeviceGetSharedMemConfig(hipSharedMemConfig *pConfig)
Get Shared memory bank configuration.
Definition: hip_hcc.cpp:734
hipError_t hipSetDevice(int device)
Set default device to be used for subsequent hip API calls from this thread.
Definition: hip_hcc.cpp:747
Device-to-Host Copy.
Definition: hip_runtime_api.h:104
hipError_t hipEventSynchronize(hipEvent_t event)
: Wait for an event to complete.
Definition: hip_hcc.cpp:1074
hipError_t hipDeviceGetProperties(hipDeviceProp_t *prop, int device)
Returns device properties.
Definition: hip_hcc.cpp:801
hipFuncCache
Definition: hip_runtime_api.h:64
hipError_t hipEventQuery(hipEvent_t event)
Query event status.
Definition: hip_hcc.cpp:1169
hipError_t hipDeviceGetCacheConfig(hipFuncCache *cacheConfig)
Set Cache configuration for a specific function.
Definition: hip_hcc.cpp:690
hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream=NULL)
Record an event in the specified stream.
Definition: hip_hcc.cpp:1025
hipError_t hipGetDevice(int *device)
Return the default device id for the calling host thread.
Definition: hip_hcc.cpp:645
hipError_t hipEventDestroy(hipEvent_t event)
Destroy the specified event.
Definition: hip_hcc.cpp:1059
hipError_t hipStreamCreateWithFlags(hipStream_t *stream, unsigned int flags)
Create an asynchronous stream.
Definition: hip_hcc.cpp:891
hipError_t hipDeviceDisablePeerAccess(int peerDevice)
Definition: hip_hcc.cpp:1563
Definition: hip_runtime_api.h:87
uint32_t y
y
Definition: hip_runtime_api.h:89
prefer equal size L1 cache and shared memory
Definition: hip_runtime_api.h:68
hipError_t hipEventCreateWithFlags(hipEvent_t *event, unsigned flags)
Create an event with the specified flags.
Definition: hip_hcc.cpp:1002
hipError_t hipMallocHost(void **ptr, size_t size)
Definition: hip_hcc.cpp:1289
hipError_t hipEventElapsedTime(float *ms, hipEvent_t start, hipEvent_t stop)
Return the elapsed time between two events.
Definition: hip_hcc.cpp:1124
hipError_t hipMemcpyPeerAsync(void *dst, int dstDevice, const void *src, int srcDevice, size_t sizeBytes, hipStream_t stream=0)
Definition: hip_hcc.cpp:1596
hipError_t hipGetDeviceCount(int *count)
Return number of compute-capable devices.
Definition: hip_hcc.cpp:658
hipError_t hipStreamDestroy(hipStream_t stream)
Destroys the specified stream.
Definition: hip_hcc.cpp:955
hipError_t hipStreamSynchronize(hipStream_t stream)
Wait for all commands in stream to complete.
Definition: hip_hcc.cpp:932
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:77
hipError_t
Definition: hip_runtime_api.h:112
hipMemcpyKind
Definition: hip_runtime_api.h:101
prefer larger L1 cache and smaller shared memory
Definition: hip_runtime_api.h:67
hipError_t hipDriverGetVersion(int *driverVersion)
Returns the approximate HIP driver versin.
Definition: hip_hcc.cpp:1608
hipError_t hipDeviceSynchronize(void)
Blocks until the default device has completed all preceding requested tasks.
Definition: hip_hcc.cpp:764
Definition: hip_runtime_api.h:124
hipError_t hipDeviceSetCacheConfig(hipFuncCache cacheConfig)
Set L1/Shared cache partition.
Definition: hip_hcc.cpp:676
hipError_t hipMalloc(void **ptr, size_t size)
Definition: hip_hcc.cpp:1268
const char * hipGetErrorName(hipError_t hip_error)
Return name of the specified error code in text form.
Definition: hip_hcc.cpp:848
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:829
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:915
hipError_t hipStreamGetFlags(hipStream_t stream, unsigned int *flags)
Return flags associated with this stream.
Definition: hip_hcc.cpp:979
#define hipStreamDefault
Flags that can be used with hipStreamCreateWithFlags.
Definition: hip_runtime_api.h:50
hipError_t hipFree(void *ptr)
Definition: hip_hcc.cpp:1513
uint32_t z
z
Definition: hip_runtime_api.h:90
hipError_t hipDeviceReset(void)
Destroy all resources and reset all state on the default device in the current process.
Definition: hip_hcc.cpp:779
Definition: hip_runtime_api.h:74
hipError_t hipMemcpyAsync(void *dst, const void *src, size_t sizeBytes, hipMemcpyKind kind, hipStream_t stream=0)
Definition: hip_hcc.cpp:1388
The compiler selects a device-specific value for the banking.
Definition: hip_runtime_api.h:76
Device-to-Device Copy.
Definition: hip_runtime_api.h:105
Definition: hip_hcc.cpp:107
Runtime will automatically determine copy-kind based on virtual addresses.
Definition: hip_runtime_api.h:106
hipSharedMemConfig
Definition: hip_runtime_api.h:75
hipError_t hipMemcpy(void *dst, const void *src, size_t sizeBytes, hipMemcpyKind kind)
Definition: hip_hcc.cpp:1346
hipError_t hipDeviceSetSharedMemConfig(hipSharedMemConfig config)
Set Shared memory bank configuration.
Definition: hip_hcc.cpp:719
prefer larger shared memory and smaller L1 cache
Definition: hip_runtime_api.h:66
Host-to-Host Copy.
Definition: hip_runtime_api.h:102
hipError_t hipHccGetAccelerator(int deviceId, hc::accelerator *acc)
Return hc::acclerator associated with the specified deviceId.
Definition: hip_hcc.cpp:1627
Shared mem is banked at 8-byte intervals and performs best when adjacent threads access data 4 bytes ...
Definition: hip_runtime_api.h:78
const char * hipGetErrorString(hipError_t hip_error)
Return handy text string message to explain the error which occurred.
Definition: hip_hcc.cpp:875