cuda_to_hip.h
1#ifndef CUDA_TO_HIP_H
2#define CUDA_TO_HIP_H
3
4#include <hip/hip_runtime.h>
5
6// Set of macros pointing CUDA functions to their analogous HIP function.
7
8#define WARPSIZE 64
9static constexpr int maxWarpsPerBlock = 1024/WARPSIZE;
10
11#define CUFFT_D2Z HIPFFT_D2Z
12#define CUFFT_FORWARD HIPFFT_FORWARD
13#define CUFFT_INVERSE HIPFFT_BACKWARD
14#define CUFFT_Z2D HIPFFT_Z2D
15#define CUFFT_Z2Z HIPFFT_Z2Z
16
17#define cudaDeviceSynchronize hipDeviceSynchronize
18#define cudaError hipError_t
19#define cudaError_t hipError_t
20#define cudaErrorInsufficientDriver hipErrorInsufficientDriver
21#define cudaErrorNoDevice hipErrorNoDevice
22#define cudaEvent_t hipEvent_t
23#define cudaEventCreate hipEventCreate
24#define cudaEventElapsedTime hipEventElapsedTime
25#define cudaEventRecord hipEventRecord
26#define cudaEventSynchronize hipEventSynchronize
27#define cudaFree hipFree
28#define cudaFreeHost hipHostFree
29#define cudaGetDevice hipGetDevice
30#define cudaGetDeviceCount hipGetDeviceCount
31#define cudaGetErrorString hipGetErrorString
32#define cudaGetLastError hipGetLastError
33#define cudaHostAlloc hipHostMalloc
34#define cudaHostAllocDefault hipHostMallocDefault
35#define cudaMalloc hipMalloc
36#define cudaMemcpy hipMemcpy
37#define cudaMemcpyAsync hipMemcpyAsync
38#define cudaMemcpyDeviceToHost hipMemcpyDeviceToHost
39#define cudaMemcpyDeviceToDevice hipMemcpyDeviceToDevice
40#define cudaMemcpyHostToDevice hipMemcpyHostToDevice
41#define cudaMemGetInfo hipMemGetInfo
42#define cudaMemset hipMemset
43#define cudaReadModeElementType hipReadModeElementType
44#define cudaSetDevice hipSetDevice
45#define cudaSuccess hipSuccess
46#define cudaDeviceProp hipDeviceProp_t
47#define cudaGetDeviceProperties hipGetDeviceProperties
48#define cudaThreadSynchronize hipDeviceSynchronize
49
50
51#define cufftDestroy hipfftDestroy
52#define cufftDoubleComplex hipfftDoubleComplex
53#define cufftDoubleReal hipfftDoubleReal
54#define cufftExecD2Z hipfftExecD2Z
55#define cufftExecZ2D hipfftExecZ2D
56#define cufftExecZ2Z hipfftExecZ2Z
57#define cufftHandle hipfftHandle
58#define cufftPlan3d hipfftPlan3d
59#define cufftPlanMany hipfftPlanMany
60
61static void __attribute__((unused)) check(const hipError_t err, const char *const file, const int line)
62{
63 if (err == hipSuccess) return;
64 fprintf(stderr,"HIP ERROR AT LINE %d OF FILE '%s': %s %s\n",line,file,hipGetErrorName(err),hipGetErrorString(err));
65 fflush(stderr);
66 exit(err);
67}
68
69#endif //CUDA_TO_HIP_H