cxx11_tensor_chipping_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_static_chip_sycl (const Eigen::SyclDevice &sycl_device)
 
template<typename DataType , int DataLayout, typename IndexType >
static void test_dynamic_chip_sycl (const Eigen::SyclDevice &sycl_device)
 
template<typename DataType , int DataLayout, typename IndexType >
static void test_chip_in_expr (const Eigen::SyclDevice &sycl_device)
 
template<typename DataType , int DataLayout, typename IndexType >
static void test_chip_as_lvalue_sycl (const Eigen::SyclDevice &sycl_device)
 
template<typename DataType , typename dev_Selector >
void sycl_chipping_test_per_device (dev_Selector s)
 
 EIGEN_DECLARE_TEST (cxx11_tensor_chipping_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_chipping_sycl  )
607  {
608  for (const auto& device : Eigen::get_sycl_supported_devices()) {
609  CALL_SUBTEST(sycl_chipping_test_per_device<float>(device));
610  CALL_SUBTEST(sycl_chipping_test_per_device<half>(device));
611  }
612 }
#define CALL_SUBTEST(FUNC)
Definition: main.h:382

References CALL_SUBTEST.

◆ sycl_chipping_test_per_device()

template<typename DataType , typename dev_Selector >
void sycl_chipping_test_per_device ( dev_Selector  s)
595  {
596  QueueInterface queueInterface(s);
597  auto sycl_device = Eigen::SyclDevice(&queueInterface);
598  /* test_static_chip_sycl<DataType, RowMajor, int64_t>(sycl_device);
599  test_static_chip_sycl<DataType, ColMajor, int64_t>(sycl_device);
600  test_dynamic_chip_sycl<DataType, RowMajor, int64_t>(sycl_device);
601  test_dynamic_chip_sycl<DataType, ColMajor, int64_t>(sycl_device);
602  test_chip_in_expr<DataType, RowMajor, int64_t>(sycl_device);
603  test_chip_in_expr<DataType, ColMajor, int64_t>(sycl_device);*/
604  test_chip_as_lvalue_sycl<DataType, RowMajor, int64_t>(sycl_device);
605  // test_chip_as_lvalue_sycl<DataType, ColMajor, int64_t>(sycl_device);
606 }
RealScalar s
Definition: level1_cplx_impl.h:130

References s.

◆ test_chip_as_lvalue_sycl()

