21#include "hip/hip_runtime.h"
24#define MLIR_ROCM_WRAPPERS_EXPORT __declspec(dllexport)
26#define MLIR_ROCM_WRAPPERS_EXPORT __attribute__((visibility("default")))
29#define HIP_REPORT_IF_ERROR(expr) \
30 [](hipError_t result) { \
33 const char *name = hipGetErrorName(result); \
36 fprintf(stderr, "'%s' failed with '%s'\n", #expr, name); \
43 hipModule_t module =
nullptr;
50 assert(
false &&
"This function is not available in HIP.");
60 hipFunction_t function =
nullptr;
71 intptr_t blockZ, int32_t smem, hipStream_t stream,
72 void **params,
void **extra,
size_t ) {
74 blockX, blockY, blockZ, smem,
75 stream, params, extra));
85 void **params,
void ** ) {
86 if (clusterX != 0 || clusterY != 0 || clusterZ != 0) {
88 "mgpuLaunchKernelCooperative: HIP does not support thread block "
89 "clusters (got cluster=%ld,%ld,%ld)\n",
90 clusterX, clusterY, clusterZ);
94 hipModuleLaunchCooperativeKernel(function, gridX, gridY, gridZ, blockX,
95 blockY, blockZ, smem, stream, params));
99 hipStream_t stream =
nullptr;
120 hipEvent_t
event =
nullptr;
135 hipStream_t stream) {
153mgpuMemcpy(
void *dst,
void *src,
size_t sizeBytes, hipStream_t stream) {
155 hipMemcpyAsync(dst, src, sizeBytes, hipMemcpyDefault, stream));
161 value, count, stream));
165mgpuMemset16(
void *dst,
int short value,
size_t count, hipStream_t stream) {
167 value, count, stream));
185 [[maybe_unused]]
int64_t *strides = &sizes[rank];
188 for (
int64_t i = rank - 1; i >= 0; --i) {
189 assert(strides[i] == runningStride &&
"Mismatch in computed dense strides");
190 runningStride *= sizes[i];
192 uint64_t sizeBytes = runningStride * elementSizeBytes;
194 auto *ptr = descriptor->
data + descriptor->
offset * elementSizeBytes;
210 auto ptr = descriptor->
data + descriptor->
offset * elementSizeBytes;
218 hipHostGetDevicePointer((
void **)devicePtr, hostPtr, 0));
224 float *devicePtr =
nullptr;
226 return {devicePtr, devicePtr, offset, {size}, {stride}};
232 int32_t *devicePtr =
nullptr;
234 return {devicePtr, devicePtr, offset, {size}, {stride}};
static thread_local int32_t defaultDevice
MLIR_ROCM_WRAPPERS_EXPORT void mgpuMemFree(void *ptr, hipStream_t)
MLIR_ROCM_WRAPPERS_EXPORT void mgpuSetDefaultDevice(int32_t device)
MLIR_ROCM_WRAPPERS_EXPORT void mgpuStreamDestroy(hipStream_t stream)
MLIR_ROCM_WRAPPERS_EXPORT void mgpuEventSynchronize(hipEvent_t event)
MLIR_ROCM_WRAPPERS_EXPORT void * mgpuMemAlloc(uint64_t sizeBytes, hipStream_t, bool)
MLIR_ROCM_WRAPPERS_EXPORT void mgpuMemHostRegister(void *ptr, uint64_t sizeBytes)
Helper functions for writing mlir example code.
MLIR_ROCM_WRAPPERS_EXPORT void mgpuEventRecord(hipEvent_t event, hipStream_t stream)
MLIR_ROCM_WRAPPERS_EXPORT void mgpuMemset32(void *dst, int value, size_t count, hipStream_t stream)
MLIR_ROCM_WRAPPERS_EXPORT hipModule_t mgpuModuleLoadJIT(void *data, int optLevel, size_t)
MLIR_ROCM_WRAPPERS_EXPORT hipStream_t mgpuStreamCreate()
MLIR_ROCM_WRAPPERS_EXPORT void mgpuMemHostUnregisterMemRef(int64_t rank, StridedMemRefType< char, 1 > *descriptor, int64_t elementSizeBytes)
MLIR_ROCM_WRAPPERS_EXPORT void mgpuMemcpy(void *dst, void *src, size_t sizeBytes, hipStream_t stream)
MLIR_ROCM_WRAPPERS_EXPORT void mgpuLaunchKernelCooperative(hipFunction_t function, intptr_t gridX, intptr_t gridY, intptr_t gridZ, intptr_t clusterX, intptr_t clusterY, intptr_t clusterZ, intptr_t blockX, intptr_t blockY, intptr_t blockZ, int32_t smem, hipStream_t stream, void **params, void **)
MLIR_ROCM_WRAPPERS_EXPORT 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)
MLIR_ROCM_WRAPPERS_EXPORT hipEvent_t mgpuEventCreate()
MLIR_ROCM_WRAPPERS_EXPORT void mgpuModuleUnload(hipModule_t module)
MLIR_ROCM_WRAPPERS_EXPORT hipFunction_t mgpuModuleGetFunction(hipModule_t module, const char *name)
void mgpuMemGetDevicePointer(T *hostPtr, T **devicePtr)
MLIR_ROCM_WRAPPERS_EXPORT StridedMemRefType< float, 1 > mgpuMemGetDeviceMemRef1dFloat(float *allocated, float *aligned, int64_t offset, int64_t size, int64_t stride)
#define MLIR_ROCM_WRAPPERS_EXPORT
MLIR_ROCM_WRAPPERS_EXPORT void mgpuStreamWaitEvent(hipStream_t stream, hipEvent_t event)
MLIR_ROCM_WRAPPERS_EXPORT void mgpuMemset16(void *dst, int short value, size_t count, hipStream_t stream)
MLIR_ROCM_WRAPPERS_EXPORT void mgpuEventDestroy(hipEvent_t event)
MLIR_ROCM_WRAPPERS_EXPORT hipModule_t mgpuModuleLoad(void *data, size_t)
MLIR_ROCM_WRAPPERS_EXPORT void mgpuStreamSynchronize(hipStream_t stream)
MLIR_ROCM_WRAPPERS_EXPORT StridedMemRefType< int32_t, 1 > mgpuMemGetDeviceMemRef1dInt32(int32_t *allocated, int32_t *aligned, int64_t offset, int64_t size, int64_t stride)
#define HIP_REPORT_IF_ERROR(expr)
MLIR_ROCM_WRAPPERS_EXPORT void mgpuMemHostUnregister(void *ptr)
MLIR_ROCM_WRAPPERS_EXPORT void mgpuMemHostRegisterMemRef(int64_t rank, StridedMemRefType< char, 1 > *descriptor, int64_t elementSizeBytes)
StridedMemRef descriptor type with static rank.