cxx11_tensor_morphing_sycl.cpp File Reference
#include "main.h"
#include <unsupported/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_reshape (const Eigen::SyclDevice &sycl_device)
 
template<typename DataType , int DataLayout, typename IndexType >
static void test_reshape_as_lvalue (const Eigen::SyclDevice &sycl_device)
 
template<typename DataType , int DataLayout, typename IndexType >
static void test_simple_slice (const Eigen::SyclDevice &sycl_device)
 
template<typename DataType , int DataLayout, typename IndexType >
static void test_strided_slice_as_rhs_sycl (const Eigen::SyclDevice &sycl_device)
 
template<typename DataType , int DataLayout, typename IndexType >
static void test_strided_slice_write_sycl (const Eigen::SyclDevice &sycl_device)
 
template<typename OutIndex , typename DSizes >
Eigen::array< OutIndex, DSizes::count > To32BitDims (const DSizes &in)
 
template<class DataType , int DataLayout, typename IndexType , typename ConvertedIndexType >
int run_eigen (const SyclDevice &sycl_device)
 
template<typename DataType , typename dev_Selector >
void sycl_morphing_test_per_device (dev_Selector s)
 
 EIGEN_DECLARE_TEST (cxx11_tensor_morphing_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_morphing_sycl  )
366  {
367  for (const auto& device : Eigen::get_sycl_supported_devices()) {
368  CALL_SUBTEST(sycl_morphing_test_per_device<half>(device));
369  CALL_SUBTEST(sycl_morphing_test_per_device<float>(device));
370  }
371 }
#define CALL_SUBTEST(FUNC)
Definition: main.h:382

References CALL_SUBTEST.

◆ run_eigen()

template<class DataType , int DataLayout, typename IndexType , typename ConvertedIndexType >
int run_eigen ( const SyclDevice &  sycl_device)
301  {
304  using TensorMI64 = TensorMap<TensorI64>;
305  using TensorMI32 = TensorMap<TensorI32>;
306  Eigen::array<IndexType, 5> tensor_range{{4, 1, 1, 1, 6}};
307  Eigen::array<IndexType, 5> slice_range{{4, 1, 1, 1, 3}};
308 
309  TensorI64 out_tensor_gpu(tensor_range);
310  TensorI64 out_tensor_cpu(tensor_range);
311  out_tensor_cpu.setRandom();
312 
313  TensorI64 sub_tensor(slice_range);
314  sub_tensor.setRandom();
315 
316  DataType* out_gpu_data = static_cast<DataType*>(sycl_device.allocate(out_tensor_cpu.size() * sizeof(DataType)));
317  DataType* sub_gpu_data = static_cast<DataType*>(sycl_device.allocate(sub_tensor.size() * sizeof(DataType)));
318  TensorMI64 out_gpu(out_gpu_data, tensor_range);
319  TensorMI64 sub_gpu(sub_gpu_data, slice_range);
320 
321  sycl_device.memcpyHostToDevice(out_gpu_data, out_tensor_cpu.data(), out_tensor_cpu.size() * sizeof(DataType));
322  sycl_device.memcpyHostToDevice(sub_gpu_data, sub_tensor.data(), sub_tensor.size() * sizeof(DataType));
323 
324  Eigen::array<ConvertedIndexType, 5> slice_offset_32{{0, 0, 0, 0, 3}};
325  Eigen::array<ConvertedIndexType, 5> slice_range_32{{4, 1, 1, 1, 3}};
326  TensorMI32 out_cpu_32(out_tensor_cpu.data(), To32BitDims<ConvertedIndexType>(out_tensor_cpu.dimensions()));
327  TensorMI32 sub_cpu_32(sub_tensor.data(), To32BitDims<ConvertedIndexType>(sub_tensor.dimensions()));
328  TensorMI32 out_gpu_32(out_gpu.data(), To32BitDims<ConvertedIndexType>(out_gpu.dimensions()));
329  TensorMI32 sub_gpu_32(sub_gpu.data(), To32BitDims<ConvertedIndexType>(sub_gpu.dimensions()));
330 
331  out_gpu_32.slice(slice_offset_32, slice_range_32).device(sycl_device) = sub_gpu_32;
332 
333  out_cpu_32.slice(slice_offset_32, slice_range_32) = sub_cpu_32;
334 
335  sycl_device.memcpyDeviceToHost(out_tensor_gpu.data(), out_gpu_data, out_tensor_cpu.size() * sizeof(DataType));
336  int has_err = 0;
337  for (IndexType i = 0; i < out_tensor_cpu.size(); ++i) {
338  auto exp = out_tensor_cpu(i);
339  auto val = out_tensor_gpu(i);
340  if (val != exp) {
341  std::cout << "#" << i << " got " << val << " but expected " << exp << std::endl;
342  has_err = 1;
343  }
344  }
345  sycl_device.deallocate(out_gpu_data);
346  sycl_device.deallocate(sub_gpu_data);
347  return has_err;
348 }
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
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 exp(const bfloat16 &a)
Definition: BFloat16.h:615
std::array< T, N > array
Definition: EmulateArray.h:231
val
Definition: calibrate.py:119

