7 #include <boost/predef.h>
9 #ifdef ALPAKA_ACC_GPU_HIP_ENABLED
11 # include <hip/hip_runtime_api.h>
12 # include <hip/hip_version.h>
19 static constexpr
char name[] =
"Hip";
20 static constexpr
auto version = BOOST_VERSION_NUMBER(HIP_VERSION_MAJOR, HIP_VERSION_MINOR, 0);
23 using DeviceAttr_t = ::hipDeviceAttribute_t;
24 using DeviceProp_t = ::hipDeviceProp_t;
25 using Error_t = ::hipError_t;
26 using Event_t = ::hipEvent_t;
27 using Extent_t = ::hipExtent;
28 using Flag_t =
unsigned int;
29 using FuncAttributes_t = ::hipFuncAttributes;
30 using HostFn_t = void (*)(
void* data);
31 using Limit_t = ::hipLimit_t;
32 using Memcpy3DParms_t = ::hipMemcpy3DParms;
33 using MemcpyKind_t = ::hipMemcpyKind;
34 using PitchedPtr_t = ::hipPitchedPtr;
35 using Pos_t = ::hipPos;
36 using Stream_t = ::hipStream_t;
39 static constexpr Error_t success = ::hipSuccess;
40 static constexpr Error_t errorNotReady = ::hipErrorNotReady;
41 static constexpr Error_t errorHostMemoryAlreadyRegistered = ::hipErrorHostMemoryAlreadyRegistered;
42 static constexpr Error_t errorHostMemoryNotRegistered = ::hipErrorHostMemoryNotRegistered;
43 static constexpr Error_t errorUnsupportedLimit = ::hipErrorUnsupportedLimit;
44 static constexpr Error_t errorUnknown = ::hipErrorUnknown;
46 static constexpr Flag_t eventDefault = hipEventDefault;
47 static constexpr Flag_t eventBlockingSync = hipEventBlockingSync;
48 static constexpr Flag_t eventDisableTiming = hipEventDisableTiming;
49 static constexpr Flag_t eventInterprocess = hipEventInterprocess;
51 static constexpr Flag_t hostMallocDefault = hipHostMallocDefault;
52 static constexpr Flag_t hostMallocMapped = hipHostMallocMapped;
53 static constexpr Flag_t hostMallocPortable = hipHostMallocPortable;
54 static constexpr Flag_t hostMallocWriteCombined = hipHostMallocWriteCombined;
55 static constexpr Flag_t hostMallocCoherent = hipHostMallocCoherent;
56 static constexpr Flag_t hostMallocNonCoherent = hipHostMallocNonCoherent;
58 static constexpr Flag_t hostRegisterDefault = hipHostRegisterDefault;
59 static constexpr Flag_t hostRegisterPortable = hipHostRegisterPortable;
60 static constexpr Flag_t hostRegisterMapped = hipHostRegisterMapped;
61 static constexpr Flag_t hostRegisterIoMemory = hipHostRegisterIoMemory;
63 static constexpr MemcpyKind_t memcpyDefault = ::hipMemcpyDefault;
64 static constexpr MemcpyKind_t memcpyDeviceToDevice = ::hipMemcpyDeviceToDevice;
65 static constexpr MemcpyKind_t memcpyDeviceToHost = ::hipMemcpyDeviceToHost;
66 static constexpr MemcpyKind_t memcpyHostToDevice = ::hipMemcpyHostToDevice;
68 static constexpr Flag_t streamDefault = hipStreamDefault;
69 static constexpr Flag_t streamNonBlocking = hipStreamNonBlocking;
71 static constexpr DeviceAttr_t deviceAttributeMaxBlockDimX = ::hipDeviceAttributeMaxBlockDimX;
72 static constexpr DeviceAttr_t deviceAttributeMaxBlockDimY = ::hipDeviceAttributeMaxBlockDimY;
73 static constexpr DeviceAttr_t deviceAttributeMaxBlockDimZ = ::hipDeviceAttributeMaxBlockDimZ;
74 static constexpr DeviceAttr_t deviceAttributeMaxGridDimX = ::hipDeviceAttributeMaxGridDimX;
75 static constexpr DeviceAttr_t deviceAttributeMaxGridDimY = ::hipDeviceAttributeMaxGridDimY;
76 static constexpr DeviceAttr_t deviceAttributeMaxGridDimZ = ::hipDeviceAttributeMaxGridDimZ;
77 static constexpr DeviceAttr_t deviceAttributeMaxSharedMemoryPerBlock
78 = ::hipDeviceAttributeMaxSharedMemoryPerBlock;
79 static constexpr DeviceAttr_t deviceAttributeMaxThreadsPerBlock = ::hipDeviceAttributeMaxThreadsPerBlock;
80 static constexpr DeviceAttr_t deviceAttributeMultiprocessorCount = ::hipDeviceAttributeMultiprocessorCount;
81 static constexpr DeviceAttr_t deviceAttributeWarpSize = ::hipDeviceAttributeWarpSize;
83 # if HIP_VERSION >= 40'500'000
84 static constexpr Limit_t limitPrintfFifoSize = ::hipLimitPrintfFifoSize;
86 static constexpr Limit_t limitPrintfFifoSize
87 =
static_cast<Limit_t
>(0x01);
89 static constexpr Limit_t limitMallocHeapSize = ::hipLimitMallocHeapSize;
99 static void hostFunction(
void* data)
101 auto ptr =
reinterpret_cast<HostFnAdaptor*
>(data);
102 ptr->func_(ptr->data_);
106 static void streamCallback(Stream_t, Error_t,
void* data)
108 auto ptr =
reinterpret_cast<HostFnAdaptor*
>(data);
109 ptr->func_(ptr->data_);
115 static inline Error_t deviceGetAttribute(
int* value, DeviceAttr_t attr,
int device)
117 return ::hipDeviceGetAttribute(value, attr, device);
120 static inline Error_t deviceGetLimit(
size_t* pValue, Limit_t limit)
122 # if HIP_VERSION < 40'500'000
123 if(limit == limitPrintfFifoSize)
126 return errorUnsupportedLimit;
129 return ::hipDeviceGetLimit(pValue, limit);
132 static inline Error_t deviceReset()
134 return ::hipDeviceReset();
137 static inline Error_t deviceSetLimit(Limit_t ,
size_t )
140 return errorUnsupportedLimit;
143 static inline Error_t deviceSynchronize()
145 return ::hipDeviceSynchronize();
148 static inline Error_t eventCreate(Event_t* event)
150 return ::hipEventCreate(event);
153 static inline Error_t eventCreateWithFlags(Event_t* event, Flag_t flags)
155 return ::hipEventCreateWithFlags(event, flags);
158 static inline Error_t eventDestroy(Event_t event)
160 return ::hipEventDestroy(event);
163 static inline Error_t eventQuery(Event_t event)
165 return ::hipEventQuery(event);
168 static inline Error_t eventRecord(Event_t event, Stream_t stream)
170 return ::hipEventRecord(event, stream);
173 static inline Error_t eventSynchronize(Event_t event)
175 return ::hipEventSynchronize(event);
178 static inline Error_t
free(
void* devPtr)
180 return ::hipFree(devPtr);
183 static inline Error_t freeAsync([[maybe_unused]]
void* devPtr, [[maybe_unused]] Stream_t stream)
186 # if HIP_VERSION >= 50'300'000
190 return ::hipFreeAsync(devPtr, stream);
202 static inline Error_t funcGetAttributes(FuncAttributes_t* attr,
void const* func)
204 return ::hipFuncGetAttributes(attr, func);
208 static inline Error_t funcGetAttributes(FuncAttributes_t* attr, T* func)
211 # pragma GCC diagnostic push
212 # pragma GCC diagnostic ignored "-Wconditionally-supported"
214 return ::hipFuncGetAttributes(attr,
reinterpret_cast<void const*
>(func));
216 # pragma GCC diagnostic pop
220 static inline Error_t getDeviceCount(
int* count)
222 return ::hipGetDeviceCount(count);
225 static inline Error_t getDeviceProperties(DeviceProp_t* prop,
int device)
227 return ::hipGetDeviceProperties(prop, device);
230 static inline char const* getErrorName(Error_t error)
232 return ::hipGetErrorName(error);
235 static inline char const* getErrorString(Error_t error)
237 return ::hipGetErrorString(error);
240 static inline Error_t getLastError()
242 return ::hipGetLastError();
245 static inline Error_t getSymbolAddress(
void** devPtr,
void const* symbol)
247 return ::hipGetSymbolAddress(devPtr, symbol);
251 static inline Error_t getSymbolAddress(
void** devPtr, T
const& symbol)
253 return ::hipGetSymbolAddress(devPtr, symbol);
256 static inline Error_t hostGetDevicePointer(
void** pDevice,
void* pHost, Flag_t flags)
258 return ::hipHostGetDevicePointer(pDevice, pHost, flags);
261 static inline Error_t hostFree(
void* ptr)
263 return ::hipHostFree(ptr);
266 static inline Error_t hostMalloc(
void** ptr,
size_t size, Flag_t flags)
268 return ::hipHostMalloc(ptr, size, flags);
271 static inline Error_t hostRegister(
void* ptr,
size_t size, Flag_t flags)
273 return ::hipHostRegister(ptr, size, flags);
276 static inline Error_t hostUnregister(
void* ptr)
278 return ::hipHostUnregister(ptr);
281 static inline Error_t launchHostFunc(Stream_t stream, HostFn_t fn,
void* userData)
284 # if HIP_VERSION >= 50'400'000
286 return ::hipLaunchHostFunc(stream, HostFnAdaptor::hostFunction,
new HostFnAdaptor{fn, userData});
289 return ::hipStreamAddCallback(stream, HostFnAdaptor::streamCallback,
new HostFnAdaptor{fn, userData}, 0);
293 static inline Error_t
malloc(
void** devPtr,
size_t size)
295 return ::hipMalloc(devPtr, size);
298 static inline Error_t malloc3D(PitchedPtr_t* pitchedDevPtr, Extent_t extent)
300 return ::hipMalloc3D(pitchedDevPtr, extent);
303 static inline Error_t mallocAsync(
304 [[maybe_unused]]
void** devPtr,
305 [[maybe_unused]]
size_t size,
306 [[maybe_unused]] Stream_t stream)
309 # if HIP_VERSION >= 50'600'000
310 return ::hipMallocAsync(devPtr, size, stream);
311 # elif HIP_VERSION >= 50'300'000
315 return ::hipMallocAsync(devPtr, size, stream);
329 static inline Error_t mallocPitch(
void** devPtr,
size_t* pitch,
size_t width,
size_t height)
331 return ::hipMallocPitch(devPtr, pitch, width, height);
334 static inline Error_t memGetInfo(
size_t*
free,
size_t* total)
336 return ::hipMemGetInfo(
free, total);
339 static inline Error_t
memcpy(
void* dst,
void const* src,
size_t count, MemcpyKind_t kind)
341 return ::hipMemcpy(dst, src, count, kind);
344 static inline Error_t memcpy2DAsync(
354 return ::hipMemcpy2DAsync(dst, dpitch, src, spitch, width, height, kind, stream);
357 static inline Error_t memcpy3DAsync(Memcpy3DParms_t
const* p, Stream_t stream)
359 return ::hipMemcpy3DAsync(p, stream);
362 static inline Error_t memcpyAsync(
void* dst,
void const* src,
size_t count, MemcpyKind_t kind, Stream_t stream)
364 return ::hipMemcpyAsync(dst, src, count, kind, stream);
367 static inline Error_t memset2DAsync(
375 return ::hipMemset2DAsync(devPtr, pitch, value, width, height, stream);
378 static inline Error_t memset3DAsync(PitchedPtr_t pitchedDevPtr,
int value, Extent_t extent, Stream_t stream)
380 return ::hipMemset3DAsync(pitchedDevPtr, value, extent, stream);
383 static inline Error_t memsetAsync(
void* devPtr,
int value,
size_t count, Stream_t stream)
385 return ::hipMemsetAsync(devPtr, value, count, stream);
388 static inline Error_t setDevice(
int device)
390 return ::hipSetDevice(device);
393 static inline Error_t streamCreate(Stream_t* pStream)
395 return ::hipStreamCreate(pStream);
398 static inline Error_t streamCreateWithFlags(Stream_t* pStream, Flag_t flags)
400 return ::hipStreamCreateWithFlags(pStream, flags);
403 static inline Error_t streamDestroy(Stream_t stream)
405 return ::hipStreamDestroy(stream);
408 static inline Error_t streamQuery(Stream_t stream)
410 return ::hipStreamQuery(stream);
413 static inline Error_t streamSynchronize(Stream_t stream)
415 return ::hipStreamSynchronize(stream);
418 static inline Error_t streamWaitEvent(Stream_t stream, Event_t event, Flag_t flags)
420 return ::hipStreamWaitEvent(stream, event, flags);
423 static inline PitchedPtr_t makePitchedPtr(
void* d,
size_t p,
size_t xsz,
size_t ysz)
425 return ::make_hipPitchedPtr(d, p, xsz, ysz);
428 static inline Pos_t makePos(
size_t x,
size_t y,
size_t z)
430 return ::make_hipPos(x, y, z);
433 static inline Extent_t makeExtent(
size_t w,
size_t h,
size_t d)
435 return ::make_hipExtent(w, h, d);
The alpaka accelerator library.
ALPAKA_FN_HOST auto free(TAlloc const &alloc, T const *const ptr) -> void
Frees the memory identified by the given pointer.
ALPAKA_FN_HOST auto memcpy(TQueue &queue, alpaka::detail::DevGlobalImplGeneric< TTag, TTypeDst > &viewDst, TViewSrc const &viewSrc) -> void
ALPAKA_FN_HOST auto malloc(TAlloc const &alloc, std::size_t const &sizeElems) -> T *