cxx11_tensor_patch_sycl.cpp File Reference
#include "main.h"
#include <Eigen/CXX11/Tensor>

Macros

#define EIGEN_TEST_NO_LONGDOUBLE
 
#define EIGEN_TEST_NO_COMPLEX
 
#define EIGEN_DEFAULT_DENSE_INDEX_TYPE   int64_t
 
#define EIGEN_USE_SYCL
 

Functions

template<typename DataType , int DataLayout, typename IndexType >
static void test_simple_patch_sycl (const Eigen::SyclDevice &sycl_device)
 
template<typename DataType , typename dev_Selector >
void sycl_tensor_patch_test_per_device (dev_Selector s)
 
 EIGEN_DECLARE_TEST (cxx11_tensor_patch_sycl)
 

Macro Definition Documentation

◆ EIGEN_DEFAULT_DENSE_INDEX_TYPE

#define EIGEN_DEFAULT_DENSE_INDEX_TYPE   int64_t

◆ EIGEN_TEST_NO_COMPLEX

#define EIGEN_TEST_NO_COMPLEX

◆ EIGEN_TEST_NO_LONGDOUBLE

#define EIGEN_TEST_NO_LONGDOUBLE

◆ EIGEN_USE_SYCL

#define EIGEN_USE_SYCL

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( cxx11_tensor_patch_sycl  )
244  {
245  for (const auto& device : Eigen::get_sycl_supported_devices()) {
246  CALL_SUBTEST(sycl_tensor_patch_test_per_device<half>(device));
247  CALL_SUBTEST(sycl_tensor_patch_test_per_device<float>(device));
248  }
249 }
#define CALL_SUBTEST(FUNC)
Definition: main.h:382

References CALL_SUBTEST.

◆ sycl_tensor_patch_test_per_device()

template<typename DataType , typename dev_Selector >
void sycl_tensor_patch_test_per_device ( dev_Selector  s)
238  {
239  QueueInterface queueInterface(s);
240  auto sycl_device = Eigen::SyclDevice(&queueInterface);
241  test_simple_patch_sycl<DataType, RowMajor, int64_t>(sycl_device);
242  test_simple_patch_sycl<DataType, ColMajor, int64_t>(sycl_device);
243 }
RealScalar s
Definition: level1_cplx_impl.h:130

References s.

◆ test_simple_patch_sycl()