References Eigen::bfloat16_impl::exp(), i, and calibrate::val.

◆ sycl_morphing_test_per_device()

template<typename DataType , typename dev_Selector >
void sycl_morphing_test_per_device ( dev_Selector  s)
351  {
352  QueueInterface queueInterface(s);
353  auto sycl_device = Eigen::SyclDevice(&queueInterface);
354  test_simple_slice<DataType, RowMajor, int64_t>(sycl_device);
355  test_simple_slice<DataType, ColMajor, int64_t>(sycl_device);
356  test_simple_reshape<DataType, RowMajor, int64_t>(sycl_device);
357  test_simple_reshape<DataType, ColMajor, int64_t>(sycl_device);
358  test_reshape_as_lvalue<DataType, RowMajor, int64_t>(sycl_device);
359  test_reshape_as_lvalue<DataType, ColMajor, int64_t>(sycl_device);
360  test_strided_slice_write_sycl<DataType, ColMajor, int64_t>(sycl_device);
361  test_strided_slice_write_sycl<DataType, RowMajor, int64_t>(sycl_device);
362  test_strided_slice_as_rhs_sycl<DataType, ColMajor, int64_t>(sycl_device);
363  test_strided_slice_as_rhs_sycl<DataType, RowMajor, int64_t>(sycl_device);
364  run_eigen<float, RowMajor, long, int>(sycl_device);
365 }
RealScalar s
Definition: level1_cplx_impl.h:130

References s.

◆ test_reshape_as_lvalue()

template<typename DataType , int DataLayout, typename IndexType >
static void test_reshape_as_lvalue ( const Eigen::SyclDevice &  sycl_device)
static

ColMajor

RowMajor

85  {
88  typename Tensor<DataType, 5, DataLayout, IndexType>::Dimensions dim3(2, 3, 1, 7, 1);
92 
93  tensor.setRandom();
94 
95  DataType* gpu_data1 = static_cast<DataType*>(sycl_device.allocate(tensor.size() * sizeof(DataType)));
96  DataType* gpu_data2 = static_cast<DataType*>(sycl_device.allocate(tensor2d.size() * sizeof(DataType)));
97  DataType* gpu_data3 = static_cast<DataType*>(sycl_device.allocate(tensor5d.size() * sizeof(DataType)));
98 
102 
103  sycl_device.memcpyHostToDevice(gpu_data1, tensor.data(), (tensor.size()) * sizeof(DataType));
104 
105  gpu2.reshape(dim1).device(sycl_device) = gpu1;
106  sycl_device.memcpyDeviceToHost(tensor2d.data(), gpu_data2, (tensor2d.size()) * sizeof(DataType));
107 
108  gpu3.reshape(dim1).device(sycl_device) = gpu1;
109  sycl_device.memcpyDeviceToHost(tensor5d.data(), gpu_data3, (tensor5d.size()) * sizeof(DataType));
110 
111  for (IndexType i = 0; i < 2; ++i) {
112  for (IndexType j = 0; j < 3; ++j) {
113  for (IndexType k = 0; k < 7; ++k) {
114  VERIFY_IS_EQUAL(tensor5d(i, j, 0, k, 0), tensor(i, j, k));
115  if (static_cast<int>(DataLayout) == static_cast<int>(ColMajor)) {
116  VERIFY_IS_EQUAL(tensor2d(i + 2 * j, k), tensor(i, j, k));
117  } else {
118  VERIFY_IS_EQUAL(tensor2d(i * 3 + j, k), tensor(i, j, k));
119  }
120  }
121  }
122  }
123  sycl_device.deallocate(gpu_data1);
124  sycl_device.deallocate(gpu_data2);
125  sycl_device.deallocate(gpu_data3);
126 }
static const int DataLayout
Definition: cxx11_tensor_image_patch_sycl.cpp:24
@ ColMajor
Definition: Constants.h:318
char char char int int * k
Definition: level2_impl.h:374
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367
Definition: TensorDimensions.h:161
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

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