template<typename DataType , int DataLayout, typename IndexType >
static void test_chip_as_lvalue_sycl ( const Eigen::SyclDevice &  sycl_device)
static
394  {
395  IndexType sizeDim1 = 2;
396  IndexType sizeDim2 = 3;
397  IndexType sizeDim3 = 5;
398  IndexType sizeDim4 = 7;
399  IndexType sizeDim5 = 11;
400 
401  array<IndexType, 5> tensorRange = {{sizeDim1, sizeDim2, sizeDim3, sizeDim4, sizeDim5}};
402  array<IndexType, 4> input2TensorRange = {{sizeDim2, sizeDim3, sizeDim4, sizeDim5}};
403 
404  Tensor<DataType, 5, DataLayout, IndexType> tensor(tensorRange);
405  Tensor<DataType, 5, DataLayout, IndexType> input1(tensorRange);
406  Tensor<DataType, 4, DataLayout, IndexType> input2(input2TensorRange);
407  input1.setRandom();
408  input2.setRandom();
409 
410  const size_t tensorBuffSize = tensor.size() * sizeof(DataType);
411  const size_t input2TensorBuffSize = input2.size() * sizeof(DataType);
412  std::cout << tensorBuffSize << " , " << input2TensorBuffSize << std::endl;
413  DataType* gpu_data_tensor = static_cast<DataType*>(sycl_device.allocate(tensorBuffSize));
414  DataType* gpu_data_input1 = static_cast<DataType*>(sycl_device.allocate(tensorBuffSize));
415  DataType* gpu_data_input2 = static_cast<DataType*>(sycl_device.allocate(input2TensorBuffSize));
416 
417  TensorMap<Tensor<DataType, 5, DataLayout, IndexType>> gpu_tensor(gpu_data_tensor, tensorRange);
418  TensorMap<Tensor<DataType, 5, DataLayout, IndexType>> gpu_input1(gpu_data_input1, tensorRange);
419  TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_input2(gpu_data_input2, input2TensorRange);
420 
421  sycl_device.memcpyHostToDevice(gpu_data_input1, input1.data(), tensorBuffSize);
422  gpu_tensor.device(sycl_device) = gpu_input1;
423  sycl_device.memcpyHostToDevice(gpu_data_input2, input2.data(), input2TensorBuffSize);
424  gpu_tensor.template chip<0l>(1l).device(sycl_device) = gpu_input2;
425  sycl_device.memcpyDeviceToHost(tensor.data(), gpu_data_tensor, tensorBuffSize);
426 
427  for (int i = 0; i < sizeDim1; ++i) {
428  for (int j = 0; j < sizeDim2; ++j) {
429  for (int k = 0; k < sizeDim3; ++k) {
430  for (int l = 0; l < sizeDim4; ++l) {
431  for (int m = 0; m < sizeDim5; ++m) {
432  if (i != 1) {
433  VERIFY_IS_EQUAL(tensor(i, j, k, l, m), input1(i, j, k, l, m));
434  } else {
435  VERIFY_IS_EQUAL(tensor(i, j, k, l, m), input2(j, k, l, m));
436  }
437  }
438  }
439  }
440  }
441  }
442 
443  gpu_tensor.device(sycl_device) = gpu_input1;
444  array<IndexType, 4> input3TensorRange = {{sizeDim1, sizeDim3, sizeDim4, sizeDim5}};
445  Tensor<DataType, 4, DataLayout, IndexType> input3(input3TensorRange);
446  input3.setRandom();
447 
448  const size_t input3TensorBuffSize = input3.size() * sizeof(DataType);
449  DataType* gpu_data_input3 = static_cast<DataType*>(sycl_device.allocate(input3TensorBuffSize));
450  TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_input3(gpu_data_input3, input3TensorRange);
451 
452  sycl_device.memcpyHostToDevice(gpu_data_input3, input3.data(), input3TensorBuffSize);
453  gpu_tensor.template chip<1l>(1l).device(sycl_device) = gpu_input3;
454  sycl_device.memcpyDeviceToHost(tensor.data(), gpu_data_tensor, tensorBuffSize);
455 
456  for (int i = 0; i < sizeDim1; ++i) {
457  for (int j = 0; j < sizeDim2; ++j) {
458  for (int k = 0; k < sizeDim3; ++k) {
459  for (int l = 0; l < sizeDim4; ++l) {
460  for (int m = 0; m < sizeDim5; ++m) {
461  if (j != 1) {
462  VERIFY_IS_EQUAL(tensor(i, j, k, l, m), input1(i, j, k, l, m));
463  } else {
464  VERIFY_IS_EQUAL(tensor(i, j, k, l, m), input3(i, k, l, m));
465  }
466  }
467  }
468  }
469  }
470  }
471 
472  gpu_tensor.device(sycl_device) = gpu_input1;
473  array<IndexType, 4> input4TensorRange = {{sizeDim1, sizeDim2, sizeDim4, sizeDim5}};
474  Tensor<DataType, 4, DataLayout, IndexType> input4(input4TensorRange);
475  input4.setRandom();
476 
477  const size_t input4TensorBuffSize = input4.size() * sizeof(DataType);
478  DataType* gpu_data_input4 = static_cast<DataType*>(sycl_device.allocate(input4TensorBuffSize));
479  TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_input4(gpu_data_input4, input4TensorRange);
480 
481  sycl_device.memcpyHostToDevice(gpu_data_input4, input4.data(), input4TensorBuffSize);
482  gpu_tensor.template chip<2l>(3l).device(sycl_device) = gpu_input4;
483  sycl_device.memcpyDeviceToHost(tensor.data(), gpu_data_tensor, tensorBuffSize);
484 
485  for (int i = 0; i < sizeDim1; ++i) {
486  for (int j = 0; j < sizeDim2; ++j) {
487  for (int k = 0; k < sizeDim3; ++k) {
488  for (int l = 0; l < sizeDim4; ++l) {
489  for (int m = 0; m < sizeDim5; ++m) {
490  if (k != 3) {
491  VERIFY_IS_EQUAL(tensor(i, j, k, l, m), input1(i, j, k, l, m));
492  } else {
493  VERIFY_IS_EQUAL(tensor(i, j, k, l, m), input4(i, j, l, m));
494  }
495  }
496  }
497  }
498  }
499  }
500 
501  gpu_tensor.device(sycl_device) = gpu_input1;
502  array<IndexType, 4> input5TensorRange = {{sizeDim1, sizeDim2, sizeDim3, sizeDim5}};
503  Tensor<DataType, 4, DataLayout, IndexType> input5(input5TensorRange);
504  input5.setRandom();
505 
506  const size_t input5TensorBuffSize = input5.size() * sizeof(DataType);
507  DataType* gpu_data_input5 = static_cast<DataType*>(sycl_device.allocate(input5TensorBuffSize));
508  TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_input5(gpu_data_input5, input5TensorRange);
509 
510  sycl_device.memcpyHostToDevice(gpu_data_input5, input5.data(), input5TensorBuffSize);
511  gpu_tensor.template chip<3l>(4l).device(sycl_device) = gpu_input5;
512  sycl_device.memcpyDeviceToHost(tensor.data(), gpu_data_tensor, tensorBuffSize);
513 
514  for (int i = 0; i < sizeDim1; ++i) {
515  for (int j = 0; j < sizeDim2; ++j) {
516  for (int k = 0; k < sizeDim3; ++k) {
517  for (int l = 0; l < sizeDim4; ++l) {
518  for (int m = 0; m < sizeDim5; ++m) {
519  if (l != 4) {
520  VERIFY_IS_EQUAL(tensor(i, j, k, l, m), input1(i, j, k, l, m));
521  } else {
522  VERIFY_IS_EQUAL(tensor(i, j, k, l, m), input5(i, j, k, m));
523  }
524  }
525  }
526  }
527  }
528  }
529  gpu_tensor.device(sycl_device) = gpu_input1;
530  array<IndexType, 4> input6TensorRange = {{sizeDim1, sizeDim2, sizeDim3, sizeDim4}};
531  Tensor<DataType, 4, DataLayout, IndexType> input6(input6TensorRange);
532  input6.setRandom();
533 
534  const size_t input6TensorBuffSize = input6.size() * sizeof(DataType);
535  DataType* gpu_data_input6 = static_cast<DataType*>(sycl_device.allocate(input6TensorBuffSize));
536  TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_input6(gpu_data_input6, input6TensorRange);
537 
538  sycl_device.memcpyHostToDevice(gpu_data_input6, input6.data(), input6TensorBuffSize);
539  gpu_tensor.template chip<4l>(5l).device(sycl_device) = gpu_input6;
540  sycl_device.memcpyDeviceToHost(tensor.data(), gpu_data_tensor, tensorBuffSize);
541 
542  for (int i = 0; i < sizeDim1; ++i) {
543  for (int j = 0; j < sizeDim2; ++j) {
544  for (int k = 0; k < sizeDim3; ++k) {
545  for (int l = 0; l < sizeDim4; ++l) {
546  for (int m = 0; m < sizeDim5; ++m) {
547  if (m != 5) {
548  VERIFY_IS_EQUAL(tensor(i, j, k, l, m), input1(i, j, k, l, m));
549  } else {
550  VERIFY_IS_EQUAL(tensor(i, j, k, l, m), input6(i, j, k, l));
551  }
552  }
553  }
554  }
555  }
556  }
557 
558  gpu_tensor.device(sycl_device) = gpu_input1;
559  Tensor<DataType, 5, DataLayout, IndexType> input7(tensorRange);
560  input7.setRandom();
561 
562  DataType* gpu_data_input7 = static_cast<DataType*>(sycl_device.allocate(tensorBuffSize));
563  TensorMap<Tensor<DataType, 5, DataLayout, IndexType>> gpu_input7(gpu_data_input7, tensorRange);
564 
565  sycl_device.memcpyHostToDevice(gpu_data_input7, input7.data(), tensorBuffSize);
566  gpu_tensor.chip(0l, 0l).device(sycl_device) = gpu_input7.chip(0l, 0l);
567  sycl_device.memcpyDeviceToHost(tensor.data(), gpu_data_tensor, tensorBuffSize);
568 
569  for (int i = 0; i < sizeDim1; ++i) {
570  for (int j = 0; j < sizeDim2; ++j) {
571  for (int k = 0; k < sizeDim3; ++k) {
572  for (int l = 0; l < sizeDim4; ++l) {
573  for (int m = 0; m < sizeDim5; ++m) {
574  if (i != 0) {
575  VERIFY_IS_EQUAL(tensor(i, j, k, l, m), input1(i, j, k, l, m));
576  } else {
577  VERIFY_IS_EQUAL(tensor(i, j, k, l, m), input7(i, j, k, l, m));
578  }
579  }
580  }
581  }
582  }
583  }
584  sycl_device.deallocate(gpu_data_tensor);
585  sycl_device.deallocate(gpu_data_input1);
586  sycl_device.deallocate(gpu_data_input2);
587  sycl_device.deallocate(gpu_data_input3);
588  sycl_device.deallocate(gpu_data_input4);
589  sycl_device.deallocate(gpu_data_input5);
590  sycl_device.deallocate(gpu_data_input6);
591  sycl_device.deallocate(gpu_data_input7);
592 }
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
int * m
Definition: level2_cplx_impl.h:294
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
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

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

