11# include <hip/hip_runtime_api.h>
12# include <hip/hip_version.h>
19 static constexpr char name[] =
"Hip";
23 using DeviceAttr_t = ::hipDeviceAttribute_t;
24 using PointerAttr_t = ::hipPointerAttribute_t;
25 using Memory_t = ::hipMemoryType;
26 using DeviceProp_t = ::hipDeviceProp_t;
27 using Error_t = ::hipError_t;
28 using Event_t = ::hipEvent_t;
29 using Extent_t = ::hipExtent;
30 using Flag_t =
unsigned int;
31 using FuncAttributes_t = ::hipFuncAttributes;
32 using HostFn_t = void (*)(
void*
data);
33 using Limit_t = ::hipLimit_t;
34 using Memcpy3DParms_t = ::hipMemcpy3DParms;
35 using MemcpyKind_t = ::hipMemcpyKind;
36 using PitchedPtr_t = ::hipPitchedPtr;
37 using Pos_t = ::hipPos;
38 using Stream_t = ::hipStream_t;
41 static constexpr Error_t success = ::hipSuccess;
42 static constexpr Error_t errorNotReady = ::hipErrorNotReady;
43 static constexpr Error_t errorHostMemoryAlreadyRegistered = ::hipErrorHostMemoryAlreadyRegistered;
44 static constexpr Error_t errorHostMemoryNotRegistered = ::hipErrorHostMemoryNotRegistered;
45 static constexpr Error_t errorUnsupportedLimit = ::hipErrorUnsupportedLimit;
46 static constexpr Error_t errorUnknown = ::hipErrorUnknown;
48 static constexpr Flag_t eventDefault = hipEventDefault;
49 static constexpr Flag_t eventBlockingSync = hipEventBlockingSync;
50 static constexpr Flag_t eventDisableTiming = hipEventDisableTiming;
51 static constexpr Flag_t eventInterprocess = hipEventInterprocess;
53 static constexpr Flag_t hostMallocDefault = hipHostMallocDefault;
54 static constexpr Flag_t hostMallocMapped = hipHostMallocMapped;
55 static constexpr Flag_t hostMallocPortable = hipHostMallocPortable;
56 static constexpr Flag_t hostMallocWriteCombined = hipHostMallocWriteCombined;
57 static constexpr Flag_t hostMallocCoherent = hipHostMallocCoherent;
58 static constexpr Flag_t hostMallocNonCoherent = hipHostMallocNonCoherent;
60 static constexpr Flag_t hostRegisterDefault = hipHostRegisterDefault;
61 static constexpr Flag_t hostRegisterPortable = hipHostRegisterPortable;
62 static constexpr Flag_t hostRegisterMapped = hipHostRegisterMapped;
63 static constexpr Flag_t hostRegisterIoMemory = hipHostRegisterIoMemory;
65 static constexpr MemcpyKind_t memcpyDefault = ::hipMemcpyDefault;
66 static constexpr MemcpyKind_t memcpyDeviceToDevice = ::hipMemcpyDeviceToDevice;
67 static constexpr MemcpyKind_t memcpyDeviceToHost = ::hipMemcpyDeviceToHost;
68 static constexpr MemcpyKind_t memcpyHostToDevice = ::hipMemcpyHostToDevice;
69 static constexpr MemcpyKind_t memcpyHostToHost = ::hipMemcpyHostToHost;
71 static constexpr Flag_t streamDefault = hipStreamDefault;
72 static constexpr Flag_t streamNonBlocking = hipStreamNonBlocking;
74 static constexpr DeviceAttr_t deviceAttributeMaxBlockDimX = ::hipDeviceAttributeMaxBlockDimX;
75 static constexpr DeviceAttr_t deviceAttributeMaxBlockDimY = ::hipDeviceAttributeMaxBlockDimY;
76 static constexpr DeviceAttr_t deviceAttributeMaxBlockDimZ = ::hipDeviceAttributeMaxBlockDimZ;
77 static constexpr DeviceAttr_t deviceAttributeMaxGridDimX = ::hipDeviceAttributeMaxGridDimX;
78 static constexpr DeviceAttr_t deviceAttributeMaxGridDimY = ::hipDeviceAttributeMaxGridDimY;
79 static constexpr DeviceAttr_t deviceAttributeMaxGridDimZ = ::hipDeviceAttributeMaxGridDimZ;
80 static constexpr DeviceAttr_t deviceAttributeMaxSharedMemoryPerBlock
81 = ::hipDeviceAttributeMaxSharedMemoryPerBlock;
82 static constexpr DeviceAttr_t deviceAttributeMaxThreadsPerBlock = ::hipDeviceAttributeMaxThreadsPerBlock;
83 static constexpr DeviceAttr_t deviceAttributeMultiprocessorCount = ::hipDeviceAttributeMultiprocessorCount;
84 static constexpr DeviceAttr_t deviceAttributeWarpSize = ::hipDeviceAttributeWarpSize;
86 static constexpr Memory_t memoryTypeUnregistered = ::hipMemoryTypeUnregistered;
87 static constexpr Memory_t memoryTypeHost = ::hipMemoryTypeHost;
88 static constexpr Memory_t memoryTypeDevice = ::hipMemoryTypeDevice;
89 static constexpr Memory_t memoryTypeManaged = ::hipMemoryTypeManaged;
91# if HIP_VERSION >= 40'500'000
92 static constexpr Limit_t limitPrintfFifoSize = ::hipLimitPrintfFifoSize;
94 static constexpr Limit_t limitPrintfFifoSize
95 =
static_cast<Limit_t
>(0x01);
97 static constexpr Limit_t limitMallocHeapSize = ::hipLimitMallocHeapSize;
107 static void hostFunction(
void* data)
109 auto ptr =
reinterpret_cast<HostFnAdaptor*
>(
data);
110 ptr->func_(ptr->data_);
114 static void streamCallback(Stream_t, Error_t,
void* data)
116 auto ptr =
reinterpret_cast<HostFnAdaptor*
>(
data);
117 ptr->func_(ptr->data_);
123 static inline Error_t deviceGetAttribute(
int* value, DeviceAttr_t attr,
int device)
125 return ::hipDeviceGetAttribute(value, attr, device);
128 static inline Error_t pointerGetAttributes(PointerAttr_t* attr,
void const* ptr)
130 return ::hipPointerGetAttributes(attr, ptr);
133 static inline Error_t deviceGetLimit(
size_t* pValue, Limit_t limit)
135# if HIP_VERSION < 40'500'000
136 if(limit == limitPrintfFifoSize)
139 return errorUnsupportedLimit;
142 return ::hipDeviceGetLimit(pValue, limit);
145 static inline Error_t deviceReset()
147 return ::hipDeviceReset();
150 static inline Error_t deviceSetLimit(Limit_t ,
size_t )
153 return errorUnsupportedLimit;
156 static inline Error_t deviceSynchronize()
158 return ::hipDeviceSynchronize();
161 static inline Error_t eventCreate(Event_t* event)
163 return ::hipEventCreate(event);
166 static inline Error_t eventCreateWithFlags(Event_t* event, Flag_t flags)
168 return ::hipEventCreateWithFlags(event, flags);
171 static inline Error_t eventDestroy(Event_t event)
173 return ::hipEventDestroy(event);
176 static inline Error_t eventQuery(Event_t event)
178 return ::hipEventQuery(event);
181 static inline Error_t eventRecord(Event_t event, Stream_t stream)
183 return ::hipEventRecord(event, stream);
186 static inline Error_t eventSynchronize(Event_t event)
188 return ::hipEventSynchronize(event);
191 static inline Error_t free(
void* devPtr)
193 return ::hipFree(devPtr);
196 static inline Error_t freeAsync(
void* devPtr, Stream_t stream)
201 return ::hipFreeAsync(devPtr, stream);
209 static inline Error_t funcGetAttributes(FuncAttributes_t* attr,
void const* func)
211 return ::hipFuncGetAttributes(attr, func);
215 static inline Error_t funcGetAttributes(FuncAttributes_t* attr, T* func)
221 return ::hipFuncGetAttributes(attr,
reinterpret_cast<void const*
>(func));
227 static inline Error_t getDeviceCount(
int* count)
229 return ::hipGetDeviceCount(count);
232 static inline Error_t getDeviceProperties(DeviceProp_t* prop,
int device)
234 return ::hipGetDeviceProperties(prop, device);
237 static inline char const* getErrorName(Error_t error)
239 return ::hipGetErrorName(error);
242 static inline char const* getErrorString(Error_t error)
244 return ::hipGetErrorString(error);
247 static inline Error_t getLastError()
249 return ::hipGetLastError();
252 static inline Error_t getSymbolAddress(
void** devPtr,
void const* symbol)
254 return ::hipGetSymbolAddress(devPtr, symbol);
258 static inline Error_t getSymbolAddress(
void** devPtr, T
const& symbol)
260 return ::hipGetSymbolAddress(devPtr, symbol);
263 static inline Error_t hostGetDevicePointer(
void** pDevice,
void* pHost, Flag_t flags)
265 return ::hipHostGetDevicePointer(pDevice, pHost, flags);
268 static inline Error_t hostFree(
void* ptr)
270 return ::hipHostFree(ptr);
273 static inline Error_t hostMalloc(
void** ptr,
size_t size, Flag_t flags)
275 return ::hipHostMalloc(ptr, size, flags);
278 static inline Error_t hostRegister(
void* ptr,
size_t size, Flag_t flags)
280 return ::hipHostRegister(ptr, size, flags);
283 static inline Error_t hostUnregister(
void* ptr)
285 return ::hipHostUnregister(ptr);
288 static inline Error_t launchHostFunc(Stream_t stream, HostFn_t fn,
void* userData)
291# if HIP_VERSION >= 50'400'000
293 return ::hipLaunchHostFunc(stream, HostFnAdaptor::hostFunction,
new HostFnAdaptor{fn, userData});
296 return ::hipStreamAddCallback(stream, HostFnAdaptor::streamCallback,
new HostFnAdaptor{fn, userData}, 0);
300 static inline Error_t malloc(
void** devPtr,
size_t size)
302 return ::hipMalloc(devPtr, size);
305 static inline Error_t mallocManaged(
void** devPtr,
size_t size)
307 return ::hipMallocManaged(devPtr, size);
310 static inline Error_t malloc3D(PitchedPtr_t* pitchedDevPtr, Extent_t extent)
312 return ::hipMalloc3D(pitchedDevPtr, extent);
315 static inline Error_t mallocAsync(
316 [[maybe_unused]]
void** devPtr,
317 [[maybe_unused]]
size_t size,
318 [[maybe_unused]] Stream_t stream)
321# if HIP_VERSION >= 50'600'000
322 return ::hipMallocAsync(devPtr, size, stream);
323# elif HIP_VERSION >= 50'300'000
327 return ::hipMallocAsync(devPtr, size, stream);
341 static inline Error_t mallocPitch(
void** devPtr,
size_t* pitch,
size_t width,
size_t height)
343 return ::hipMallocPitch(devPtr, pitch, width, height);
346 static inline Error_t memGetInfo(
size_t* free,
size_t* total)
348 return ::hipMemGetInfo(free, total);
351 static inline Error_t
memcpy(
void* dst,
void const* src,
size_t count, MemcpyKind_t kind)
353 return ::hipMemcpy(dst, src, count, kind);
356 static inline Error_t memcpy2DAsync(
366 return ::hipMemcpy2DAsync(dst, dpitch, src, spitch, width, height, kind, stream);
369 static inline Error_t memcpy3DAsync(Memcpy3DParms_t
const* p, Stream_t stream)
371 return ::hipMemcpy3DAsync(p, stream);
374 static inline Error_t memcpyAsync(
void* dst,
void const* src,
size_t count, MemcpyKind_t kind, Stream_t stream)
376 return ::hipMemcpyAsync(dst, src, count, kind, stream);
379 static inline Error_t memset2DAsync(
387 return ::hipMemset2DAsync(devPtr, pitch, value, width, height, stream);
390 static inline Error_t memset3DAsync(PitchedPtr_t pitchedDevPtr,
int value, Extent_t extent, Stream_t stream)
392 return ::hipMemset3DAsync(pitchedDevPtr, value, extent, stream);
395 static inline Error_t memsetAsync(
void* devPtr,
int value,
size_t count, Stream_t stream)
397 return ::hipMemsetAsync(devPtr, value, count, stream);
400 static inline Error_t setDevice(
int device)
402 return ::hipSetDevice(device);
405 static inline Error_t streamCreate(Stream_t* pStream)
407 return ::hipStreamCreate(pStream);
410 static inline Error_t streamCreateWithFlags(Stream_t* pStream, Flag_t flags)
412 return ::hipStreamCreateWithFlags(pStream, flags);
415 static inline Error_t streamDestroy(Stream_t stream)
417 return ::hipStreamDestroy(stream);
420 static inline Error_t streamQuery(Stream_t stream)
422 return ::hipStreamQuery(stream);
425 static inline Error_t streamSynchronize(Stream_t stream)
427 return ::hipStreamSynchronize(stream);
430 static inline Error_t streamWaitEvent(Stream_t stream, Event_t event, Flag_t flags)
432 return ::hipStreamWaitEvent(stream, event, flags);
435 static inline PitchedPtr_t makePitchedPtr(
void* d,
size_t p,
size_t xsz,
size_t ysz)
437 return ::make_hipPitchedPtr(d, p, xsz, ysz);
440 static inline Pos_t makePos(
size_t x,
size_t y,
size_t z)
442 return ::make_hipPos(x, y, z);
445 static inline Extent_t makeExtent(
size_t w,
size_t h,
size_t d)
447 return ::make_hipExtent(w, h, d);
#define ALPAKA_VERSION_NUMBER(major, minor, patch)
decltype(auto) data(auto &&any)
pointer to data of an object
void memcpy(Queue< T_Device, T_QueueKind > const &queue, auto &&dest, auto const &source)
copy data byte wise from one to another container