◆ test_simple_reshape()

template<typename DataType , int DataLayout, typename IndexType >
static void test_simple_reshape ( const Eigen::SyclDevice &  sycl_device)
static

ColMajor

ColMajor

ColMajor

RowMajor

RowMajor

30  {
31  typename Tensor<DataType, 5, DataLayout, IndexType>::Dimensions dim1(2, 3, 1, 7, 1);
35 
40 
41  tensor1.setRandom();
42 
43  DataType* gpu_data1 = static_cast<DataType*>(sycl_device.allocate(tensor1.size() * sizeof(DataType)));
44  DataType* gpu_data2 = static_cast<DataType*>(sycl_device.allocate(tensor2.size() * sizeof(DataType)));
45  DataType* gpu_data3 = static_cast<DataType*>(sycl_device.allocate(tensor3.size() * sizeof(DataType)));
46  DataType* gpu_data4 = static_cast<DataType*>(sycl_device.allocate(tensor4.size() * sizeof(DataType)));
47 
52 
53  sycl_device.memcpyHostToDevice(gpu_data1, tensor1.data(), (tensor1.size()) * sizeof(DataType));
54 
55  gpu2.device(sycl_device) = gpu1.reshape(dim2);
56  sycl_device.memcpyDeviceToHost(tensor2.data(), gpu_data2, (tensor1.size()) * sizeof(DataType));
57 
58  gpu3.device(sycl_device) = gpu1.reshape(dim3);
59  sycl_device.memcpyDeviceToHost(tensor3.data(), gpu_data3, (tensor3.size()) * sizeof(DataType));
60 
61  gpu4.device(sycl_device) = gpu1.reshape(dim2).reshape(dim4);
62  sycl_device.memcpyDeviceToHost(tensor4.data(), gpu_data4, (tensor4.size()) * sizeof(DataType));
63  for (IndexType i = 0; i < 2; ++i) {
64  for (IndexType j = 0; j < 3; ++j) {
65  for (IndexType k = 0; k < 7; ++k) {
66  VERIFY_IS_EQUAL(tensor1(i, j, 0, k, 0), tensor2(i, j, k));
67  if (static_cast<int>(DataLayout) == static_cast<int>(ColMajor)) {
68  VERIFY_IS_EQUAL(tensor1(i, j, 0, k, 0), tensor3(i + 2 * j, k));
69  VERIFY_IS_EQUAL(tensor1(i, j, 0, k, 0), tensor4(i, j + 3 * k));
70  } else {
71  // VERIFY_IS_EQUAL(tensor1(i,j,0,k,0), tensor2(i,j,k)); /// RowMajor
72  VERIFY_IS_EQUAL(tensor1(i, j, 0, k, 0), tensor4(i, j * 7 + k));
73  VERIFY_IS_EQUAL(tensor1(i, j, 0, k, 0), tensor3(i * 3 + j, k));
74  }
75  }
76  }
77  }
78  sycl_device.deallocate(gpu_data1);
79  sycl_device.deallocate(gpu_data2);
80  sycl_device.deallocate(gpu_data3);
81  sycl_device.deallocate(gpu_data4);
82 }

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

◆ test_simple_slice()