◆ test_chip_in_expr()

template<typename DataType , int DataLayout, typename IndexType >
static void test_chip_in_expr ( const Eigen::SyclDevice &  sycl_device)
static
321  {
322  IndexType sizeDim1 = 2;
323  IndexType sizeDim2 = 3;
324  IndexType sizeDim3 = 5;
325  IndexType sizeDim4 = 7;
326  IndexType sizeDim5 = 11;
327 
328  array<IndexType, 5> tensorRange = {{sizeDim1, sizeDim2, sizeDim3, sizeDim4, sizeDim5}};
329  array<IndexType, 4> chip1TensorRange = {{sizeDim2, sizeDim3, sizeDim4, sizeDim5}};
330 
331  Tensor<DataType, 5, DataLayout, IndexType> tensor(tensorRange);
332 
333  Tensor<DataType, 4, DataLayout, IndexType> chip1(chip1TensorRange);
334  Tensor<DataType, 4, DataLayout, IndexType> tensor1(chip1TensorRange);
335  tensor.setRandom();
336  tensor1.setRandom();
337 
338  const size_t tensorBuffSize = tensor.size() * sizeof(DataType);
339  const size_t chip1TensorBuffSize = chip1.size() * sizeof(DataType);
340  DataType* gpu_data_tensor = static_cast<DataType*>(sycl_device.allocate(tensorBuffSize));
341  DataType* gpu_data_chip1 = static_cast<DataType*>(sycl_device.allocate(chip1TensorBuffSize));
342  DataType* gpu_data_tensor1 = static_cast<DataType*>(sycl_device.allocate(chip1TensorBuffSize));
343 
344  TensorMap<Tensor<DataType, 5, DataLayout, IndexType>> gpu_tensor(gpu_data_tensor, tensorRange);
345  TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_chip1(gpu_data_chip1, chip1TensorRange);
346  TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_tensor1(gpu_data_tensor1, chip1TensorRange);
347 
348  sycl_device.memcpyHostToDevice(gpu_data_tensor, tensor.data(), tensorBuffSize);
349  sycl_device.memcpyHostToDevice(gpu_data_tensor1, tensor1.data(), chip1TensorBuffSize);
350  gpu_chip1.device(sycl_device) = gpu_tensor.template chip<0l>(0l) + gpu_tensor1;
351  sycl_device.memcpyDeviceToHost(chip1.data(), gpu_data_chip1, chip1TensorBuffSize);
352 
353  for (int i = 0; i < sizeDim2; ++i) {
354  for (int j = 0; j < sizeDim3; ++j) {
355  for (int k = 0; k < sizeDim4; ++k) {
356  for (int l = 0; l < sizeDim5; ++l) {
357  float expected = tensor(0l, i, j, k, l) + tensor1(i, j, k, l);
358  VERIFY_IS_EQUAL(chip1(i, j, k, l), expected);
359  }
360  }
361  }
362  }
363 
364  array<IndexType, 3> chip2TensorRange = {{sizeDim2, sizeDim4, sizeDim5}};
365  Tensor<DataType, 3, DataLayout, IndexType> tensor2(chip2TensorRange);
366  Tensor<DataType, 3, DataLayout, IndexType> chip2(chip2TensorRange);
367  tensor2.setRandom();
368  const size_t chip2TensorBuffSize = tensor2.size() * sizeof(DataType);
369  DataType* gpu_data_tensor2 = static_cast<DataType*>(sycl_device.allocate(chip2TensorBuffSize));
370  DataType* gpu_data_chip2 = static_cast<DataType*>(sycl_device.allocate(chip2TensorBuffSize));
371  TensorMap<Tensor<DataType, 3, DataLayout, IndexType>> gpu_tensor2(gpu_data_tensor2, chip2TensorRange);
372  TensorMap<Tensor<DataType, 3, DataLayout, IndexType>> gpu_chip2(gpu_data_chip2, chip2TensorRange);
373 
374  sycl_device.memcpyHostToDevice(gpu_data_tensor2, tensor2.data(), chip2TensorBuffSize);
375  gpu_chip2.device(sycl_device) = gpu_tensor.template chip<0l>(0l).template chip<1l>(2l) + gpu_tensor2;
376  sycl_device.memcpyDeviceToHost(chip2.data(), gpu_data_chip2, chip2TensorBuffSize);
377 
378  for (int i = 0; i < sizeDim2; ++i) {
379  for (int j = 0; j < sizeDim4; ++j) {
380  for (int k = 0; k < sizeDim5; ++k) {
381  float expected = tensor(0l, i, 2l, j, k) + tensor2(i, j, k);
382  VERIFY_IS_EQUAL(chip2(i, j, k), expected);
383  }
384  }
385  }
386  sycl_device.deallocate(gpu_data_tensor);
387  sycl_device.deallocate(gpu_data_tensor1);
388  sycl_device.deallocate(gpu_data_chip1);
389  sycl_device.deallocate(gpu_data_tensor2);
390  sycl_device.deallocate(gpu_data_chip2);
391 }

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(), and VERIFY_IS_EQUAL.

