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__)
22template<
typename Kernel,
typename Input,
typename Output>
25 for(
int i=0;
i<
n;
i++)
26 ker(
i, in.data(),
out.data());
30template<
typename Kernel,
typename Input,
typename Output>
42template<
typename Kernel,
typename Input,
typename Output>
45 typename Input::Scalar* d_in;
46 typename Output::Scalar* d_out;
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);
95template<
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);
137 ArrayXi dummy(1),
info(10);
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";
int n
Definition BiCGSTAB_simple.cpp:1
int i
Definition BiCGSTAB_step_by_step.cpp:9
#define EIGEN_CUDA_SDK_VER
Definition Macros.h:476
#define EIGEN_UNUSED_VARIABLE(var)
Definition Macros.h:1076
#define EIGEN_DEVICE_FUNC
Definition Macros.h:976
#define EIGEN_HIP_LAUNCH_BOUNDS_1024
Definition Macros.h:510
#define EIGEN_COMP_NVCC
Definition Macros.h:126
dim3 threadIdx
Definition gpu_common.h:19
dim3 blockDim
Definition gpu_common.h:19
void ei_test_init_gpu()
Definition gpu_common.h:131
void run_and_compare_to_gpu(const Kernel &ker, int n, const Input &in, Output &out)
Definition gpu_common.h:96
__global__ EIGEN_HIP_LAUNCH_BOUNDS_1024 void run_on_gpu_meta_kernel(const Kernel ker, int n, const Input *in, Output *out)
Definition gpu_common.h:33
dim3 blockIdx
Definition gpu_common.h:19
void run_on_cpu(const Kernel &ker, int n, const Input &in, Output &out)
Definition gpu_common.h:23
void run_on_gpu(const Kernel &ker, int n, const Input &in, Output &out)
Definition gpu_common.h:43
#define VERIFY_IS_APPROX(a, b)
Definition integer_types.cpp:15
else if n * info
Definition cholesky.cpp:18
Definition gpu_common.h:115
EIGEN_DEVICE_FUNC void operator()(int i, const int *, int *info) const
Definition gpu_common.h:117
std::ofstream out("Result.txt")