14 #define EIGEN_TEST_NO_LONGDOUBLE 15 #define EIGEN_TEST_NO_COMPLEX 16 #define EIGEN_TEST_FUNC cxx11_tensor_reduction_sycl 17 #define EIGEN_DEFAULT_DENSE_INDEX_TYPE int 18 #define EIGEN_USE_SYCL 21 #include <unsupported/Eigen/CXX11/Tensor> 27 const int num_rows = 452;
28 const int num_cols = 765;
29 array<int, 2> tensorRange = {{num_rows, num_cols}};
31 Tensor<float, 2> in(tensorRange);
32 Tensor<float, 0> full_redux;
33 Tensor<float, 0> full_redux_gpu;
37 full_redux = in.sum();
39 float* gpu_in_data =
static_cast<float*
>(sycl_device.allocate(in.dimensions().TotalSize()*
sizeof(float)));
40 float* gpu_out_data =(
float*)sycl_device.allocate(
sizeof(
float));
42 TensorMap<Tensor<float, 2> > in_gpu(gpu_in_data, tensorRange);
43 TensorMap<Tensor<float, 0> > out_gpu(gpu_out_data);
45 sycl_device.memcpyHostToDevice(gpu_in_data, in.data(),(in.dimensions().TotalSize())*
sizeof(
float));
46 out_gpu.device(sycl_device) = in_gpu.sum();
47 sycl_device.memcpyDeviceToHost(full_redux_gpu.data(), gpu_out_data,
sizeof(float));
49 VERIFY_IS_APPROX(full_redux_gpu(), full_redux());
51 sycl_device.deallocate(gpu_in_data);
52 sycl_device.deallocate(gpu_out_data);
61 array<int, 3> tensorRange = {{dim_x, dim_y, dim_z}};
64 array<int, 2> reduced_tensorRange = {{dim_y, dim_z}};
66 Tensor<float, 3> in(tensorRange);
67 Tensor<float, 2> redux(reduced_tensorRange);
68 Tensor<float, 2> redux_gpu(reduced_tensorRange);
72 redux= in.sum(red_axis);
74 float* gpu_in_data =
static_cast<float*
>(sycl_device.allocate(in.dimensions().TotalSize()*
sizeof(float)));
75 float* gpu_out_data =
static_cast<float*
>(sycl_device.allocate(redux_gpu.dimensions().TotalSize()*
sizeof(float)));
77 TensorMap<Tensor<float, 3> > in_gpu(gpu_in_data, tensorRange);
78 TensorMap<Tensor<float, 2> > out_gpu(gpu_out_data, reduced_tensorRange);
80 sycl_device.memcpyHostToDevice(gpu_in_data, in.data(),(in.dimensions().TotalSize())*
sizeof(
float));
81 out_gpu.device(sycl_device) = in_gpu.sum(red_axis);
82 sycl_device.memcpyDeviceToHost(redux_gpu.data(), gpu_out_data, redux_gpu.dimensions().TotalSize()*
sizeof(float));
85 for(
int j=0; j<reduced_tensorRange[0]; j++ )
86 for(
int k=0; k<reduced_tensorRange[1]; k++ )
87 VERIFY_IS_APPROX(redux_gpu(j,k), redux(j,k));
89 sycl_device.deallocate(gpu_in_data);
90 sycl_device.deallocate(gpu_out_data);
99 array<int, 3> tensorRange = {{dim_x, dim_y, dim_z}};
102 array<int, 2> reduced_tensorRange = {{dim_x, dim_y}};
104 Tensor<float, 3> in(tensorRange);
105 Tensor<float, 2> redux(reduced_tensorRange);
106 Tensor<float, 2> redux_gpu(reduced_tensorRange);
110 redux= in.sum(red_axis);
112 float* gpu_in_data =
static_cast<float*
>(sycl_device.allocate(in.dimensions().TotalSize()*
sizeof(float)));
113 float* gpu_out_data =
static_cast<float*
>(sycl_device.allocate(redux_gpu.dimensions().TotalSize()*
sizeof(float)));
115 TensorMap<Tensor<float, 3> > in_gpu(gpu_in_data, tensorRange);
116 TensorMap<Tensor<float, 2> > out_gpu(gpu_out_data, reduced_tensorRange);
118 sycl_device.memcpyHostToDevice(gpu_in_data, in.data(),(in.dimensions().TotalSize())*
sizeof(
float));
119 out_gpu.device(sycl_device) = in_gpu.sum(red_axis);
120 sycl_device.memcpyDeviceToHost(redux_gpu.data(), gpu_out_data, redux_gpu.dimensions().TotalSize()*
sizeof(float));
122 for(
int j=0; j<reduced_tensorRange[0]; j++ )
123 for(
int k=0; k<reduced_tensorRange[1]; k++ )
124 VERIFY_IS_APPROX(redux_gpu(j,k), redux(j,k));
126 sycl_device.deallocate(gpu_in_data);
127 sycl_device.deallocate(gpu_out_data);
132 cl::sycl::gpu_selector
s;
133 Eigen::SyclDevice sycl_device(s);
static void test_full_reductions_sycl(const Eigen::SyclDevice &sycl_device)
static void test_first_dim_reductions_sycl(const Eigen::SyclDevice &sycl_device)
void test_cxx11_tensor_reduction_sycl()
static void test_last_dim_reductions_sycl(const Eigen::SyclDevice &sycl_device)