1 #ifndef EIGEN_TEST_GPU_COMMON_H 2 #define EIGEN_TEST_GPU_COMMON_H 5 #include <hip/hip_runtime.h> 6 #include <hip/hip_runtime_api.h> 9 #include <cuda_runtime.h> 10 #include <cuda_runtime_api.h> 18 #if !defined(__CUDACC__) && !defined(__HIPCC__) 22 template<
typename Kernel,
typename Input,
typename Output>
25 for(
int i=0;
i<
n;
i++)
26 ker(
i, in.data(), out.data());
30 template<
typename Kernel,
typename Input,
typename Output>
42 template<
typename Kernel,
typename Input,
typename Output>
47 std::ptrdiff_t in_bytes = in.size() *
sizeof(
typename Input::Scalar);
48 std::ptrdiff_t out_bytes = out.size() *
sizeof(
typename Output::Scalar);
50 gpuMalloc((
void**)(&d_in), in_bytes);
51 gpuMalloc((
void**)(&d_out), out_bytes);
53 gpuMemcpy(d_in, in.data(), in_bytes, gpuMemcpyHostToDevice);
54 gpuMemcpy(d_out, out.data(), out_bytes, gpuMemcpyHostToDevice);
59 dim3 Grids( (n+
int(Blocks.x)-1)/
int(Blocks.x) );
61 gpuDeviceSynchronize();
65 typename std::decay<decltype(*d_in)>::
type,
66 typename std::decay<decltype(*d_out)>::
type>),
67 dim3(Grids), dim3(Blocks), 0, 0, ker, n, d_in, d_out);
69 run_on_gpu_meta_kernel<<<Grids,Blocks>>>(ker,
n, d_in, d_out);
72 gpuError_t err = gpuGetLastError();
73 if (err != gpuSuccess) {
74 printf(
"%s: %s\n", gpuGetErrorName(err), gpuGetErrorString(err));
79 err = gpuDeviceSynchronize();
80 if (err != gpuSuccess) {
81 printf(
"%s: %s\n", gpuGetErrorName(err), gpuGetErrorString(err));
87 gpuMemcpy(const_cast<typename Input::Scalar*>(in.data()), d_in, in_bytes, gpuMemcpyDeviceToHost);
88 gpuMemcpy(out.data(), d_out, out_bytes, gpuMemcpyDeviceToHost);
95 template<
typename Kernel,
typename Input,
typename Output>
99 Output out_ref, out_gpu;
100 #if !defined(EIGEN_GPU_COMPILE_PHASE) 101 in_ref = in_gpu = in;
102 out_ref = out_gpu =
out;
109 #if !defined(EIGEN_GPU_COMPILE_PHASE) 121 #if defined(__CUDA_ARCH__) 122 info[0] =
int(__CUDA_ARCH__ +0);
124 #if defined(EIGEN_HIP_DEVICE_COMPILE) 125 info[1] =
int(EIGEN_HIP_DEVICE_COMPILE +0);
134 gpuDeviceProp_t deviceProp;
135 gpuGetDeviceProperties(&deviceProp, device);
142 std::cout <<
"GPU compile-time info:\n";
145 std::cout <<
" EIGEN_CUDACC: " <<
int(EIGEN_CUDACC) <<
"\n";
148 #ifdef EIGEN_CUDA_SDK_VER 152 #ifdef EIGEN_COMP_NVCC 157 std::cout <<
" EIGEN_HIPCC: " <<
int(EIGEN_HIPCC) <<
"\n";
160 std::cout <<
" EIGEN_CUDA_ARCH: " << info[0] <<
"\n";
161 std::cout <<
" EIGEN_HIP_DEVICE_COMPILE: " << info[1] <<
"\n";
163 std::cout <<
"GPU device info:\n";
164 std::cout <<
" name: " << deviceProp.name <<
"\n";
165 std::cout <<
" capability: " << deviceProp.major <<
"." << deviceProp.minor <<
"\n";
166 std::cout <<
" multiProcessorCount: " << deviceProp.multiProcessorCount <<
"\n";
167 std::cout <<
" maxThreadsPerMultiProcessor: " << deviceProp.maxThreadsPerMultiProcessor <<
"\n";
168 std::cout <<
" warpSize: " << deviceProp.warpSize <<
"\n";
169 std::cout <<
" regsPerBlock: " << deviceProp.regsPerBlock <<
"\n";
170 std::cout <<
" concurrentKernels: " << deviceProp.concurrentKernels <<
"\n";
171 std::cout <<
" clockRate: " << deviceProp.clockRate <<
"\n";
172 std::cout <<
" canMapHostMemory: " << deviceProp.canMapHostMemory <<
"\n";
173 std::cout <<
" computeMode: " << deviceProp.computeMode <<
"\n";
176 #endif // EIGEN_TEST_GPU_COMMON_H void run_and_compare_to_gpu(const Kernel &ker, int n, const Input &in, Output &out)
#define EIGEN_HIP_LAUNCH_BOUNDS_1024
std::ofstream out("Result.txt")
EIGEN_DEVICE_FUNC void operator()(int i, const int *, int *info) const
#define VERIFY_IS_APPROX(a, b)
#define EIGEN_CUDA_SDK_VER
__global__ EIGEN_HIP_LAUNCH_BOUNDS_1024 void run_on_gpu_meta_kernel(const Kernel ker, int n, const Input *in, Output *out)
#define EIGEN_DEVICE_FUNC
void run_on_cpu(const Kernel &ker, int n, const Input &in, Output &out)
#define EIGEN_UNUSED_VARIABLE(var)
void run_on_gpu(const Kernel &ker, int n, const Input &in, Output &out)