cxx11_tensor_layout_swap_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 , typename IndexType >
static void test_simple_swap_sycl (const Eigen::SyclDevice &sycl_device)
 
template<typename DataType , typename IndexType >
static void test_swap_as_lvalue_sycl (const Eigen::SyclDevice &sycl_device)
 
template<typename DataType , typename dev_Selector >
void sycl_tensor_layout_swap_test_per_device (dev_Selector s)
 
 EIGEN_DECLARE_TEST (cxx11_tensor_layout_swap_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_layout_swap_sycl  )
115  {
116  for (const auto& device : Eigen::get_sycl_supported_devices()) {
117  CALL_SUBTEST(sycl_tensor_layout_swap_test_per_device<half>(device));
118  CALL_SUBTEST(sycl_tensor_layout_swap_test_per_device<float>(device));
119  }
120 }
#define CALL_SUBTEST(FUNC)
Definition: main.h:382

References CALL_SUBTEST.

◆ sycl_tensor_layout_swap_test_per_device()

template<typename DataType , typename dev_Selector >
void sycl_tensor_layout_swap_test_per_device ( dev_Selector  s)
109  {
110  QueueInterface queueInterface(s);
111  auto sycl_device = Eigen::SyclDevice(&queueInterface);
112  test_simple_swap_sycl<DataType, int64_t>(sycl_device);
113  test_swap_as_lvalue_sycl<DataType, int64_t>(sycl_device);
114 }
RealScalar s
Definition: level1_cplx_impl.h:130

References s.

◆ test_simple_swap_sycl()

template<typename DataType , typename IndexType >
static void test_simple_swap_sycl ( const Eigen::SyclDevice &  sycl_device)
static
28  {
29  IndexType sizeDim1 = 2;
30  IndexType sizeDim2 = 3;
31  IndexType sizeDim3 = 7;
32  array<IndexType, 3> tensorColRange = {{sizeDim1, sizeDim2, sizeDim3}};
33  array<IndexType, 3> tensorRowRange = {{sizeDim3, sizeDim2, sizeDim1}};
34 
35  Tensor<DataType, 3, ColMajor, IndexType> tensor1(tensorColRange);
36  Tensor<DataType, 3, RowMajor, IndexType> tensor2(tensorRowRange);
37  tensor1.setRandom();
38 
39  DataType* gpu_data1 = static_cast<DataType*>(sycl_device.allocate(tensor1.size() * sizeof(DataType)));
40  DataType* gpu_data2 = static_cast<DataType*>(sycl_device.allocate(tensor2.size() * sizeof(DataType)));
41  TensorMap<Tensor<DataType, 3, ColMajor, IndexType>> gpu1(gpu_data1, tensorColRange);
42  TensorMap<Tensor<DataType, 3, RowMajor, IndexType>> gpu2(gpu_data2, tensorRowRange);
43 
44  sycl_device.memcpyHostToDevice(gpu_data1, tensor1.data(), (tensor1.size()) * sizeof(DataType));
45  gpu2.device(sycl_device) = gpu1.swap_layout();
46  sycl_device.memcpyDeviceToHost(tensor2.data(), gpu_data2, (tensor2.size()) * sizeof(DataType));
47 
48  // Tensor<float, 3, ColMajor> tensor(2,3,7);
49  // tensor.setRandom();
50 
51  // Tensor<float, 3, RowMajor> tensor2 = tensor.swap_layout();
52  VERIFY_IS_EQUAL(tensor1.dimension(0), tensor2.dimension(2));
53  VERIFY_IS_EQUAL(tensor1.dimension(1), tensor2.dimension(1));
54  VERIFY_IS_EQUAL(tensor1.dimension(2), tensor2.dimension(0));
55 
56  for (IndexType i = 0; i < 2; ++i) {
57  for (IndexType j = 0; j < 3; ++j) {
58  for (IndexType k = 0; k < 7; ++k) {
59  VERIFY_IS_EQUAL(tensor1(i, j, k), tensor2(k, j, i));
60  }
61  }
62  }
63  sycl_device.deallocate(gpu_data1);
64  sycl_device.deallocate(gpu_data2);
65 }
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
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::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(), Eigen::TensorBase< Derived, AccessLevel >::swap_layout(), and VERIFY_IS_EQUAL.

◆ test_swap_as_lvalue_sycl()

template<typename DataType , typename IndexType >
static void test_swap_as_lvalue_sycl ( const Eigen::SyclDevice &  sycl_device)
static
68  {
69  IndexType sizeDim1 = 2;
70  IndexType sizeDim2 = 3;
71  IndexType sizeDim3 = 7;
72  array<IndexType, 3> tensorColRange = {{sizeDim1, sizeDim2, sizeDim3}};
73  array<IndexType, 3> tensorRowRange = {{sizeDim3, sizeDim2, sizeDim1}};
74 
75  Tensor<DataType, 3, ColMajor, IndexType> tensor1(tensorColRange);
76  Tensor<DataType, 3, RowMajor, IndexType> tensor2(tensorRowRange);
77  tensor1.setRandom();
78 
79  DataType* gpu_data1 = static_cast<DataType*>(sycl_device.allocate(tensor1.size() * sizeof(DataType)));
80  DataType* gpu_data2 = static_cast<DataType*>(sycl_device.allocate(tensor2.size() * sizeof(DataType)));
81  TensorMap<Tensor<DataType, 3, ColMajor, IndexType>> gpu1(gpu_data1, tensorColRange);
82  TensorMap<Tensor<DataType, 3, RowMajor, IndexType>> gpu2(gpu_data2, tensorRowRange);
83 
84  sycl_device.memcpyHostToDevice(gpu_data1, tensor1.data(), (tensor1.size()) * sizeof(DataType));
85  gpu2.swap_layout().device(sycl_device) = gpu1;
86  sycl_device.memcpyDeviceToHost(tensor2.data(), gpu_data2, (tensor2.size()) * sizeof(DataType));
87 
88  // Tensor<float, 3, ColMajor> tensor(2,3,7);
89  // tensor.setRandom();
90 
91  // Tensor<float, 3, RowMajor> tensor2(7,3,2);
92  // tensor2.swap_layout() = tensor;
93  VERIFY_IS_EQUAL(tensor1.dimension(0), tensor2.dimension(2));
94  VERIFY_IS_EQUAL(tensor1.dimension(1), tensor2.dimension(1));
95  VERIFY_IS_EQUAL(tensor1.dimension(2), tensor2.dimension(0));
96 
97  for (IndexType i = 0; i < 2; ++i) {
98  for (IndexType j = 0; j < 3; ++j) {
99  for (IndexType k = 0; k < 7; ++k) {
100  VERIFY_IS_EQUAL(tensor1(i, j, k), tensor2(k, j, i));
101  }
102  }
103  }
104  sycl_device.deallocate(gpu_data1);
105  sycl_device.deallocate(gpu_data2);
106 }

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