template<typename DataType , int DataLayout, typename IndexType >
static void test_simple_patch_sycl ( const Eigen::SyclDevice &  sycl_device)
static
28  {
29  IndexType sizeDim1 = 2;
30  IndexType sizeDim2 = 3;
31  IndexType sizeDim3 = 5;
32  IndexType sizeDim4 = 7;
33  array<IndexType, 4> tensorRange = {{sizeDim1, sizeDim2, sizeDim3, sizeDim4}};
34  array<IndexType, 5> patchTensorRange;
35  if (DataLayout == ColMajor) {
36  patchTensorRange = {{1, 1, 1, 1, sizeDim1 * sizeDim2 * sizeDim3 * sizeDim4}};
37  } else {
38  patchTensorRange = {{sizeDim1 * sizeDim2 * sizeDim3 * sizeDim4, 1, 1, 1, 1}};
39  }
40 
42  Tensor<DataType, 5, DataLayout, IndexType> no_patch(patchTensorRange);
43 
44  tensor.setRandom();
45 
46  array<ptrdiff_t, 4> patch_dims;
47  patch_dims[0] = 1;
48  patch_dims[1] = 1;
49  patch_dims[2] = 1;
50  patch_dims[3] = 1;
51 
52  const size_t tensorBuffSize = tensor.size() * sizeof(DataType);
53  size_t patchTensorBuffSize = no_patch.size() * sizeof(DataType);
54  DataType* gpu_data_tensor = static_cast<DataType*>(sycl_device.allocate(tensorBuffSize));
55  DataType* gpu_data_no_patch = static_cast<DataType*>(sycl_device.allocate(patchTensorBuffSize));
56 
57  TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_tensor(gpu_data_tensor, tensorRange);
58  TensorMap<Tensor<DataType, 5, DataLayout, IndexType>> gpu_no_patch(gpu_data_no_patch, patchTensorRange);
59 
60  sycl_device.memcpyHostToDevice(gpu_data_tensor, tensor.data(), tensorBuffSize);
61  gpu_no_patch.device(sycl_device) = gpu_tensor.extract_patches(patch_dims);
62  sycl_device.memcpyDeviceToHost(no_patch.data(), gpu_data_no_patch, patchTensorBuffSize);
63 
64  if (DataLayout == ColMajor) {
65  VERIFY_IS_EQUAL(no_patch.dimension(0), 1);
66  VERIFY_IS_EQUAL(no_patch.dimension(1), 1);
67  VERIFY_IS_EQUAL(no_patch.dimension(2), 1);
68  VERIFY_IS_EQUAL(no_patch.dimension(3), 1);
69  VERIFY_IS_EQUAL(no_patch.dimension(4), tensor.size());
70  } else {
71  VERIFY_IS_EQUAL(no_patch.dimension(0), tensor.size());
72  VERIFY_IS_EQUAL(no_patch.dimension(1), 1);
73  VERIFY_IS_EQUAL(no_patch.dimension(2), 1);
74  VERIFY_IS_EQUAL(no_patch.dimension(3), 1);
75  VERIFY_IS_EQUAL(no_patch.dimension(4), 1);
76  }
77 
78  for (int i = 0; i < tensor.size(); ++i) {
79  VERIFY_IS_EQUAL(tensor.data()[i], no_patch.data()[i]);
80  }
81 
82  patch_dims[0] = 2;
83  patch_dims[1] = 3;
84  patch_dims[2] = 5;
85  patch_dims[3] = 7;
86 
87  if (DataLayout == ColMajor) {
88  patchTensorRange = {{sizeDim1, sizeDim2, sizeDim3, sizeDim4, 1}};
89  } else {
90  patchTensorRange = {{1, sizeDim1, sizeDim2, sizeDim3, sizeDim4}};
91  }
92  Tensor<DataType, 5, DataLayout, IndexType> single_patch(patchTensorRange);
93  patchTensorBuffSize = single_patch.size() * sizeof(DataType);
94  DataType* gpu_data_single_patch = static_cast<DataType*>(sycl_device.allocate(patchTensorBuffSize));
95  TensorMap<Tensor<DataType, 5, DataLayout, IndexType>> gpu_single_patch(gpu_data_single_patch, patchTensorRange);
96 
97  gpu_single_patch.device(sycl_device) = gpu_tensor.extract_patches(patch_dims);
98  sycl_device.memcpyDeviceToHost(single_patch.data(), gpu_data_single_patch, patchTensorBuffSize);
99 
100  if (DataLayout == ColMajor) {
101  VERIFY_IS_EQUAL(single_patch.dimension(0), 2);
102  VERIFY_IS_EQUAL(single_patch.dimension(1), 3);
103  VERIFY_IS_EQUAL(single_patch.dimension(2), 5);
104  VERIFY_IS_EQUAL(single_patch.dimension(3), 7);
105  VERIFY_IS_EQUAL(single_patch.dimension(4), 1);
106  } else {
107  VERIFY_IS_EQUAL(single_patch.dimension(0), 1);
108  VERIFY_IS_EQUAL(single_patch.dimension(1), 2);
109  VERIFY_IS_EQUAL(single_patch.dimension(2), 3);
110  VERIFY_IS_EQUAL(single_patch.dimension(3), 5);
111  VERIFY_IS_EQUAL(single_patch.dimension(4), 7);
112  }
113 
114  for (int i = 0; i < tensor.size(); ++i) {
115  VERIFY_IS_EQUAL(tensor.data()[i], single_patch.data()[i]);
116  }
117  patch_dims[0] = 1;
118  patch_dims[1] = 2;
119  patch_dims[2] = 2;
120  patch_dims[3] = 1;
121 
122  if (DataLayout == ColMajor) {
123  patchTensorRange = {{1, 2, 2, 1, 2 * 2 * 4 * 7}};
124  } else {
125  patchTensorRange = {{2 * 2 * 4 * 7, 1, 2, 2, 1}};
126  }
127  Tensor<DataType, 5, DataLayout, IndexType> twod_patch(patchTensorRange);
128  patchTensorBuffSize = twod_patch.size() * sizeof(DataType);
129  DataType* gpu_data_twod_patch = static_cast<DataType*>(sycl_device.allocate(patchTensorBuffSize));
130  TensorMap<Tensor<DataType, 5, DataLayout, IndexType>> gpu_twod_patch(gpu_data_twod_patch, patchTensorRange);
131 
132  gpu_twod_patch.device(sycl_device) = gpu_tensor.extract_patches(patch_dims);
133  sycl_device.memcpyDeviceToHost(twod_patch.data(), gpu_data_twod_patch, patchTensorBuffSize);
134 
135  if (DataLayout == ColMajor) {
136  VERIFY_IS_EQUAL(twod_patch.dimension(0), 1);
137  VERIFY_IS_EQUAL(twod_patch.dimension(1), 2);
138  VERIFY_IS_EQUAL(twod_patch.dimension(2), 2);
139  VERIFY_IS_EQUAL(twod_patch.dimension(3), 1);
140  VERIFY_IS_EQUAL(twod_patch.dimension(4), 2 * 2 * 4 * 7);
141  } else {
142  VERIFY_IS_EQUAL(twod_patch.dimension(0), 2 * 2 * 4 * 7);
143  VERIFY_IS_EQUAL(twod_patch.dimension(1), 1);
144  VERIFY_IS_EQUAL(twod_patch.dimension(2), 2);
145  VERIFY_IS_EQUAL(twod_patch.dimension(3), 2);
146  VERIFY_IS_EQUAL(twod_patch.dimension(4), 1);
147  }
148 
149  for (int i = 0; i < 2; ++i) {
150  for (int j = 0; j < 2; ++j) {
151  for (int k = 0; k < 4; ++k) {
152  for (int l = 0; l < 7; ++l) {
153  int patch_loc;
154  if (DataLayout == ColMajor) {
155  patch_loc = i + 2 * (j + 2 * (k + 4 * l));
156  } else {
157  patch_loc = l + 7 * (k + 4 * (j + 2 * i));
158  }
159  for (int x = 0; x < 2; ++x) {
160  for (int y = 0; y < 2; ++y) {
161  if (DataLayout == ColMajor) {
162  VERIFY_IS_EQUAL(tensor(i, j + x, k + y, l), twod_patch(0, x, y, 0, patch_loc));
163  } else {
164  VERIFY_IS_EQUAL(tensor(i, j + x, k + y, l), twod_patch(patch_loc, 0, x, y, 0));
165  }
166  }
167  }
168  }
169  }
170  }
171  }
172 
173  patch_dims[0] = 1;
174  patch_dims[1] = 2;
175  patch_dims[2] = 3;
176  patch_dims[3] = 5;
177 
178  if (DataLayout == ColMajor) {
179  patchTensorRange = {{1, 2, 3, 5, 2 * 2 * 3 * 3}};
180  } else {
181  patchTensorRange = {{2 * 2 * 3 * 3, 1, 2, 3, 5}};
182  }
183  Tensor<DataType, 5, DataLayout, IndexType> threed_patch(patchTensorRange);
184  patchTensorBuffSize = threed_patch.size() * sizeof(DataType);
185  DataType* gpu_data_threed_patch = static_cast<DataType*>(sycl_device.allocate(patchTensorBuffSize));
186  TensorMap<Tensor<DataType, 5, DataLayout, IndexType>> gpu_threed_patch(gpu_data_threed_patch, patchTensorRange);
187 
188  gpu_threed_patch.device(sycl_device) = gpu_tensor.extract_patches(patch_dims);
189  sycl_device.memcpyDeviceToHost(threed_patch.data(), gpu_data_threed_patch, patchTensorBuffSize);
190 
191  if (DataLayout == ColMajor) {
192  VERIFY_IS_EQUAL(threed_patch.dimension(0), 1);
193  VERIFY_IS_EQUAL(threed_patch.dimension(1), 2);
194  VERIFY_IS_EQUAL(threed_patch.dimension(2), 3);
195  VERIFY_IS_EQUAL(threed_patch.dimension(3), 5);
196  VERIFY_IS_EQUAL(threed_patch.dimension(4), 2 * 2 * 3 * 3);
197  } else {
198  VERIFY_IS_EQUAL(threed_patch.dimension(0), 2 * 2 * 3 * 3);
199  VERIFY_IS_EQUAL(threed_patch.dimension(1), 1);
200  VERIFY_IS_EQUAL(threed_patch.dimension(2), 2);
201  VERIFY_IS_EQUAL(threed_patch.dimension(3), 3);
202  VERIFY_IS_EQUAL(threed_patch.dimension(4), 5);
203  }
204 
205  for (int i = 0; i < 2; ++i) {
206  for (int j = 0; j < 2; ++j) {
207  for (int k = 0; k < 3; ++k) {
208  for (int l = 0; l < 3; ++l) {
209  int patch_loc;
210  if (DataLayout == ColMajor) {
211  patch_loc = i + 2 * (j + 2 * (k + 3 * l));
212  } else {
213  patch_loc = l + 3 * (k + 3 * (j + 2 * i));
214  }
215  for (int x = 0; x < 2; ++x) {
216  for (int y = 0; y < 3; ++y) {
217  for (int z = 0; z < 5; ++z) {
218  if (DataLayout == ColMajor) {
219  VERIFY_IS_EQUAL(tensor(i, j + x, k + y, l + z), threed_patch(0, x, y, z, patch_loc));
220  } else {
221  VERIFY_IS_EQUAL(tensor(i, j + x, k + y, l + z), threed_patch(patch_loc, 0, x, y, z));
222  }
223  }
224  }
225  }
226  }
227  }
228  }
229  }
230  sycl_device.deallocate(gpu_data_tensor);
231  sycl_device.deallocate(gpu_data_no_patch);
232  sycl_device.deallocate(gpu_data_single_patch);
233  sycl_device.deallocate(gpu_data_twod_patch);
234  sycl_device.deallocate(gpu_data_threed_patch);
235 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
A tensor expression mapping an existing array of data.
Definition: TensorMap.h:33
The tensor class.
Definition: Tensor.h:68
static const int DataLayout
Definition: cxx11_tensor_image_patch_sycl.cpp:24
@ ColMajor
Definition: Constants.h:318
Scalar * y
Definition: level1_cplx_impl.h:128
char char char int int * k
Definition: level2_impl.h:374
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367
std::array< T, N > array
Definition: EmulateArray.h:231
list x
Definition: plotDoE.py:28
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References Eigen::ColMajor, Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::data(), DataLayout, Eigen::TensorBase< Derived, AccessLevel >::device(), Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::dimension(), i, j, k, Eigen::TensorBase< Derived, AccessLevel >::setRandom(), Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::size(), VERIFY_IS_EQUAL, plotDoE::x, and y.