cxx11_tensor_padding_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_padding (const Eigen::SyclDevice &sycl_device)
 
template<typename DataType , int DataLayout, typename IndexType >
static void test_padded_expr (const Eigen::SyclDevice &sycl_device)
 
template<typename DataType , typename dev_Selector >
void sycl_padding_test_per_device (dev_Selector s)
 
 EIGEN_DECLARE_TEST (cxx11_tensor_padding_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_padding_sycl  )
143  {
144  for (const auto& device : Eigen::get_sycl_supported_devices()) {
145  CALL_SUBTEST(sycl_padding_test_per_device<half>(device));
146  CALL_SUBTEST(sycl_padding_test_per_device<float>(device));
147  }
148 }
#define CALL_SUBTEST(FUNC)
Definition: main.h:382

References CALL_SUBTEST.

◆ sycl_padding_test_per_device()

template<typename DataType , typename dev_Selector >
void sycl_padding_test_per_device ( dev_Selector  s)
135  {
136  QueueInterface queueInterface(s);
137  auto sycl_device = Eigen::SyclDevice(&queueInterface);
138  test_simple_padding<DataType, RowMajor, int64_t>(sycl_device);
139  test_simple_padding<DataType, ColMajor, int64_t>(sycl_device);
140  test_padded_expr<DataType, RowMajor, int64_t>(sycl_device);
141  test_padded_expr<DataType, ColMajor, int64_t>(sycl_device);
142 }
RealScalar s
Definition: level1_cplx_impl.h:130

References s.

◆ test_padded_expr()

template<typename DataType , int DataLayout, typename IndexType >
static void test_padded_expr ( const Eigen::SyclDevice &  sycl_device)
static
84  {
85  IndexType sizeDim1 = 2;
86  IndexType sizeDim2 = 3;
87  IndexType sizeDim3 = 5;
88  IndexType sizeDim4 = 7;
89  array<IndexType, 4> tensorRange = {{sizeDim1, sizeDim2, sizeDim3, sizeDim4}};
90 
92  tensor.setRandom();
93 
95  paddings[0] = std::make_pair(0, 0);
96  paddings[1] = std::make_pair(2, 1);
97  paddings[2] = std::make_pair(3, 4);
98  paddings[3] = std::make_pair(0, 0);
99 
100  Eigen::DSizes<IndexType, 2> reshape_dims;
101  reshape_dims[0] = 12;
102  reshape_dims[1] = 84;
103 
104  Tensor<DataType, 2, DataLayout, IndexType> result(reshape_dims);
105 
106  DataType* gpu_data1 = static_cast<DataType*>(sycl_device.allocate(tensor.size() * sizeof(DataType)));
107  DataType* gpu_data2 = static_cast<DataType*>(sycl_device.allocate(result.size() * sizeof(DataType)));
108  TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu1(gpu_data1, tensorRange);
109  TensorMap<Tensor<DataType, 2, DataLayout, IndexType>> gpu2(gpu_data2, reshape_dims);
110 
111  sycl_device.memcpyHostToDevice(gpu_data1, tensor.data(), (tensor.size()) * sizeof(DataType));
112  gpu2.device(sycl_device) = gpu1.pad(paddings).reshape(reshape_dims);
113  sycl_device.memcpyDeviceToHost(result.data(), gpu_data2, (result.size()) * sizeof(DataType));
114 
115  for (IndexType i = 0; i < 2; ++i) {
116  for (IndexType j = 0; j < 6; ++j) {
117  for (IndexType k = 0; k < 12; ++k) {
118  for (IndexType l = 0; l < 7; ++l) {
119  const float result_value =
120  DataLayout == ColMajor ? result(i + 2 * j, k + 12 * l) : result(j + 6 * i, l + 7 * k);
121  if (j >= 2 && j < 5 && k >= 3 && k < 8) {
122  VERIFY_IS_EQUAL(result_value, tensor(i, j - 2, k - 3, l));
123  } else {
124  VERIFY_IS_EQUAL(result_value, 0.0f);
125  }
126  }
127  }
128  }
129  }
130  sycl_device.deallocate(gpu_data1);
131  sycl_device.deallocate(gpu_data2);
132 }
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
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
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, 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_padding()

template<typename DataType , int DataLayout, typename IndexType >
static void test_simple_padding ( const Eigen::SyclDevice &  sycl_device)
static
30  {
31  IndexType sizeDim1 = 2;
32  IndexType sizeDim2 = 3;
33  IndexType sizeDim3 = 5;
34  IndexType sizeDim4 = 7;
35  array<IndexType, 4> tensorRange = {{sizeDim1, sizeDim2, sizeDim3, sizeDim4}};
36 
38  tensor.setRandom();
39 
41  paddings[0] = std::make_pair(0, 0);
42  paddings[1] = std::make_pair(2, 1);
43  paddings[2] = std::make_pair(3, 4);
44  paddings[3] = std::make_pair(0, 0);
45 
46  IndexType padedSizeDim1 = 2;
47  IndexType padedSizeDim2 = 6;
48  IndexType padedSizeDim3 = 12;
49  IndexType padedSizeDim4 = 7;
50  array<IndexType, 4> padedtensorRange = {{padedSizeDim1, padedSizeDim2, padedSizeDim3, padedSizeDim4}};
51 
52  Tensor<DataType, 4, DataLayout, IndexType> padded(padedtensorRange);
53 
54  DataType* gpu_data1 = static_cast<DataType*>(sycl_device.allocate(tensor.size() * sizeof(DataType)));
55  DataType* gpu_data2 = static_cast<DataType*>(sycl_device.allocate(padded.size() * sizeof(DataType)));
56  TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu1(gpu_data1, tensorRange);
57  TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu2(gpu_data2, padedtensorRange);
58 
59  VERIFY_IS_EQUAL(padded.dimension(0), 2 + 0);
60  VERIFY_IS_EQUAL(padded.dimension(1), 3 + 3);
61  VERIFY_IS_EQUAL(padded.dimension(2), 5 + 7);
62  VERIFY_IS_EQUAL(padded.dimension(3), 7 + 0);
63  sycl_device.memcpyHostToDevice(gpu_data1, tensor.data(), (tensor.size()) * sizeof(DataType));
64  gpu2.device(sycl_device) = gpu1.pad(paddings);
65  sycl_device.memcpyDeviceToHost(padded.data(), gpu_data2, (padded.size()) * sizeof(DataType));
66  for (IndexType i = 0; i < padedSizeDim1; ++i) {
67  for (IndexType j = 0; j < padedSizeDim2; ++j) {
68  for (IndexType k = 0; k < padedSizeDim3; ++k) {
69  for (IndexType l = 0; l < padedSizeDim4; ++l) {
70  if (j >= 2 && j < 5 && k >= 3 && k < 8) {
71  VERIFY_IS_EQUAL(padded(i, j, k, l), tensor(i, j - 2, k - 3, l));
72  } else {
73  VERIFY_IS_EQUAL(padded(i, j, k, l), 0.0f);
74  }
75  }
76  }
77  }
78  }
79  sycl_device.deallocate(gpu_data1);
80  sycl_device.deallocate(gpu_data2);
81 }

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.