HIP: Heterogenous-computing Interface for Portability
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Classes | Macros | Typedefs | Enumerations | Functions | Variables
hip_hcc.cpp File Reference
#include <assert.h>
#include <stdint.h>
#include <iostream>
#include <sstream>
#include <list>
#include <sys/types.h>
#include <unistd.h>
#include <deque>
#include <vector>
#include <algorithm>
#include <hc.hpp>
#include <hc_am.hpp>
#include "hip_runtime.h"
#include "hsa_ext_amd.h"
#include "hcc_detail/staging_buffer.h"
#include "hcc_detail/trace_helper.h"
#include "staging_buffer.cpp"

Classes

class  ihipException
 
struct  ihipSignal_t
 
class  FakeMutex
 
class  ihipStream_t
 
struct  ihipEvent_t
 
struct  ihipDevice_t
 

Macros

#define HIP_HCC
 
#define USE_AV_COPY   0
 
#define INLINE   static inline
 
#define KNRM   "\x1B[0m"
 
#define KRED   "\x1B[31m"
 
#define KGRN   "\x1B[32m"
 
#define KYEL   "\x1B[33m"
 
#define KBLU   "\x1B[34m"
 
#define KMAG   "\x1B[35m"
 
#define KCYN   "\x1B[36m"
 
#define KWHT   "\x1B[37m"
 
#define API_COLOR   KGRN
 
#define HIP_HCC
 
#define STREAM_THREAD_SAFE   1
 
#define FORCE_SAMEDIR_COPY_DEP   1
 
#define COMPILE_HIP_DB   1
 
#define COMPILE_HIP_TRACE_API   0x3
 
#define COMPILE_TRACE_MARKER   0
 
#define ONE_OBJECT_FILE   1
 
#define SCOPED_MARKER(markerName, group, userString)
 
#define API_TRACE(...)
 
#define HIP_INIT_API(...)
 
#define DB_API   0 /* 0x01 - shortcut to enable HIP_TRACE_API on single switch */
 
#define DB_SYNC   1 /* 0x02 - trace synchronization pieces */
 
#define DB_MEM   2 /* 0x04 - trace memory allocation / deallocation */
 
#define DB_COPY1   3 /* 0x08 - trace memory copy commands. . */
 
#define DB_SIGNAL   4 /* 0x10 - trace signal pool commands */
 
#define DB_COPY2   5 /* 0x20 - trace memory copy commands. Detailed. */
 
#define tprintf(trace_level,...)
 
#define DeviceErrorCheck(x)   if (x != HSA_STATUS_SUCCESS) { return hipErrorInvalidDevice; }
 
#define ErrorCheck(x)   error_check(x, __LINE__, __FILE__)
 
#define ihipLogStatus(_hip_status)
 
#define READ_ENV_I(_build, _ENV_VAR, _ENV_VAR2, _description)
 

Typedefs

typedef uint64_t SIGSEQNUM
 
typedef std::mutex StreamMutex
 

Enumerations

enum  ihipCommand_t {
  ihipCommandCopyH2H, ihipCommandCopyH2D, ihipCommandCopyD2H, ihipCommandCopyD2D,
  ihipCommandKernel, ihipCommandCopyH2H, ihipCommandCopyH2D, ihipCommandCopyD2H,
  ihipCommandCopyD2D, ihipCommandKernel
}
 
enum  hipEventStatus_t {
  hipEventStatusUnitialized = 0, hipEventStatusCreated = 1, hipEventStatusRecording = 2, hipEventStatusRecorded = 3,
  hipEventStatusUnitialized = 0, hipEventStatusCreated = 1, hipEventStatusRecording = 2, hipEventStatusRecorded = 3
}
 

Functions

const char * ihipErrorString (hipError_t hip_error)
 
INLINE bool ihipIsValidDevice (unsigned deviceIndex)
 
void error_check (hsa_status_t hsa_error_code, int line_num, std::string str)
 
hsa_status_t get_region_info (hsa_region_t region, void *data)
 
void ihipReadEnv_I (int *var_ptr, const char *var_name1, const char *var_name2, const char *description)
 
void ihipInit ()
 
INLINE ihipDevice_tihipGetTlsDefaultDevice ()
 
INLINE ihipDevice_tihipGetDevice (int deviceId)
 
hipStream_t ihipSyncAndResolveStream (hipStream_t stream)
 
hipStream_t ihipPreLaunchKernel (hipStream_t stream, hc::accelerator_view **av)
 
void ihipPostLaunchKernel (hipStream_t stream, hc::completion_future &kernelFuture)
 
hipError_t hipGetDevice (int *device)
 Return the default device id for the calling host thread. More...
 
hipError_t hipGetDeviceCount (int *count)
 Return number of compute-capable devices. More...
 
hipError_t hipDeviceSetCacheConfig (hipFuncCache cacheConfig)
 Set L1/Shared cache partition. More...
 
hipError_t hipDeviceGetCacheConfig (hipFuncCache *cacheConfig)
 Set Cache configuration for a specific function. More...
 
hipError_t hipFuncSetCacheConfig (hipFuncCache cacheConfig)
 Set Cache configuration for a specific function. More...
 
