cxx11_tensor_striding_sycl.cpp File Reference
#include <iostream>
#include <chrono>
#include <ctime>
#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_striding (const Eigen::SyclDevice &sycl_device)
 
template<typename DataType , int DataLayout, typename IndexType >
static void test_striding_as_lvalue (const Eigen::SyclDevice &sycl_device)
 
template<typename Dev_selector >
void tensorStridingPerDevice (Dev_selector &s)
 
 EIGEN_DECLARE_TEST (cxx11_tensor_striding_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_striding_sycl  )
189  {
190  for (const auto& device : Eigen::get_sycl_supported_devices()) {
192  }
193 }
void tensorStridingPerDevice(Dev_selector &s)
Definition: cxx11_tensor_striding_sycl.cpp:180
#define CALL_SUBTEST(FUNC)
Definition: main.h:382

References CALL_SUBTEST, and tensorStridingPerDevice().

◆ tensorStridingPerDevice()

template<typename Dev_selector >
void tensorStridingPerDevice ( Dev_selector &  s)
180  {
181  QueueInterface queueInterface(s);
182  auto sycl_device = Eigen::SyclDevice(&queueInterface);
183  test_simple_striding<float, ColMajor, int64_t>(sycl_device);
184  test_simple_striding<float, RowMajor, int64_t>(sycl_device);
185  test_striding_as_lvalue<float, ColMajor, int64_t>(sycl_device);
186  test_striding_as_lvalue<float, RowMajor, int64_t>(sycl_device);
187 }
RealScalar s
Definition: level1_cplx_impl.h:130

References s.

Referenced by EIGEN_DECLARE_TEST().

◆ test_simple_striding()

template<typename DataType , int DataLayout, typename IndexType >
static void test_simple_striding ( const Eigen::SyclDevice &  sycl_device)
static
33  {
34  Eigen::array<IndexType, 4> tensor_dims = {{2, 3, 5, 7}};
35  Eigen::array<IndexType, 4> stride_dims = {{1, 1, 3, 3}};
36 
38  Tensor<DataType, 4, DataLayout, IndexType> no_stride(tensor_dims);
40 
41  std::size_t tensor_bytes = tensor.size() * sizeof(DataType);
42  std::size_t no_stride_bytes = no_stride.size() * sizeof(DataType);
43  std::size_t stride_bytes = stride.size() * sizeof(DataType);
44  DataType* d_tensor = static_cast<DataType*>(sycl_device.allocate(tensor_bytes));
45  DataType* d_no_stride = static_cast<DataType*>(sycl_device.allocate(no_stride_bytes));
46  DataType* d_stride = static_cast<DataType*>(sycl_device.allocate(stride_bytes));
47 
49  Eigen::TensorMap<Eigen::Tensor<DataType, 4, DataLayout, IndexType> > gpu_no_stride(d_no_stride, tensor_dims);
51 
52  tensor.setRandom();
54  strides[0] = 1;
55  strides[1] = 1;
56  strides[2] = 1;
57  strides[3] = 1;
58  sycl_device.memcpyHostToDevice(d_tensor, tensor.data(), tensor_bytes);
59  gpu_no_stride.device(sycl_device) = gpu_tensor.stride(strides);
60  sycl_device.memcpyDeviceToHost(no_stride.data(), d_no_stride, no_stride_bytes);
61 
62  // no_stride = tensor.stride(strides);
63 
64  VERIFY_IS_EQUAL(no_stride.dimension(0), 2);
65  VERIFY_IS_EQUAL(no_stride.dimension(1), 3);
66  VERIFY_IS_EQUAL(no_stride.dimension(2), 5);
67  VERIFY_IS_EQUAL(no_stride.dimension(3), 7);
68 
69  for (IndexType i = 0; i < 2; ++i) {
70  for (IndexType j = 0; j < 3; ++j) {
71  for (IndexType k = 0; k < 5; ++k) {
72  for (IndexType l = 0; l < 7; ++l) {
73  VERIFY_IS_EQUAL(tensor(i, j, k, l), no_stride(i, j, k, l));
74  }
75  }
76  }
77  }
78 
79  strides[0] = 2;
80  strides[1] = 4;
81  strides[2] = 2;
82  strides[3] = 3;
83  // Tensor<float, 4, DataLayout> stride;
84  // stride = tensor.stride(strides);
85 
86  gpu_stride.device(sycl_device) = gpu_tensor.stride(strides);
87  sycl_device.memcpyDeviceToHost(stride.data(), d_stride, stride_bytes);
88 
89  VERIFY_IS_EQUAL(stride.dimension(0), 1);
90  VERIFY_IS_EQUAL(stride.dimension(1), 1);
91  VERIFY_IS_EQUAL(stride.dimension(2), 3);
92  VERIFY_IS_EQUAL(stride.dimension(3), 3);
93 
94  for (IndexType i = 0; i < 1; ++i) {
95  for (IndexType j = 0; j < 1; ++j) {
96  for (IndexType k = 0; k < 3; ++k) {
97  for (IndexType l = 0; l < 3; ++l) {
98  VERIFY_IS_EQUAL(tensor(2 * i, 4 * j, 2 * k, 3 * l), stride(i, j, k, l));
99  }
100  }
101  }
102  }
103 
104  sycl_device.deallocate(d_tensor);
105  sycl_device.deallocate(d_no_stride);
106  sycl_device.deallocate(d_stride);
107 }
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::TensorBase< Derived, AccessLevel >::stride(), Eigen::internal::strides(), and VERIFY_IS_EQUAL.

