cxx11_tensor_inflation_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 >
void test_simple_inflation_sycl (const Eigen::SyclDevice &sycl_device)
 
template<typename DataType , typename dev_Selector >
void sycl_inflation_test_per_device (dev_Selector s)
 
 EIGEN_DECLARE_TEST (cxx11_tensor_inflation_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_inflation_sycl  )
125  {
126  for (const auto& device : Eigen::get_sycl_supported_devices()) {
127  CALL_SUBTEST(sycl_inflation_test_per_device<half>(device));
128  CALL_SUBTEST(sycl_inflation_test_per_device<float>(device));
129  }
130 }
#define CALL_SUBTEST(FUNC)
Definition: main.h:382

References CALL_SUBTEST.

◆ sycl_inflation_test_per_device()

template<typename DataType , typename dev_Selector >
void sycl_inflation_test_per_device ( dev_Selector  s)
119  {
120  QueueInterface queueInterface(s);
121  auto sycl_device = Eigen::SyclDevice(&queueInterface);
122  test_simple_inflation_sycl<DataType, RowMajor, int64_t>(sycl_device);
123  test_simple_inflation_sycl<DataType, ColMajor, int64_t>(sycl_device);
124 }
RealScalar s
Definition: level1_cplx_impl.h:130

References s.

◆ test_simple_inflation_sycl()

template<typename DataType , int DataLayout, typename IndexType >
void test_simple_inflation_sycl ( const Eigen::SyclDevice &  sycl_device)
33  {
34  IndexType sizeDim1 = 2;
35  IndexType sizeDim2 = 3;
36  IndexType sizeDim3 = 5;
37  IndexType sizeDim4 = 7;
38  array<IndexType, 4> tensorRange = {{sizeDim1, sizeDim2, sizeDim3, sizeDim4}};
40  Tensor<DataType, 4, DataLayout, IndexType> no_stride(tensorRange);
41  tensor.setRandom();
42 
44  strides[0] = 1;
45  strides[1] = 1;
46  strides[2] = 1;
47  strides[3] = 1;
48 
49  const size_t tensorBuffSize = tensor.size() * sizeof(DataType);
50  DataType* gpu_data_tensor = static_cast<DataType*>(sycl_device.allocate(tensorBuffSize));
51  DataType* gpu_data_no_stride = static_cast<DataType*>(sycl_device.allocate(tensorBuffSize));
52 
53  TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_tensor(gpu_data_tensor, tensorRange);
54  TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_no_stride(gpu_data_no_stride, tensorRange);
55 
56  sycl_device.memcpyHostToDevice(gpu_data_tensor, tensor.data(), tensorBuffSize);
57  gpu_no_stride.device(sycl_device) = gpu_tensor.inflate(strides);
58  sycl_device.memcpyDeviceToHost(no_stride.data(), gpu_data_no_stride, tensorBuffSize);
59 
60  VERIFY_IS_EQUAL(no_stride.dimension(0), sizeDim1);
61  VERIFY_IS_EQUAL(no_stride.dimension(1), sizeDim2);
62  VERIFY_IS_EQUAL(no_stride.dimension(2), sizeDim3);
63  VERIFY_IS_EQUAL(no_stride.dimension(3), sizeDim4);
64 
65  for (IndexType i = 0; i < 2; ++i) {
66  for (IndexType j = 0; j < 3; ++j) {
67  for (IndexType k = 0; k < 5; ++k) {
68  for (IndexType l = 0; l < 7; ++l) {
69  VERIFY_IS_EQUAL(tensor(i, j, k, l), no_stride(i, j, k, l));
70  }
71  }
72  }
73  }
74 
75  strides[0] = 2;
76  strides[1] = 4;
77  strides[2] = 2;
78  strides[3] = 3;
79 
80  IndexType inflatedSizeDim1 = 3;
81  IndexType inflatedSizeDim2 = 9;
82  IndexType inflatedSizeDim3 = 9;
83  IndexType inflatedSizeDim4 = 19;
84  array<IndexType, 4> inflatedTensorRange = {{inflatedSizeDim1, inflatedSizeDim2, inflatedSizeDim3, inflatedSizeDim4}};
85 
86  Tensor<DataType, 4, DataLayout, IndexType> inflated(inflatedTensorRange);
87 
88  const size_t inflatedTensorBuffSize = inflated.size() * sizeof(DataType);
89  DataType* gpu_data_inflated = static_cast<DataType*>(sycl_device.allocate(inflatedTensorBuffSize));
90  TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_inflated(gpu_data_inflated, inflatedTensorRange);
91  gpu_inflated.device(sycl_device) = gpu_tensor.inflate(strides);
92  sycl_device.memcpyDeviceToHost(inflated.data(), gpu_data_inflated, inflatedTensorBuffSize);
93 
94  VERIFY_IS_EQUAL(inflated.dimension(0), inflatedSizeDim1);
95  VERIFY_IS_EQUAL(inflated.dimension(1), inflatedSizeDim2);
96  VERIFY_IS_EQUAL(inflated.dimension(2), inflatedSizeDim3);
97  VERIFY_IS_EQUAL(inflated.dimension(3), inflatedSizeDim4);
98 
99  for (IndexType i = 0; i < inflatedSizeDim1; ++i) {
100  for (IndexType j = 0; j < inflatedSizeDim2; ++j) {
101  for (IndexType k = 0; k < inflatedSizeDim3; ++k) {
102  for (IndexType l = 0; l < inflatedSizeDim4; ++l) {
103  if (i % strides[0] == 0 && j % strides[1] == 0 && k % strides[2] == 0 && l % strides[3] == 0) {
104  VERIFY_IS_EQUAL(inflated(i, j, k, l),
105  tensor(i / strides[0], j / strides[1], k / strides[2], l / strides[3]));
106  } else {
107  VERIFY_IS_EQUAL(0, inflated(i, j, k, l));
108  }
109  }
110  }
111  }
112  }
113  sycl_device.deallocate(gpu_data_tensor);
114  sycl_device.deallocate(gpu_data_no_stride);
115  sycl_device.deallocate(gpu_data_inflated);
116 }
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
EIGEN_ALWAYS_INLINE DSizes< IndexType, NumDims > strides(const DSizes< IndexType, NumDims > &dimensions)
Definition: TensorBlock.h:29
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::internal::strides(), and VERIFY_IS_EQUAL.