hipError_t hipDeviceSetSharedMemConfig (hipSharedMemConfig config)
 Set Shared memory bank configuration. More...
 
hipError_t hipDeviceGetSharedMemConfig (hipSharedMemConfig *pConfig)
 Get Shared memory bank configuration. More...
 
hipError_t hipSetDevice (int device)
 Set default device to be used for subsequent hip API calls from this thread. More...
 
hipError_t hipDeviceSynchronize (void)
 Blocks until the default device has completed all preceding requested tasks. More...
 
hipError_t hipDeviceReset (void)
 Destroy all resources and reset all state on the default device in the current process. More...
 
hipError_t hipDeviceGetAttribute (int *pi, hipDeviceAttribute_t attr, int device)
 Query device attribute. More...
 
hipError_t hipGetDeviceProperties (hipDeviceProp_t *props, int device)
 Returns device properties. More...
 
hipError_t hipGetLastError ()
 Return last error returned by any HIP runtime API call and resets the stored error code to hipSuccess. More...
 
hipError_t hipPeakAtLastError ()
 
const char * hipGetErrorName (hipError_t hip_error)
 Return name of the specified error code in text form. More...
 
const char * hipGetErrorString (hipError_t hip_error)
 Return handy text string message to explain the error which occurred. More...
 
hipError_t hipStreamCreateWithFlags (hipStream_t *stream, unsigned int flags)
 Create an asynchronous stream. More...
 
hipError_t hipStreamWaitEvent (hipStream_t stream, hipEvent_t event, unsigned int flags)
 Make the specified compute stream wait for an event. More...
 
hipError_t hipStreamSynchronize (hipStream_t stream)
 Wait for all commands in stream to complete. More...
 
hipError_t hipStreamDestroy (hipStream_t stream)
 Destroys the specified stream. More...
 
hipError_t hipStreamGetFlags (hipStream_t stream, unsigned int *flags)
 Return flags associated with this stream. More...
 
hipError_t hipEventCreateWithFlags (hipEvent_t *event, unsigned flags)
 Create an event with the specified flags. More...
 
hipError_t hipEventRecord (hipEvent_t event, hipStream_t stream)
 Record an event in the specified stream. More...
 
hipError_t hipEventDestroy (hipEvent_t event)
 Destroy the specified event. More...
 
hipError_t hipEventSynchronize (hipEvent_t event)
 : Wait for an event to complete. More...
 
void ihipSetTs (hipEvent_t e)
 
hipError_t hipEventElapsedTime (float *ms, hipEvent_t start, hipEvent_t stop)
 Return the elapsed time between two events. More...
 
hipError_t hipEventQuery (hipEvent_t event)
 Query event status. More...
 
hipError_t hipPointerGetAttributes (hipPointerAttribute_t *attributes, void *ptr)
 Return attributes for the specified pointer. More...
 
hipError_t hipHostGetDevicePointer (void **devicePointer, void *hostPointer, unsigned flags)
 
template<typename T >
hc::completion_future ihipMemcpyKernel (hipStream_t stream, T *c, const T *a, size_t sizeBytes)
 
template<typename T >
hc::completion_future ihipMemsetKernel (hipStream_t stream, T *ptr, T val, size_t sizeBytes)
 
hipError_t hipMalloc (void **ptr, size_t sizeBytes)
 Allocate memory on the default accelerator. More...
 
hipError_t hipMallocHost (void **ptr, size_t sizeBytes)
 Allocate pinned host memory. More...
 
hipError_t hipHostMalloc (void **ptr, size_t sizeBytes, unsigned int flags)
 Allocate device accessible page locked host memory. More...
 
hipError_t hipHostAlloc (void **ptr, size_t sizeBytes, unsigned int flags)
 
hipError_t hipHostGetFlags (unsigned int *flagsPtr, void *hostPtr)
 Get flags associated with host pointer. More...
 
hipError_t hipHostRegister (void *hostPtr, size_t sizeBytes, unsigned int flags)
 Register host memory so it can be accessed from the current device. More...
 
hipError_t hipHostUnregister (void *hostPtr)
 Un-register host pointer. More...
 
hipError_t hipMemcpyToSymbol (const char *symbolName, const void *src, size_t count, size_t offset, hipMemcpyKind kind)
 Copies sizeBytes bytes from the memory area pointed to by src to the memory area pointed to by offset bytes from the start of symbol symbol. More...
 
hipError_t hipMemcpy (void *dst, const void *src, size_t sizeBytes, hipMemcpyKind kind)
 Copy data from src to dst. More...
 
hipError_t hipMemcpyAsync (void *dst, const void *src, size_t sizeBytes, hipMemcpyKind kind, hipStream_t stream)
 Copy data from src to dst asynchronously. More...
 
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 value. More...
 
hipError_t hipMemset (void *dst, int value, size_t sizeBytes)
 Copy data from src to dst asynchronously. More...
 
hipError_t hipMemGetInfo (size_t *free, size_t *total)
 Query memory info. Return snapshot of free memory, and total allocatable memory on the device. More...
 