template<typename DataType , int DataLayout, typename IndexType >
static void test_simple_slice ( const Eigen::SyclDevice &  sycl_device)
static
129  {
130  IndexType sizeDim1 = 2;
131  IndexType sizeDim2 = 3;
132  IndexType sizeDim3 = 5;
133  IndexType sizeDim4 = 7;
134  IndexType sizeDim5 = 11;
135  array<IndexType, 5> tensorRange = {{sizeDim1, sizeDim2, sizeDim3, sizeDim4, sizeDim5}};
136  Tensor<DataType, 5, DataLayout, IndexType> tensor(tensorRange);
137  tensor.setRandom();
138  array<IndexType, 5> slice1_range = {{1, 1, 1, 1, 1}};
139  Tensor<DataType, 5, DataLayout, IndexType> slice1(slice1_range);
140 
141  DataType* gpu_data1 = static_cast<DataType*>(sycl_device.allocate(tensor.size() * sizeof(DataType)));
142  DataType* gpu_data2 = static_cast<DataType*>(sycl_device.allocate(slice1.size() * sizeof(DataType)));
143  TensorMap<Tensor<DataType, 5, DataLayout, IndexType>> gpu1(gpu_data1, tensorRange);
144  TensorMap<Tensor<DataType, 5, DataLayout, IndexType>> gpu2(gpu_data2, slice1_range);
145  Eigen::DSizes<IndexType, 5> indices(1, 2, 3, 4, 5);
146  Eigen::DSizes<IndexType, 5> sizes(1, 1, 1, 1, 1);
147  sycl_device.memcpyHostToDevice(gpu_data1, tensor.data(), (tensor.size()) * sizeof(DataType));
148  gpu2.device(sycl_device) = gpu1.slice(indices, sizes);
149  sycl_device.memcpyDeviceToHost(slice1.data(), gpu_data2, (slice1.size()) * sizeof(DataType));
150  VERIFY_IS_EQUAL(slice1(0, 0, 0, 0, 0), tensor(1, 2, 3, 4, 5));
151 
152  array<IndexType, 5> slice2_range = {{1, 1, 2, 2, 3}};
153  Tensor<DataType, 5, DataLayout, IndexType> slice2(slice2_range);
154  DataType* gpu_data3 = static_cast<DataType*>(sycl_device.allocate(slice2.size() * sizeof(DataType)));
155  TensorMap<Tensor<DataType, 5, DataLayout, IndexType>> gpu3(gpu_data3, slice2_range);
156  Eigen::DSizes<IndexType, 5> indices2(1, 1, 3, 4, 5);
157  Eigen::DSizes<IndexType, 5> sizes2(1, 1, 2, 2, 3);
158  gpu3.device(sycl_device) = gpu1.slice(indices2, sizes2);
159  sycl_device.memcpyDeviceToHost(slice2.data(), gpu_data3, (slice2.size()) * sizeof(DataType));
160  for (IndexType i = 0; i < 2; ++i) {
161  for (IndexType j = 0; j < 2; ++j) {
162  for (IndexType k = 0; k < 3; ++k) {
163  VERIFY_IS_EQUAL(slice2(0, 0, i, j, k), tensor(1, 1, 3 + i, 4 + j, 5 + k));
164  }
165  }
166  }
167  sycl_device.deallocate(gpu_data1);
168  sycl_device.deallocate(gpu_data2);
169  sycl_device.deallocate(gpu_data3);
170 }
std::vector< Array2i > sizes
Definition: dense_solvers.cpp:12

References Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::data(), Eigen::TensorBase< Derived, AccessLevel >::device(), i, j, k, Eigen::TensorBase< Derived, AccessLevel >::setRandom(), Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::size(), sizes, Eigen::TensorBase< Derived, AccessLevel >::slice(), and VERIFY_IS_EQUAL.

◆ test_strided_slice_as_rhs_sycl()