◆ test_dynamic_chip_sycl()

template<typename DataType , int DataLayout, typename IndexType >
static void test_dynamic_chip_sycl ( const Eigen::SyclDevice &  sycl_device)
static
175  {
176  IndexType sizeDim1 = 2;
177  IndexType sizeDim2 = 3;
178  IndexType sizeDim3 = 5;
179  IndexType sizeDim4 = 7;
180  IndexType sizeDim5 = 11;
181 
182  array<IndexType, 5> tensorRange = {{sizeDim1, sizeDim2, sizeDim3, sizeDim4, sizeDim5}};
183  array<IndexType, 4> chip1TensorRange = {{sizeDim2, sizeDim3, sizeDim4, sizeDim5}};
184 
185  Tensor<DataType, 5, DataLayout, IndexType> tensor(tensorRange);
186  Tensor<DataType, 4, DataLayout, IndexType> chip1(chip1TensorRange);
187 
188  tensor.setRandom();
189 
190  const size_t tensorBuffSize = tensor.size() * sizeof(DataType);
191  const size_t chip1TensorBuffSize = chip1.size() * sizeof(DataType);
192  DataType* gpu_data_tensor = static_cast<DataType*>(sycl_device.allocate(tensorBuffSize));
193  DataType* gpu_data_chip1 = static_cast<DataType*>(sycl_device.allocate(chip1TensorBuffSize));
194 
195  TensorMap<Tensor<DataType, 5, DataLayout, IndexType>> gpu_tensor(gpu_data_tensor, tensorRange);
196  TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_chip1(gpu_data_chip1, chip1TensorRange);
197 
198  sycl_device.memcpyHostToDevice(gpu_data_tensor, tensor.data(), tensorBuffSize);
199  gpu_chip1.device(sycl_device) = gpu_tensor.chip(1l, 0l);
200  sycl_device.memcpyDeviceToHost(chip1.data(), gpu_data_chip1, chip1TensorBuffSize);
201 
202  VERIFY_IS_EQUAL(chip1.dimension(0), sizeDim2);
203  VERIFY_IS_EQUAL(chip1.dimension(1), sizeDim3);
204  VERIFY_IS_EQUAL(chip1.dimension(2), sizeDim4);
205  VERIFY_IS_EQUAL(chip1.dimension(3), sizeDim5);
206 
207  for (IndexType i = 0; i < sizeDim2; ++i) {
208  for (IndexType j = 0; j < sizeDim3; ++j) {
209  for (IndexType k = 0; k < sizeDim4; ++k) {
210  for (IndexType l = 0; l < sizeDim5; ++l) {
211  VERIFY_IS_EQUAL(chip1(i, j, k, l), tensor(1l, i, j, k, l));
212  }
213  }
214  }
215  }
216 
217  array<IndexType, 4> chip2TensorRange = {{sizeDim1, sizeDim3, sizeDim4, sizeDim5}};
218  Tensor<DataType, 4, DataLayout, IndexType> chip2(chip2TensorRange);
219  const size_t chip2TensorBuffSize = chip2.size() * sizeof(DataType);
220  DataType* gpu_data_chip2 = static_cast<DataType*>(sycl_device.allocate(chip2TensorBuffSize));
221  TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_chip2(gpu_data_chip2, chip2TensorRange);
222 
223  gpu_chip2.device(sycl_device) = gpu_tensor.chip(1l, 1l);
224  sycl_device.memcpyDeviceToHost(chip2.data(), gpu_data_chip2, chip2TensorBuffSize);
225 
226  VERIFY_IS_EQUAL(chip2.dimension(0), sizeDim1);
227  VERIFY_IS_EQUAL(chip2.dimension(1), sizeDim3);
228  VERIFY_IS_EQUAL(chip2.dimension(2), sizeDim4);
229  VERIFY_IS_EQUAL(chip2.dimension(3), sizeDim5);
230 
231  for (IndexType i = 0; i < sizeDim1; ++i) {
232  for (IndexType j = 0; j < sizeDim3; ++j) {
233  for (IndexType k = 0; k < sizeDim4; ++k) {
234  for (IndexType l = 0; l < sizeDim5; ++l) {
235  VERIFY_IS_EQUAL(chip2(i, j, k, l), tensor(i, 1l, j, k, l));
236  }
237  }
238  }
239  }
240 
241  array<IndexType, 4> chip3TensorRange = {{sizeDim1, sizeDim2, sizeDim4, sizeDim5}};
242  Tensor<DataType, 4, DataLayout, IndexType> chip3(chip3TensorRange);
243  const size_t chip3TensorBuffSize = chip3.size() * sizeof(DataType);
244  DataType* gpu_data_chip3 = static_cast<DataType*>(sycl_device.allocate(chip3TensorBuffSize));
245  TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_chip3(gpu_data_chip3, chip3TensorRange);
246 
247  gpu_chip3.device(sycl_device) = gpu_tensor.chip(2l, 2l);
248  sycl_device.memcpyDeviceToHost(chip3.data(), gpu_data_chip3, chip3TensorBuffSize);
249 
250  VERIFY_IS_EQUAL(chip3.dimension(0), sizeDim1);
251  VERIFY_IS_EQUAL(chip3.dimension(1), sizeDim2);
252  VERIFY_IS_EQUAL(chip3.dimension(2), sizeDim4);
253  VERIFY_IS_EQUAL(chip3.dimension(3), sizeDim5);
254 
255  for (IndexType i = 0; i < sizeDim1; ++i) {
256  for (IndexType j = 0; j < sizeDim2; ++j) {
257  for (IndexType k = 0; k < sizeDim4; ++k) {
258  for (IndexType l = 0; l < sizeDim5; ++l) {
259  VERIFY_IS_EQUAL(chip3(i, j, k, l), tensor(i, j, 2l, k, l));
260  }
261  }
262  }
263  }
264 
265  array<IndexType, 4> chip4TensorRange = {{sizeDim1, sizeDim2, sizeDim3, sizeDim5}};
266  Tensor<DataType, 4, DataLayout, IndexType> chip4(chip4TensorRange);
267  const size_t chip4TensorBuffSize = chip4.size() * sizeof(DataType);
268  DataType* gpu_data_chip4 = static_cast<DataType*>(sycl_device.allocate(chip4TensorBuffSize));
269  TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_chip4(gpu_data_chip4, chip4TensorRange);
270 
271  gpu_chip4.device(sycl_device) = gpu_tensor.chip(5l, 3l);
272  sycl_device.memcpyDeviceToHost(chip4.data(), gpu_data_chip4, chip4TensorBuffSize);
273 
274  VERIFY_IS_EQUAL(chip4.dimension(0), sizeDim1);
275  VERIFY_IS_EQUAL(chip4.dimension(1), sizeDim2);
276  VERIFY_IS_EQUAL(chip4.dimension(2), sizeDim3);
277  VERIFY_IS_EQUAL(chip4.dimension(3), sizeDim5);
278 
279  for (IndexType i = 0; i < sizeDim1; ++i) {
280  for (IndexType j = 0; j < sizeDim2; ++j) {
281  for (IndexType k = 0; k < sizeDim3; ++k) {
282  for (IndexType l = 0; l < sizeDim5; ++l) {
283  VERIFY_IS_EQUAL(chip4(i, j, k, l), tensor(i, j, k, 5l, l));
284  }
285  }
286  }
287  }
288 
289  array<IndexType, 4> chip5TensorRange = {{sizeDim1, sizeDim2, sizeDim3, sizeDim4}};
290  Tensor<DataType, 4, DataLayout, IndexType> chip5(chip5TensorRange);
291  const size_t chip5TensorBuffSize = chip5.size() * sizeof(DataType);
292  DataType* gpu_data_chip5 = static_cast<DataType*>(sycl_device.allocate(chip5TensorBuffSize));
293  TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_chip5(gpu_data_chip5, chip5TensorRange);
294 
295  gpu_chip5.device(sycl_device) = gpu_tensor.chip(7l, 4l);
296  sycl_device.memcpyDeviceToHost(chip5.data(), gpu_data_chip5, chip5TensorBuffSize);
297 
298  VERIFY_IS_EQUAL(chip5.dimension(0), sizeDim1);
299  VERIFY_IS_EQUAL(chip5.dimension(1), sizeDim2);
300  VERIFY_IS_EQUAL(chip5.dimension(2), sizeDim3);
301  VERIFY_IS_EQUAL(chip5.dimension(3), sizeDim4);
302 
303  for (IndexType i = 0; i < sizeDim1; ++i) {
304  for (IndexType j = 0; j < sizeDim2; ++j) {
305  for (IndexType k = 0; k < sizeDim3; ++k) {
306  for (IndexType l = 0; l < sizeDim4; ++l) {
307  VERIFY_IS_EQUAL(chip5(i, j, k, l), tensor(i, j, k, l, 7l));
308  }
309  }
310  }
311  }
312  sycl_device.deallocate(gpu_data_tensor);
313  sycl_device.deallocate(gpu_data_chip1);
314  sycl_device.deallocate(gpu_data_chip2);
315  sycl_device.deallocate(gpu_data_chip3);
316  sycl_device.deallocate(gpu_data_chip4);
317  sycl_device.deallocate(gpu_data_chip5);
318 }