hipError_t hipFree (void *ptr)
 Free memory allocated by the hcc hip memory allocation API. This API performs an implicit hipDeviceSynchronize() call. More...
 
hipError_t hipHostFree (void *ptr)
 Free memory allocated by the hcc hip host memory allocation API. More...
 
hipError_t hipFreeHost (void *ptr)
 Free memory allocated by the hcc hip host memory allocation API. More...
 
hipError_t hipDeviceCanAccessPeer (int *canAccessPeer, int device, int peerDevice)
 Determine if a device can access a peer's memory. More...
 
hipError_t hipDeviceDisablePeerAccess (int peerDevice)
 Disables registering memory on peerDevice for direct access from the current device. More...
 
hipError_t hipDeviceEnablePeerAccess (int peerDevice, unsigned int flags)
 Enables registering memory on peerDevice for direct access from the current device. More...
 
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. More...
 
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. More...
 
hipError_t hipDriverGetVersion (int *driverVersion)
 Returns the approximate HIP driver version. More...
 
hipError_t hipHccGetAccelerator (int deviceId, hc::accelerator *acc)
 Return hc::accelerator associated with the specified deviceId. More...
 
hipError_t hipHccGetAcceleratorView (hipStream_t stream, hc::accelerator_view **av)
 Return hc::accelerator_view associated with the specified stream. More...
 

Variables

int HIP_LAUNCH_BLOCKING = 0
 Make all HIP APIs host-synchronous.
 
int HIP_PRINT_ENV = 0
 Print all HIP-related environment variables.
 
int HIP_TRACE_API = 0
 Trace HIP APIs.
 
int HIP_DB = 0
 
int HIP_STAGING_SIZE = 64
 
int HIP_STAGING_BUFFERS = 2
 
int HIP_PININPLACE = 0
 
int HIP_STREAM_SIGNALS = 2
 
int HIP_VISIBLE_DEVICES = 0
 
int HIP_DISABLE_HW_KERNEL_DEP = 1
 
int HIP_DISABLE_HW_COPY_DEP = 1
 
const char * dbName []
 
const hipStream_t hipStreamNull = 0x0
 
const char * ihipCommandName []
 
thread_local hipError_t tls_lastHipError = hipSuccess
 
thread_local int tls_defaultDevice = 0
 
std::once_flag hip_initialized
 
ihipDevice_tg_devices
 
bool g_visible_device = false
 
unsigned g_deviceCnt
 
std::vector< int > g_hip_visible_devices
 
hsa_agent_t g_cpu_agent
 

Detailed Description

Contains definitions for functions that are large enough that we don't want to inline them everywhere. This file is compiled and linked into apps running HIP / HCC path.

Macro Definition Documentation

#define API_TRACE (   ...)
Value:
{\
std::string s = std::string(__func__) + " (" + ToString(__VA_ARGS__) + ')';\
if (COMPILE_HIP_DB && HIP_TRACE_API) {\
fprintf (stderr, API_COLOR "<<hip-api: %s\n" KNRM, s.c_str());\
}\
SCOPED_MARKER(s.c_str(), "HIP", NULL);\
}
int HIP_TRACE_API
Trace HIP APIs.
Definition: hip_hcc.cpp:73
#define HIP_INIT_API (   ...)
Value:
std::call_once(hip_initialized, ihipInit);\
API_TRACE(__VA_ARGS__);
#define ihipLogStatus (   _hip_status)
Value:
({\
tls_lastHipError = _hip_status;\
\
if ((COMPILE_HIP_TRACE_API & 0x2) && HIP_TRACE_API) {\
fprintf(stderr, " %ship-api: %-30s ret=%2d (%s)>>\n" KNRM, (_hip_status == 0) ? API_COLOR:KRED, __func__, _hip_status, ihipErrorString(_hip_status));\
}\
_hip_status;\
})
int HIP_TRACE_API
Trace HIP APIs.
Definition: hip_hcc.cpp:73
#define READ_ENV_I (   _build,
  _ENV_VAR,
  _ENV_VAR2,
  _description 
)
Value:
if (_build == release) {\
ihipReadEnv_I(&_ENV_VAR, #_ENV_VAR, #_ENV_VAR2, _description);\
};
#define tprintf (   trace_level,
  ... 
)
Value:
{\
if (HIP_DB & (1<<(trace_level))) {\
fprintf (stderr, " %s:", dbName[trace_level]); \
fprintf (stderr, __VA_ARGS__);\
fprintf (stderr, "%s", KNRM); \
}\
}

Function Documentation

hipError_t hipHostGetDevicePointer ( void **  devicePointer,
void *  hostPointer,
unsigned  flags 
)
Returns
hipSuccess,
hipErrorInvalidValue if flags are not 0
hipErrorMemoryAllocation if hostPointer is not a tracked allocation.

Variable Documentation

const char* dbName[]
Initial value:
=
{
KNRM "hip-api",
KYEL "hip-sync",
KCYN "hip-mem",
KMAG "hip-copy1",
KRED "hip-signal",
KNRM "hip-copy2",
}
const char* ihipCommandName[]
Initial value:
= {
"CopyH2H", "CopyH2D", "CopyD2H", "CopyD2D", "Kernel"
}