cxx11_tensor_generator_sycl.cpp File Reference
#include "main.h"
#include <unsupported/Eigen/CXX11/Tensor>

Classes

struct  Generator1D
 
struct  Generator2D
 

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_1D_sycl (const Eigen::SyclDevice &sycl_device)
 
template<typename DataType , int DataLayout, typename IndexType >
static void test_2D_sycl (const Eigen::SyclDevice &sycl_device)
 
template<typename DataType , int DataLayout, typename IndexType >
static void test_gaussian_sycl (const Eigen::SyclDevice &sycl_device)
 
template<typename DataType , typename dev_Selector >
void sycl_generator_test_per_device (dev_Selector s)
 
 EIGEN_DECLARE_TEST (cxx11_tensor_generator_sycl)
 

Variables

static const float error_threshold = 1e-8f
 

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_generator_sycl  )
136  {
137  for (const auto& device : Eigen::get_sycl_supported_devices()) {
138  CALL_SUBTEST(sycl_generator_test_per_device<float>(device));
139  }
140 }
#define CALL_SUBTEST(FUNC)
Definition: main.h:382

References CALL_SUBTEST.

◆ sycl_generator_test_per_device()

template<typename DataType , typename dev_Selector >
void sycl_generator_test_per_device ( dev_Selector  s)
126  {
127  QueueInterface queueInterface(s);
128  auto sycl_device = Eigen::SyclDevice(&queueInterface);
129  test_1D_sycl<DataType, RowMajor, int64_t>(sycl_device);
130  test_1D_sycl<DataType, ColMajor, int64_t>(sycl_device);
131  test_2D_sycl<DataType, RowMajor, int64_t>(sycl_device);
132  test_2D_sycl<DataType, ColMajor, int64_t>(sycl_device);
133  test_gaussian_sycl<DataType, RowMajor, int64_t>(sycl_device);
134  test_gaussian_sycl<DataType, ColMajor, int64_t>(sycl_device);
135 }
RealScalar s
Definition: level1_cplx_impl.h:130

References s.

◆ test_1D_sycl()

template<typename DataType , int DataLayout, typename IndexType >
static void test_1D_sycl ( const Eigen::SyclDevice &  sycl_device)
static
32  {
33  IndexType sizeDim1 = 6;
34  array<IndexType, 1> tensorRange = {{sizeDim1}};
37 
38  const size_t tensorBuffSize = vec.size() * sizeof(DataType);
39  DataType* gpu_data_vec = static_cast<DataType*>(sycl_device.allocate(tensorBuffSize));
40  DataType* gpu_data_result = static_cast<DataType*>(sycl_device.allocate(tensorBuffSize));
41 
42  TensorMap<Tensor<DataType, 1, DataLayout, IndexType>> gpu_vec(gpu_data_vec, tensorRange);
43  TensorMap<Tensor<DataType, 1, DataLayout, IndexType>> gpu_result(gpu_data_result, tensorRange);
44 
45  sycl_device.memcpyHostToDevice(gpu_data_vec, vec.data(), tensorBuffSize);
46  gpu_result.device(sycl_device) = gpu_vec.generate(Generator1D());
47  sycl_device.memcpyDeviceToHost(result.data(), gpu_data_result, tensorBuffSize);
48 
49  for (IndexType i = 0; i < 6; ++i) {
50  VERIFY_IS_EQUAL(result(i), i);
51  }
52 }
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
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367
std::array< T, N > array
Definition: EmulateArray.h:231
Definition: cxx11_tensor_generator.cpp:14

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

◆ test_2D_sycl()