References Eigen::TensorBase< Derived, AccessLevel >::chip(), Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::data(), 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(), and VERIFY_IS_EQUAL.

◆ test_static_chip_sycl()

template<typename DataType , int DataLayout, typename IndexType >
static void test_static_chip_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  IndexType sizeDim5 = 11;
34 
35  array<IndexType, 5> tensorRange = {{sizeDim1, sizeDim2, sizeDim3, sizeDim4, sizeDim5}};
36  array<IndexType, 4> chip1TensorRange = {{sizeDim2, sizeDim3, sizeDim4, sizeDim5}};
37 
39  Tensor<DataType, 4, DataLayout, IndexType> chip1(chip1TensorRange);
40 
41  tensor.setRandom();
42 
43  const size_t tensorBuffSize = tensor.size() * sizeof(DataType);
44  const size_t chip1TensorBuffSize = chip1.size() * sizeof(DataType);
45  DataType* gpu_data_tensor = static_cast<DataType*>(sycl_device.allocate(tensorBuffSize));
46  DataType* gpu_data_chip1 = static_cast<DataType*>(sycl_device.allocate(chip1TensorBuffSize));
47 
48  TensorMap<Tensor<DataType, 5, DataLayout, IndexType>> gpu_tensor(gpu_data_tensor, tensorRange);
49  TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_chip1(gpu_data_chip1, chip1TensorRange);
50 
51  sycl_device.memcpyHostToDevice(gpu_data_tensor, tensor.data(), tensorBuffSize);
52  gpu_chip1.device(sycl_device) = gpu_tensor.template chip<0l>(1l);
53  sycl_device.memcpyDeviceToHost(chip1.data(), gpu_data_chip1, chip1TensorBuffSize);
54 
55  VERIFY_IS_EQUAL(chip1.dimension(0), sizeDim2);
56  VERIFY_IS_EQUAL(chip1.dimension(1), sizeDim3);
57  VERIFY_IS_EQUAL(chip1.dimension(2), sizeDim4);
58  VERIFY_IS_EQUAL(chip1.dimension(3), sizeDim5);
59 
60  for (IndexType i = 0; i < sizeDim2; ++i) {
61  for (IndexType j = 0; j < sizeDim3; ++j) {
62  for (IndexType k = 0; k < sizeDim4; ++k) {
63  for (IndexType l = 0; l < sizeDim5; ++l) {
64  VERIFY_IS_EQUAL(chip1(i, j, k, l), tensor(1l, i, j, k, l));
65  }
66  }
67  }
68  }
69 
70  array<IndexType, 4> chip2TensorRange = {{sizeDim1, sizeDim3, sizeDim4, sizeDim5}};
71  Tensor<DataType, 4, DataLayout, IndexType> chip2(chip2TensorRange);
72  const size_t chip2TensorBuffSize = chip2.size() * sizeof(DataType);
73  DataType* gpu_data_chip2 = static_cast<DataType*>(sycl_device.allocate(chip2TensorBuffSize));
74  TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_chip2(gpu_data_chip2, chip2TensorRange);
75 
76  gpu_chip2.device(sycl_device) = gpu_tensor.template chip<1l>(1l);
77  sycl_device.memcpyDeviceToHost(chip2.data(), gpu_data_chip2, chip2TensorBuffSize);
78 
79  VERIFY_IS_EQUAL(chip2.dimension(0), sizeDim1);
80  VERIFY_IS_EQUAL(chip2.dimension(1), sizeDim3);
81  VERIFY_IS_EQUAL(chip2.dimension(2), sizeDim4);
82  VERIFY_IS_EQUAL(chip2.dimension(3), sizeDim5);
83 
84  for (IndexType i = 0; i < sizeDim1; ++i) {
85  for (IndexType j = 0; j < sizeDim3; ++j) {
86  for (IndexType k = 0; k < sizeDim4; ++k) {
87  for (IndexType l = 0; l < sizeDim5; ++l) {
88  VERIFY_IS_EQUAL(chip2(i, j, k, l), tensor(i, 1l, j, k, l));
89  }
90  }
91  }
92  }
93 
94  array<IndexType, 4> chip3TensorRange = {{sizeDim1, sizeDim2, sizeDim4, sizeDim5}};
95  Tensor<DataType, 4, DataLayout, IndexType> chip3(chip3TensorRange);
96  const size_t chip3TensorBuffSize = chip3.size() * sizeof(DataType);
97  DataType* gpu_data_chip3 = static_cast<DataType*>(sycl_device.allocate(chip3TensorBuffSize));
98  TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_chip3(gpu_data_chip3, chip3TensorRange);
99 
100  gpu_chip3.device(sycl_device) = gpu_tensor.template chip<2l>(2l);
101  sycl_device.memcpyDeviceToHost(chip3.data(), gpu_data_chip3, chip3TensorBuffSize);
102 
103  VERIFY_IS_EQUAL(chip3.dimension(0), sizeDim1);
104  VERIFY_IS_EQUAL(chip3.dimension(1), sizeDim2);
105  VERIFY_IS_EQUAL(chip3.dimension(2), sizeDim4);
106  VERIFY_IS_EQUAL(chip3.dimension(3), sizeDim5);
107 
108  for (IndexType i = 0; i < sizeDim1; ++i) {
109  for (IndexType j = 0; j < sizeDim2; ++j) {
110  for (IndexType k = 0; k < sizeDim4; ++k) {
111  for (IndexType l = 0; l < sizeDim5; ++l) {
112  VERIFY_IS_EQUAL(chip3(i, j, k, l), tensor(i, j, 2l, k, l));
113  }
114  }
115  }
116  }
117 
118  array<IndexType, 4> chip4TensorRange = {{sizeDim1, sizeDim2, sizeDim3, sizeDim5}};
119  Tensor<DataType, 4, DataLayout, IndexType> chip4(chip4TensorRange);
120  const size_t chip4TensorBuffSize = chip4.size() * sizeof(DataType);
121  DataType* gpu_data_chip4 = static_cast<DataType*>(sycl_device.allocate(chip4TensorBuffSize));
122  TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_chip4(gpu_data_chip4, chip4TensorRange);
123 
124  gpu_chip4.device(sycl_device) = gpu_tensor.template chip<3l>(5l);
125  sycl_device.memcpyDeviceToHost(chip4.data(), gpu_data_chip4, chip4TensorBuffSize);
126 
127  VERIFY_IS_EQUAL(chip4.dimension(0), sizeDim1);
128  VERIFY_IS_EQUAL(chip4.dimension(1), sizeDim2);
129  VERIFY_IS_EQUAL(chip4.dimension(2), sizeDim3);
130  VERIFY_IS_EQUAL(chip4.dimension(3), sizeDim5);
131 
132  for (IndexType i = 0; i < sizeDim1; ++i) {
133  for (IndexType j = 0; j < sizeDim2; ++j) {
134  for (IndexType k = 0; k < sizeDim3; ++k) {
135  for (IndexType l = 0; l < sizeDim5; ++l) {
136  VERIFY_IS_EQUAL(chip4(i, j, k, l), tensor(i, j, k, 5l, l));
137  }
138  }
139  }
140  }
141 
142  array<IndexType, 4> chip5TensorRange = {{sizeDim1, sizeDim2, sizeDim3, sizeDim4}};
143  Tensor<DataType, 4, DataLayout, IndexType> chip5(chip5TensorRange);
144  const size_t chip5TensorBuffSize = chip5.size() * sizeof(DataType);
145  DataType* gpu_data_chip5 = static_cast<DataType*>(sycl_device.allocate(chip5TensorBuffSize));
146  TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_chip5(gpu_data_chip5, chip5TensorRange);
147 
148  gpu_chip5.device(sycl_device) = gpu_tensor.template chip<4l>(7l);
149  sycl_device.memcpyDeviceToHost(chip5.data(), gpu_data_chip5, chip5TensorBuffSize);
150 
151  VERIFY_IS_EQUAL(chip5.dimension(0), sizeDim1);
152  VERIFY_IS_EQUAL(chip5.dimension(1), sizeDim2);
153  VERIFY_IS_EQUAL(chip5.dimension(2), sizeDim3);
154  VERIFY_IS_EQUAL(chip5.dimension(3), sizeDim4);
155 
156  for (IndexType i = 0; i < sizeDim1; ++i) {
157  for (IndexType j = 0; j < sizeDim2; ++j) {
158  for (IndexType k = 0; k < sizeDim3; ++k) {
159  for (IndexType l = 0; l < sizeDim4; ++l) {
160  VERIFY_IS_EQUAL(chip5(i, j, k, l), tensor(i, j, k, l, 7l));
161  }
162  }
163  }
164  }
165 
166  sycl_device.deallocate(gpu_data_tensor);
167  sycl_device.deallocate(gpu_data_chip1);
168  sycl_device.deallocate(gpu_data_chip2);
169  sycl_device.deallocate(gpu_data_chip3);
170  sycl_device.deallocate(gpu_data_chip4);
171  sycl_device.deallocate(gpu_data_chip5);
172 }

References Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::data(), 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(), and VERIFY_IS_EQUAL.