◆ test_striding_as_lvalue()

template<typename DataType , int DataLayout, typename IndexType >
static void test_striding_as_lvalue ( const Eigen::SyclDevice &  sycl_device)
static
110  {
111  Eigen::array<IndexType, 4> tensor_dims = {{2, 3, 5, 7}};
112  Eigen::array<IndexType, 4> stride_dims = {{3, 12, 10, 21}};
113 
114  Tensor<DataType, 4, DataLayout, IndexType> tensor(tensor_dims);
115  Tensor<DataType, 4, DataLayout, IndexType> no_stride(stride_dims);
116  Tensor<DataType, 4, DataLayout, IndexType> stride(stride_dims);
117 
118  std::size_t tensor_bytes = tensor.size() * sizeof(DataType);
119  std::size_t no_stride_bytes = no_stride.size() * sizeof(DataType);
120  std::size_t stride_bytes = stride.size() * sizeof(DataType);
121 
122  DataType* d_tensor = static_cast<DataType*>(sycl_device.allocate(tensor_bytes));
123  DataType* d_no_stride = static_cast<DataType*>(sycl_device.allocate(no_stride_bytes));
124  DataType* d_stride = static_cast<DataType*>(sycl_device.allocate(stride_bytes));
125 
126  Eigen::TensorMap<Eigen::Tensor<DataType, 4, DataLayout, IndexType> > gpu_tensor(d_tensor, tensor_dims);
127  Eigen::TensorMap<Eigen::Tensor<DataType, 4, DataLayout, IndexType> > gpu_no_stride(d_no_stride, stride_dims);
128  Eigen::TensorMap<Eigen::Tensor<DataType, 4, DataLayout, IndexType> > gpu_stride(d_stride, stride_dims);
129 
130  // Tensor<float, 4, DataLayout> tensor(2,3,5,7);
131  tensor.setRandom();
133  strides[0] = 2;
134  strides[1] = 4;
135  strides[2] = 2;
136  strides[3] = 3;
137 
138  // Tensor<float, 4, DataLayout> result(3, 12, 10, 21);
139  // result.stride(strides) = tensor;
140  sycl_device.memcpyHostToDevice(d_tensor, tensor.data(), tensor_bytes);
141  gpu_stride.stride(strides).device(sycl_device) = gpu_tensor;
142  sycl_device.memcpyDeviceToHost(stride.data(), d_stride, stride_bytes);
143 
144  for (IndexType i = 0; i < 2; ++i) {
145  for (IndexType j = 0; j < 3; ++j) {
146  for (IndexType k = 0; k < 5; ++k) {
147  for (IndexType l = 0; l < 7; ++l) {
148  VERIFY_IS_EQUAL(tensor(i, j, k, l), stride(2 * i, 4 * j, 2 * k, 3 * l));
149  }
150  }
151  }
152  }
153 
154  array<IndexType, 4> no_strides;
155  no_strides[0] = 1;
156  no_strides[1] = 1;
157  no_strides[2] = 1;
158  no_strides[3] = 1;
159  // Tensor<float, 4, DataLayout> result2(3, 12, 10, 21);
160  // result2.stride(strides) = tensor.stride(no_strides);
161 
162  gpu_no_stride.stride(strides).device(sycl_device) = gpu_tensor.stride(no_strides);
163  sycl_device.memcpyDeviceToHost(no_stride.data(), d_no_stride, no_stride_bytes);
164 
165  for (IndexType i = 0; i < 2; ++i) {
166  for (IndexType j = 0; j < 3; ++j) {
167  for (IndexType k = 0; k < 5; ++k) {
168  for (IndexType l = 0; l < 7; ++l) {
169  VERIFY_IS_EQUAL(tensor(i, j, k, l), no_stride(2 * i, 4 * j, 2 * k, 3 * l));
170  }
171  }
172  }
173  }
174  sycl_device.deallocate(d_tensor);
175  sycl_device.deallocate(d_no_stride);
176  sycl_device.deallocate(d_stride);
177 }

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