10#ifdef ALPAKA_ACC_GPU_HIP_ENABLED
12# include <hip/hip_runtime_api.h>
13# include <hip/hip_version.h>
20 static constexpr char name[] =
"Hip";
24 using DeviceAttr_t = ::hipDeviceAttribute_t;
25 using DeviceProp_t = ::hipDeviceProp_t;
26 using Error_t = ::hipError_t;
27 using Event_t = ::hipEvent_t;
28 using Extent_t = ::hipExtent;
29 using Flag_t =
unsigned int;
30 using FuncAttributes_t = ::hipFuncAttributes;
31 using HostFn_t = void (*)(
void* data);
32 using Limit_t = ::hipLimit_t;
33 using Memcpy3DParms_t = ::hipMemcpy3DParms;
34 using MemcpyKind_t = ::hipMemcpyKind;
35 using PitchedPtr_t = ::hipPitchedPtr;
36 using Pos_t = ::hipPos;
37 using Stream_t = ::hipStream_t;
40 static constexpr Error_t success = ::hipSuccess;
41 static constexpr Error_t errorNotReady = ::hipErrorNotReady;
42 static constexpr Error_t errorHostMemoryAlreadyRegistered = ::hipErrorHostMemoryAlreadyRegistered;
43 static constexpr Error_t errorHostMemoryNotRegistered = ::hipErrorHostMemoryNotRegistered;
44 static constexpr Error_t errorUnsupportedLimit = ::hipErrorUnsupportedLimit;
45 static constexpr Error_t errorUnknown = ::hipErrorUnknown;
47 static constexpr Flag_t eventDefault = hipEventDefault;
48 static constexpr Flag_t eventBlockingSync = hipEventBlockingSync;
49 static constexpr Flag_t eventDisableTiming = hipEventDisableTiming;
50 static constexpr Flag_t eventInterprocess = hipEventInterprocess;
52 static constexpr Flag_t hostMallocDefault = hipHostMallocDefault;
53 static constexpr Flag_t hostMallocMapped = hipHostMallocMapped;
54 static constexpr Flag_t hostMallocPortable = hipHostMallocPortable;
55 static constexpr Flag_t hostMallocWriteCombined = hipHostMallocWriteCombined;
56 static constexpr Flag_t hostMallocCoherent = hipHostMallocCoherent;
57 static constexpr Flag_t hostMallocNonCoherent = hipHostMallocNonCoherent;
59 static constexpr Flag_t memAttachGlobal = hipMemAttachGlobal;
60 static constexpr Flag_t memAttachHost = hipMemAttachHost;
62 static constexpr Flag_t hostRegisterDefault = hipHostRegisterDefault;
63 static constexpr Flag_t hostRegisterPortable = hipHostRegisterPortable;
64 static constexpr Flag_t hostRegisterMapped = hipHostRegisterMapped;
65 static constexpr Flag_t hostRegisterIoMemory = hipHostRegisterIoMemory;
67 static constexpr MemcpyKind_t memcpyDefault = ::hipMemcpyDefault;
68 static constexpr MemcpyKind_t memcpyDeviceToDevice = ::hipMemcpyDeviceToDevice;
69 static constexpr MemcpyKind_t memcpyDeviceToHost = ::hipMemcpyDeviceToHost;
70 static constexpr MemcpyKind_t memcpyHostToDevice = ::hipMemcpyHostToDevice;
72 static constexpr Flag_t streamDefault = hipStreamDefault;
73 static constexpr Flag_t streamNonBlocking = hipStreamNonBlocking;
75 static constexpr DeviceAttr_t deviceAttributeMaxBlockDimX = ::hipDeviceAttributeMaxBlockDimX;
76 static constexpr DeviceAttr_t deviceAttributeMaxBlockDimY = ::hipDeviceAttributeMaxBlockDimY;
77 static constexpr DeviceAttr_t deviceAttributeMaxBlockDimZ = ::hipDeviceAttributeMaxBlockDimZ;
78 static constexpr DeviceAttr_t deviceAttributeMaxGridDimX = ::hipDeviceAttributeMaxGridDimX;
79 static constexpr DeviceAttr_t deviceAttributeMaxGridDimY = ::hipDeviceAttributeMaxGridDimY;
80 static constexpr DeviceAttr_t deviceAttributeMaxGridDimZ = ::hipDeviceAttributeMaxGridDimZ;
81 static constexpr DeviceAttr_t deviceAttributeMaxSharedMemoryPerBlock
82 = ::hipDeviceAttributeMaxSharedMemoryPerBlock;
83 static constexpr DeviceAttr_t deviceAttributeMaxThreadsPerBlock = ::hipDeviceAttributeMaxThreadsPerBlock;
84 static constexpr DeviceAttr_t deviceAttributeMultiprocessorCount = ::hipDeviceAttributeMultiprocessorCount;
85 static constexpr DeviceAttr_t deviceAttributeWarpSize = ::hipDeviceAttributeWarpSize;
86 static constexpr DeviceAttr_t deviceAttributeCooperativeLaunch = ::hipDeviceAttributeCooperativeLaunch;
88# if HIP_VERSION >= 40'500'000
89 static constexpr Limit_t limitPrintfFifoSize = ::hipLimitPrintfFifoSize;
91 static constexpr Limit_t limitPrintfFifoSize
92 =
static_cast<Limit_t
>(0x01);
94 static constexpr Limit_t limitMallocHeapSize = ::hipLimitMallocHeapSize;
104 static void hostFunction(
void* data)
106 auto ptr =
reinterpret_cast<HostFnAdaptor*
>(data);
107 ptr->func_(ptr->data_);
111 static void streamCallback(Stream_t, Error_t,
void* data)
113 auto ptr =
reinterpret_cast<HostFnAdaptor*
>(data);
114 ptr->func_(ptr->data_);
120 static inline Error_t deviceGetAttribute(
int* value, DeviceAttr_t attr,
int device)
122 return ::hipDeviceGetAttribute(value, attr, device);
125 static inline Error_t deviceGetLimit(
size_t* pValue, Limit_t limit)
127# if HIP_VERSION < 40'500'000
128 if(limit == limitPrintfFifoSize)
131 return errorUnsupportedLimit;
134 return ::hipDeviceGetLimit(pValue, limit);
137 static inline Error_t deviceReset()
139 return ::hipDeviceReset();
142 static inline Error_t deviceSetLimit(Limit_t ,
size_t )
145 return errorUnsupportedLimit;
148 static inline Error_t deviceSynchronize()
150 return ::hipDeviceSynchronize();
153 static inline Error_t eventCreate(Event_t* event)
155 return ::hipEventCreate(event);
158 static inline Error_t eventCreateWithFlags(Event_t* event, Flag_t flags)
160 return ::hipEventCreateWithFlags(event, flags);
163 static inline Error_t eventDestroy(Event_t event)
165 return ::hipEventDestroy(event);
168 static inline Error_t eventQuery(Event_t event)
170 return ::hipEventQuery(event);
173 static inline Error_t eventRecord(Event_t event, Stream_t stream)
175 return ::hipEventRecord(event, stream);
178 static inline Error_t eventSynchronize(Event_t event)
180 return ::hipEventSynchronize(event);
183 static inline Error_t
free(
void* devPtr)
185 return ::hipFree(devPtr);
188 static inline Error_t freeAsync([[maybe_unused]]
void* devPtr, [[maybe_unused]] Stream_t stream)
191# if HIP_VERSION >= 50'300'000
195 return ::hipFreeAsync(devPtr, stream);
207 static inline Error_t funcGetAttributes(FuncAttributes_t* attr,
void const* func)
209 return ::hipFuncGetAttributes(attr, func);
213 static inline Error_t funcGetAttributes(FuncAttributes_t* attr, T* func)
216# pragma GCC diagnostic push
217# pragma GCC diagnostic ignored "-Wconditionally-supported"
219 return ::hipFuncGetAttributes(attr,
reinterpret_cast<void const*
>(func));
221# pragma GCC diagnostic pop
225 static inline int getCurrentDevice()
228 using TApi = alpaka::ApiHipRt;
234 static inline Error_t getDeviceCount(
int* count)
236 return ::hipGetDeviceCount(count);
239 static inline Error_t getDeviceProperties(DeviceProp_t* prop,
int device)
241 return ::hipGetDeviceProperties(prop, device);
244 static inline char const* getErrorName(Error_t error)
246 return ::hipGetErrorName(error);
249 static inline char const* getErrorString(Error_t error)
251 return ::hipGetErrorString(error);
254 static inline Error_t getLastError()
256 return ::hipGetLastError();
259 static inline Error_t getSymbolAddress(
void** devPtr,
void const* symbol)
261 return ::hipGetSymbolAddress(devPtr, symbol);
265 static inline Error_t getSymbolAddress(
void** devPtr, T
const& symbol)
267 return ::hipGetSymbolAddress(devPtr, symbol);
270 static inline Error_t hostGetDevicePointer(
void** pDevice,
void* pHost, Flag_t flags)
272 return ::hipHostGetDevicePointer(pDevice, pHost, flags);
275 static inline Error_t hostFree(
void* ptr)
277 return ::hipHostFree(ptr);
280 static inline Error_t hostMalloc(
void** ptr,
size_t size, Flag_t flags)
282 return ::hipHostMalloc(ptr, size, flags);
285 static inline Error_t hostRegister(
void* ptr,
size_t size, Flag_t flags)
287 return ::hipHostRegister(ptr, size, flags);
290 static inline Error_t hostUnregister(
void* ptr)
292 return ::hipHostUnregister(ptr);
296 static inline Error_t launchCooperativeKernel(
304 return ::hipLaunchCooperativeKernel(func, gridDim, blockDim, args,
static_cast<uint
>(sharedMem), stream);
307 static inline Error_t launchHostFunc(Stream_t stream, HostFn_t fn,
void* userData)
310# if HIP_VERSION >= 50'400'000
312 return ::hipLaunchHostFunc(stream, HostFnAdaptor::hostFunction,
new HostFnAdaptor{fn, userData});
315 return ::hipStreamAddCallback(stream, HostFnAdaptor::streamCallback,
new HostFnAdaptor{fn, userData}, 0);
319 static inline Error_t
malloc(
void** devPtr,
size_t size)
321 return ::hipMalloc(devPtr, size);
324 static inline Error_t malloc3D(PitchedPtr_t* pitchedDevPtr, Extent_t extent)
326 return ::hipMalloc3D(pitchedDevPtr, extent);
329 static inline Error_t mallocAsync(
330 [[maybe_unused]]
void** devPtr,
331 [[maybe_unused]]
size_t size,
332 [[maybe_unused]] Stream_t stream)
335# if HIP_VERSION >= 50'600'000
336 return ::hipMallocAsync(devPtr, size, stream);
337# elif HIP_VERSION >= 50'300'000
341 return ::hipMallocAsync(devPtr, size, stream);
355 static inline Error_t mallocManaged(
void** ptr,
size_t size, Flag_t flags)
357 return ::hipMallocManaged(ptr, size, flags);
360 static inline Error_t mallocPitch(
void** devPtr,
size_t* pitch,
size_t width,
size_t height)
362 return ::hipMallocPitch(devPtr, pitch, width, height);
365 static inline Error_t memGetInfo(
size_t* free,
size_t* total)
367 return ::hipMemGetInfo(free, total);
370 static inline Error_t
memcpy(
void* dst,
void const* src,
size_t count, MemcpyKind_t kind)
372 return ::hipMemcpy(dst, src, count, kind);
375 static inline Error_t memcpy2DAsync(
385 return ::hipMemcpy2DAsync(dst, dpitch, src, spitch, width, height, kind, stream);
388 static inline Error_t memcpy3DAsync(Memcpy3DParms_t
const* p, Stream_t stream)
390 return ::hipMemcpy3DAsync(p, stream);
393 static inline Error_t memcpyAsync(
void* dst,
void const* src,
size_t count, MemcpyKind_t kind, Stream_t stream)
395 return ::hipMemcpyAsync(dst, src, count, kind, stream);
398 static inline Error_t memset2DAsync(
406 return ::hipMemset2DAsync(devPtr, pitch, value, width, height, stream);
409 static inline Error_t memset3DAsync(PitchedPtr_t pitchedDevPtr,
int value, Extent_t extent, Stream_t stream)
411 return ::hipMemset3DAsync(pitchedDevPtr, value, extent, stream);
414 static inline Error_t memsetAsync(
void* devPtr,
int value,
size_t count, Stream_t stream)
416 return ::hipMemsetAsync(devPtr, value, count, stream);
419 static inline Error_t setDevice(
int device)
421 return ::hipSetDevice(device);
424 static inline Error_t streamCreate(Stream_t* pStream)
426 return ::hipStreamCreate(pStream);
429 static inline Error_t streamCreateWithFlags(Stream_t* pStream, Flag_t flags)
431 return ::hipStreamCreateWithFlags(pStream, flags);
434 static inline Error_t streamDestroy(Stream_t stream)
436 return ::hipStreamDestroy(stream);
439 static inline Error_t streamQuery(Stream_t stream)
441 return ::hipStreamQuery(stream);
444 static inline Error_t streamSynchronize(Stream_t stream)
446 return ::hipStreamSynchronize(stream);
449 static inline Error_t streamWaitEvent(Stream_t stream, Event_t event, Flag_t flags)
451 return ::hipStreamWaitEvent(stream, event, flags);
454 static inline PitchedPtr_t makePitchedPtr(
void* d,
size_t p,
size_t xsz,
size_t ysz)
456 return ::make_hipPitchedPtr(d, p, xsz, ysz);
459 static inline Pos_t makePos(
size_t x,
size_t y,
size_t z)
461 return ::make_hipPos(x, y, z);
464 static inline Extent_t makeExtent(
size_t w,
size_t h,
size_t d)
466 return ::make_hipExtent(w, h, d);
470 static inline Error_t occupancyMaxActiveBlocksPerMultiprocessor(
474 size_t dynamicSMemSize)
476 return ::hipOccupancyMaxActiveBlocksPerMultiprocessor(numBlocks, func, blockSize, dynamicSMemSize);
#define ALPAKA_VERSION_NUMBER(major, minor, patch)
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 *