template<typename DataType , int DataLayout, typename IndexType >
static void test_strided_slice_as_rhs_sycl ( const Eigen::SyclDevice &  sycl_device)
static
173  {
174  IndexType sizeDim1 = 2;
175  IndexType sizeDim2 = 3;
176  IndexType sizeDim3 = 5;
177  IndexType sizeDim4 = 7;
178  IndexType sizeDim5 = 11;
179  typedef Eigen::DSizes<IndexType, 5> Index5;
180  Index5 strides(1L, 1L, 1L, 1L, 1L);
181  Index5 indicesStart(1L, 2L, 3L, 4L, 5L);
182  Index5 indicesStop(2L, 3L, 4L, 5L, 6L);
183  Index5 lengths(1L, 1L, 1L, 1L, 1L);
184 
185  array<IndexType, 5> tensorRange = {{sizeDim1, sizeDim2, sizeDim3, sizeDim4, sizeDim5}};
186  Tensor<DataType, 5, DataLayout, IndexType> tensor(tensorRange);
187  tensor.setRandom();
188 
189  array<IndexType, 5> slice1_range = {{1, 1, 1, 1, 1}};
190  Tensor<DataType, 5, DataLayout, IndexType> slice1(slice1_range);
191  Tensor<DataType, 5, DataLayout, IndexType> slice_stride1(slice1_range);
192 
193  DataType* gpu_data1 = static_cast<DataType*>(sycl_device.allocate(tensor.size() * sizeof(DataType)));
194  DataType* gpu_data2 = static_cast<DataType*>(sycl_device.allocate(slice1.size() * sizeof(DataType)));
195  DataType* gpu_data_stride2 = static_cast<DataType*>(sycl_device.allocate(slice_stride1.size() * sizeof(DataType)));
196 
197  TensorMap<Tensor<DataType, 5, DataLayout, IndexType>> gpu1(gpu_data1, tensorRange);
198  TensorMap<Tensor<DataType, 5, DataLayout, IndexType>> gpu2(gpu_data2, slice1_range);
199  TensorMap<Tensor<DataType, 5, DataLayout, IndexType>> gpu_stride2(gpu_data_stride2, slice1_range);
200 
201  Eigen::DSizes<IndexType, 5> indices(1, 2, 3, 4, 5);
202  Eigen::DSizes<IndexType, 5> sizes(1, 1, 1, 1, 1);
203  sycl_device.memcpyHostToDevice(gpu_data1, tensor.data(), (tensor.size()) * sizeof(DataType));
204  gpu2.device(sycl_device) = gpu1.slice(indices, sizes);
205  sycl_device.memcpyDeviceToHost(slice1.data(), gpu_data2, (slice1.size()) * sizeof(DataType));
206 
207  gpu_stride2.device(sycl_device) = gpu1.stridedSlice(indicesStart, indicesStop, strides);
208  sycl_device.memcpyDeviceToHost(slice_stride1.data(), gpu_data_stride2, (slice_stride1.size()) * sizeof(DataType));
209 
210  VERIFY_IS_EQUAL(slice1(0, 0, 0, 0, 0), tensor(1, 2, 3, 4, 5));
211  VERIFY_IS_EQUAL(slice_stride1(0, 0, 0, 0, 0), tensor(1, 2, 3, 4, 5));
212 
213  array<IndexType, 5> slice2_range = {{1, 1, 2, 2, 3}};
214  Tensor<DataType, 5, DataLayout, IndexType> slice2(slice2_range);
215  Tensor<DataType, 5, DataLayout, IndexType> strideSlice2(slice2_range);
216 
217  DataType* gpu_data3 = static_cast<DataType*>(sycl_device.allocate(slice2.size() * sizeof(DataType)));
218  DataType* gpu_data_stride3 = static_cast<DataType*>(sycl_device.allocate(strideSlice2.size() * sizeof(DataType)));
219  TensorMap<Tensor<DataType, 5, DataLayout, IndexType>> gpu3(gpu_data3, slice2_range);
220  TensorMap<Tensor<DataType, 5, DataLayout, IndexType>> gpu_stride3(gpu_data_stride3, slice2_range);
221  Eigen::DSizes<IndexType, 5> indices2(1, 1, 3, 4, 5);
222  Eigen::DSizes<IndexType, 5> sizes2(1, 1, 2, 2, 3);
223  Index5 strides2(1L, 1L, 1L, 1L, 1L);
224  Index5 indicesStart2(1L, 1L, 3L, 4L, 5L);
225  Index5 indicesStop2(2L, 2L, 5L, 6L, 8L);
226 
227  gpu3.device(sycl_device) = gpu1.slice(indices2, sizes2);
228  sycl_device.memcpyDeviceToHost(slice2.data(), gpu_data3, (slice2.size()) * sizeof(DataType));
229 
230  gpu_stride3.device(sycl_device) = gpu1.stridedSlice(indicesStart2, indicesStop2, strides2);
231  sycl_device.memcpyDeviceToHost(strideSlice2.data(), gpu_data_stride3, (strideSlice2.size()) * sizeof(DataType));
232 
233  for (IndexType i = 0; i < 2; ++i) {
234  for (IndexType j = 0; j < 2; ++j) {
235  for (IndexType k = 0; k < 3; ++k) {
236  VERIFY_IS_EQUAL(slice2(0, 0, i, j, k), tensor(1, 1, 3 + i, 4 + j, 5 + k));
237  VERIFY_IS_EQUAL(strideSlice2(0, 0, i, j, k), tensor(1, 1, 3 + i, 4 + j, 5 + k));
238  }
239  }
240  }
241  sycl_device.deallocate(gpu_data1);
242  sycl_device.deallocate(gpu_data2);
243  sycl_device.deallocate(gpu_data3);
244 }
EIGEN_ALWAYS_INLINE DSizes< IndexType, NumDims > strides(const DSizes< IndexType, NumDims > &dimensions)
Definition: TensorBlock.h:29

References Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::data(), Eigen::TensorBase< Derived, AccessLevel >::device(), i, j, k, Eigen::TensorBase< Derived, AccessLevel >::setRandom(), Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::size(), sizes, Eigen::TensorBase< Derived, AccessLevel >::slice(), Eigen::TensorBase< Derived, AccessLevel >::stridedSlice(), Eigen::internal::strides(), and VERIFY_IS_EQUAL.

◆ test_strided_slice_write_sycl()

template<typename DataType , int DataLayout, typename IndexType >
static void test_strided_slice_write_sycl ( const Eigen::SyclDevice &  sycl_device)
static
247  {
249  typedef Eigen::DSizes<IndexType, 2> Index2;
250  IndexType sizeDim1 = 7L;
251  IndexType sizeDim2 = 11L;
252  array<IndexType, 2> tensorRange = {{sizeDim1, sizeDim2}};
253  Tensor<DataType, 2, DataLayout, IndexType> tensor(tensorRange), tensor2(tensorRange);
254  IndexType sliceDim1 = 2;
255  IndexType sliceDim2 = 3;
256  array<IndexType, 2> sliceRange = {{sliceDim1, sliceDim2}};
257  Tensor2f slice(sliceRange);
258  Index2 strides(1L, 1L);
259  Index2 indicesStart(3L, 4L);
260  Index2 indicesStop(5L, 7L);
261  Index2 lengths(2L, 3L);
262 
263  DataType* gpu_data1 = static_cast<DataType*>(sycl_device.allocate(tensor.size() * sizeof(DataType)));
264  DataType* gpu_data2 = static_cast<DataType*>(sycl_device.allocate(tensor2.size() * sizeof(DataType)));
265  DataType* gpu_data3 = static_cast<DataType*>(sycl_device.allocate(slice.size() * sizeof(DataType)));
266  TensorMap<Tensor<DataType, 2, DataLayout, IndexType>> gpu1(gpu_data1, tensorRange);
267  TensorMap<Tensor<DataType, 2, DataLayout, IndexType>> gpu2(gpu_data2, tensorRange);
268  TensorMap<Tensor<DataType, 2, DataLayout, IndexType>> gpu3(gpu_data3, sliceRange);
269 
270  tensor.setRandom();
271  sycl_device.memcpyHostToDevice(gpu_data1, tensor.data(), (tensor.size()) * sizeof(DataType));
272  gpu2.device(sycl_device) = gpu1;
273 
274  slice.setRandom();
275  sycl_device.memcpyHostToDevice(gpu_data3, slice.data(), (slice.size()) * sizeof(DataType));
276 
277  gpu1.slice(indicesStart, lengths).device(sycl_device) = gpu3;
278  gpu2.stridedSlice(indicesStart, indicesStop, strides).device(sycl_device) = gpu3;
279  sycl_device.memcpyDeviceToHost(tensor.data(), gpu_data1, (tensor.size()) * sizeof(DataType));
280  sycl_device.memcpyDeviceToHost(tensor2.data(), gpu_data2, (tensor2.size()) * sizeof(DataType));
281 
282  for (IndexType i = 0; i < sizeDim1; i++)
283  for (IndexType j = 0; j < sizeDim2; j++) {
284  VERIFY_IS_EQUAL(tensor(i, j), tensor2(i, j));
285  }
286  sycl_device.deallocate(gpu_data1);
287  sycl_device.deallocate(gpu_data2);
288  sycl_device.deallocate(gpu_data3);
289 }

References Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::data(), Eigen::TensorBase< Derived, AccessLevel >::device(), i, j, Eigen::TensorBase< Derived, AccessLevel >::setRandom(), Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::size(), Eigen::TensorBase< Derived, AccessLevel >::slice(), Eigen::TensorBase< Derived, AccessLevel >::stridedSlice(), Eigen::internal::strides(), and VERIFY_IS_EQUAL.

◆ To32BitDims()

template<typename OutIndex , typename DSizes >
Eigen::array<OutIndex, DSizes::count> To32BitDims ( const DSizes in)
292  {
294  for (int i = 0; i < DSizes::count; ++i) {
295  out[i] = in[i];
296  }
297  return out;
298 }
std::ofstream out("Result.txt")

References i, and out().