19 #include "llvm/ADT/ArrayRef.h"
21 #include "hip/hip_runtime.h"
23 #define HIP_REPORT_IF_ERROR(expr) \
24 [](hipError_t result) { \
27 const char *name = hipGetErrorName(result); \
30 fprintf(stderr, "'%s' failed with '%s'\n", #expr, name); \
36 hipModule_t module =
nullptr;
42 assert(
false &&
"This function is not available in HIP.");
52 hipFunction_t
function =
nullptr;
61 intptr_t gridY, intptr_t gridZ,
62 intptr_t blockX, intptr_t blockY,
63 intptr_t blockZ, int32_t smem,
64 hipStream_t stream,
void **params,
65 void **extra,
size_t ) {
67 blockX, blockY, blockZ, smem,
68 stream, params, extra));
72 hipStream_t stream =
nullptr;
90 hipEvent_t
event =
nullptr;
118 extern "C" void mgpuMemcpy(
void *dst,
void *src,
size_t sizeBytes,
119 hipStream_t stream) {
121 hipMemcpyAsync(dst, src, sizeBytes, hipMemcpyDefault, stream));
125 hipStream_t stream) {
127 value, count, stream));
131 hipStream_t stream) {
133 value, count, stream));
148 int64_t elementSizeBytes) {
154 std::partial_sum(sizes.rbegin(), sizes.rend(), denseStrides.rbegin(),
155 std::multiplies<int64_t>());
156 auto sizeBytes = denseStrides.front() * elementSizeBytes;
159 std::rotate(denseStrides.begin(), denseStrides.begin() + 1,
161 denseStrides.back() = 1;
164 auto ptr = descriptor->
data + descriptor->
offset * elementSizeBytes;
179 int64_t elementSizeBytes) {
180 auto ptr = descriptor->
data + descriptor->
offset * elementSizeBytes;
184 template <
typename T>
188 hipHostGetDevicePointer((
void **)devicePtr, hostPtr, 0));
193 int64_t size, int64_t stride) {
194 float *devicePtr =
nullptr;
196 return {devicePtr, devicePtr, offset, {size}, {stride}};
201 int64_t offset, int64_t size, int64_t stride) {
202 int32_t *devicePtr =
nullptr;
204 return {devicePtr, devicePtr, offset, {size}, {stride}};
void mgpuMemset32(void *dst, int value, size_t count, hipStream_t stream)
void mgpuMemHostRegister(void *ptr, uint64_t sizeBytes)
Helper functions for writing mlir example code.
void mgpuMemset16(void *dst, int short value, size_t count, hipStream_t stream)
void mgpuStreamWaitEvent(hipStream_t stream, hipEvent_t event)
static thread_local int32_t defaultDevice
hipEvent_t mgpuEventCreate()
void mgpuEventSynchronize(hipEvent_t event)
void mgpuStreamDestroy(hipStream_t stream)
void mgpuMemHostUnregister(void *ptr)
void mgpuStreamSynchronize(hipStream_t stream)
void * mgpuMemAlloc(uint64_t sizeBytes, hipStream_t, bool)
StridedMemRefType< int32_t, 1 > mgpuMemGetDeviceMemRef1dInt32(int32_t *allocated, int32_t *aligned, int64_t offset, int64_t size, int64_t stride)
void mgpuModuleUnload(hipModule_t module)
void mgpuMemGetDevicePointer(T *hostPtr, T **devicePtr)
StridedMemRefType< float, 1 > mgpuMemGetDeviceMemRef1dFloat(float *allocated, float *aligned, int64_t offset, int64_t size, int64_t stride)
void mgpuMemcpy(void *dst, void *src, size_t sizeBytes, hipStream_t stream)
void mgpuMemHostRegisterMemRef(int64_t rank, StridedMemRefType< char, 1 > *descriptor, int64_t elementSizeBytes)
hipFunction_t mgpuModuleGetFunction(hipModule_t module, const char *name)
hipModule_t mgpuModuleLoadJIT(void *data, int optLevel)
hipModule_t mgpuModuleLoad(void *data, size_t)
void mgpuEventDestroy(hipEvent_t event)
void mgpuEventRecord(hipEvent_t event, hipStream_t stream)
#define HIP_REPORT_IF_ERROR(expr)
void mgpuMemFree(void *ptr, hipStream_t)
void mgpuSetDefaultDevice(int32_t device)
void mgpuLaunchKernel(hipFunction_t function, intptr_t gridX, intptr_t gridY, intptr_t gridZ, intptr_t blockX, intptr_t blockY, intptr_t blockZ, int32_t smem, hipStream_t stream, void **params, void **extra, size_t)
void mgpuMemHostUnregisterMemRef(int64_t rank, StridedMemRefType< char, 1 > *descriptor, int64_t elementSizeBytes)
hipStream_t mgpuStreamCreate()
StridedMemRef descriptor type with static rank.