template<typename DataType , int DataLayout, typename IndexType >
static void test_2D_sycl ( const Eigen::SyclDevice &  sycl_device)
static
63  {
64  IndexType sizeDim1 = 5;
65  IndexType sizeDim2 = 7;
66  array<IndexType, 2> tensorRange = {{sizeDim1, sizeDim2}};
69 
70  const size_t tensorBuffSize = matrix.size() * sizeof(DataType);
71  DataType* gpu_data_matrix = static_cast<DataType*>(sycl_device.allocate(tensorBuffSize));
72  DataType* gpu_data_result = static_cast<DataType*>(sycl_device.allocate(tensorBuffSize));
73 
74  TensorMap<Tensor<DataType, 2, DataLayout, IndexType>> gpu_matrix(gpu_data_matrix, tensorRange);
75  TensorMap<Tensor<DataType, 2, DataLayout, IndexType>> gpu_result(gpu_data_result, tensorRange);
76 
77  sycl_device.memcpyHostToDevice(gpu_data_matrix, matrix.data(), tensorBuffSize);
78  gpu_result.device(sycl_device) = gpu_matrix.generate(Generator2D());
79  sycl_device.memcpyDeviceToHost(result.data(), gpu_data_result, tensorBuffSize);
80 
81  for (IndexType i = 0; i < 5; ++i) {
82  for (IndexType j = 0; j < 5; ++j) {
83  VERIFY_IS_EQUAL(result(i, j), 3 * i + 11 * j);
84  }
85  }
86 }
Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor >, 0, Eigen::OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition: common.h:85
Definition: cxx11_tensor_generator.cpp:30
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::data(), Eigen::TensorBase< Derived, AccessLevel >::device(), i, j, matrix(), and VERIFY_IS_EQUAL.

◆ test_gaussian_sycl()

template<typename DataType , int DataLayout, typename IndexType >
static void test_gaussian_sycl ( const Eigen::SyclDevice &  sycl_device)
static
89  {
90  IndexType rows = 32;
91  IndexType cols = 48;
92  array<DataType, 2> means;
93  means[0] = rows / 2.0f;
94  means[1] = cols / 2.0f;
95  array<DataType, 2> std_devs;
96  std_devs[0] = 3.14f;
97  std_devs[1] = 2.7f;
98  internal::GaussianGenerator<DataType, Eigen::DenseIndex, 2> gaussian_gen(means, std_devs);
99 
100  array<IndexType, 2> tensorRange = {{rows, cols}};
102  Tensor<DataType, 2, DataLayout, IndexType> result(tensorRange);
103 
104  const size_t tensorBuffSize = matrix.size() * sizeof(DataType);
105  DataType* gpu_data_matrix = static_cast<DataType*>(sycl_device.allocate(tensorBuffSize));
106  DataType* gpu_data_result = static_cast<DataType*>(sycl_device.allocate(tensorBuffSize));
107 
108  TensorMap<Tensor<DataType, 2, DataLayout, IndexType>> gpu_matrix(gpu_data_matrix, tensorRange);
109  TensorMap<Tensor<DataType, 2, DataLayout, IndexType>> gpu_result(gpu_data_result, tensorRange);
110 
111  sycl_device.memcpyHostToDevice(gpu_data_matrix, matrix.data(), tensorBuffSize);
112  gpu_result.device(sycl_device) = gpu_matrix.generate(gaussian_gen);
113  sycl_device.memcpyDeviceToHost(result.data(), gpu_data_result, tensorBuffSize);
114 
115  for (IndexType i = 0; i < rows; ++i) {
116  for (IndexType j = 0; j < cols; ++j) {
117  DataType g_rows = powf(rows / 2.0f - i, 2) / (3.14f * 3.14f) * 0.5f;
118  DataType g_cols = powf(cols / 2.0f - j, 2) / (2.7f * 2.7f) * 0.5f;
119  DataType gaussian = expf(-g_rows - g_cols);
120  Eigen::internal::isApprox(result(i, j), gaussian, error_threshold);
121  }
122  }
123 }
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
static const float error_threshold
Definition: cxx11_tensor_generator_sycl.cpp:19
EIGEN_DEVICE_FUNC bool isApprox(const Scalar &x, const Scalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
Definition: MathFunctions.h:1923

References cols, Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::data(), Eigen::TensorBase< Derived, AccessLevel >::device(), error_threshold, i, Eigen::internal::isApprox(), j, matrix(), and rows.

Variable Documentation

◆ error_threshold

const float error_threshold = 1e-8f
static

Referenced by test_gaussian_sycl().