14 #define EIGEN_TEST_NO_LONGDOUBLE 15 #define EIGEN_TEST_NO_COMPLEX 17 #define EIGEN_DEFAULT_DENSE_INDEX_TYPE int64_t 18 #define EIGEN_USE_SYCL 22 #include <unsupported/Eigen/CXX11/Tensor> 29 return coordinates[0];
33 template <
typename DataType,
int DataLayout,
typename IndexType>
37 IndexType sizeDim1 = 6;
42 const size_t tensorBuffSize =vec.
size()*
sizeof(DataType);
43 DataType* gpu_data_vec =
static_cast<DataType*
>(sycl_device.allocate(tensorBuffSize));
44 DataType* gpu_data_result =
static_cast<DataType*
>(sycl_device.allocate(tensorBuffSize));
49 sycl_device.memcpyHostToDevice(gpu_data_vec, vec.
data(), tensorBuffSize);
51 sycl_device.memcpyDeviceToHost(result.
data(), gpu_data_result, tensorBuffSize);
53 for (IndexType
i = 0;
i < 6; ++
i) {
63 return 3 * coordinates[0] + 11 * coordinates[1];
67 template <
typename DataType,
int DataLayout,
typename IndexType>
70 IndexType sizeDim1 = 5;
71 IndexType sizeDim2 = 7;
76 const size_t tensorBuffSize =matrix.
size()*
sizeof(DataType);
77 DataType* gpu_data_matrix =
static_cast<DataType*
>(sycl_device.allocate(tensorBuffSize));
78 DataType* gpu_data_result =
static_cast<DataType*
>(sycl_device.allocate(tensorBuffSize));
83 sycl_device.memcpyHostToDevice(gpu_data_matrix, matrix.
data(), tensorBuffSize);
85 sycl_device.memcpyDeviceToHost(result.
data(), gpu_data_result, tensorBuffSize);
87 for (IndexType
i = 0;
i < 5; ++
i) {
88 for (IndexType
j = 0;
j < 5; ++
j) {
94 template <
typename DataType,
int DataLayout,
typename IndexType>
100 means[0] = rows / 2.0f;
101 means[1] = cols / 2.0f;
105 internal::GaussianGenerator<DataType, Eigen::DenseIndex, 2> gaussian_gen(means, std_devs);
111 const size_t tensorBuffSize =matrix.
size()*
sizeof(DataType);
112 DataType* gpu_data_matrix =
static_cast<DataType*
>(sycl_device.allocate(tensorBuffSize));
113 DataType* gpu_data_result =
static_cast<DataType*
>(sycl_device.allocate(tensorBuffSize));
118 sycl_device.memcpyHostToDevice(gpu_data_matrix, matrix.
data(), tensorBuffSize);
119 gpu_result.
device(sycl_device)=gpu_matrix.generate(gaussian_gen);
120 sycl_device.memcpyDeviceToHost(result.
data(), gpu_data_result, tensorBuffSize);
122 for (IndexType
i = 0;
i <
rows; ++
i) {
123 for (IndexType
j = 0;
j <
cols; ++
j) {
124 DataType g_rows = powf(rows/2.0
f -
i, 2) / (3.14f * 3.14f) * 0.5
f;
125 DataType g_cols = powf(cols/2.0
f -
j, 2) / (2.7f * 2.7f) * 0.5
f;
126 DataType gaussian = expf(-g_rows - g_cols);
133 QueueInterface queueInterface(s);
134 auto sycl_device = Eigen::SyclDevice(&queueInterface);
135 test_1D_sycl<DataType, RowMajor, int64_t>(sycl_device);
136 test_1D_sycl<DataType, ColMajor, int64_t>(sycl_device);
137 test_2D_sycl<DataType, RowMajor, int64_t>(sycl_device);
138 test_2D_sycl<DataType, ColMajor, int64_t>(sycl_device);
139 test_gaussian_sycl<DataType, RowMajor, int64_t>(sycl_device);
140 test_gaussian_sycl<DataType, ColMajor, int64_t>(sycl_device);
144 for (
const auto& device :Eigen::get_sycl_supported_devices()) {
145 CALL_SUBTEST(sycl_generator_test_per_device<float>(device));
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const
static void test_2D_sycl(const Eigen::SyclDevice &sycl_device)
EIGEN_DECLARE_TEST(cxx11_tensor_generator_sycl)
static void test_gaussian_sycl(const Eigen::SyclDevice &sycl_device)
static void test_1D_sycl(const Eigen::SyclDevice &sycl_device)
float operator()(const array< Eigen::DenseIndex, 2 > &coordinates) const
void sycl_generator_test_per_device(dev_Selector s)
#define VERIFY_IS_EQUAL(a, b)
A tensor expression mapping an existing array of data.
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
TensorDevice< TensorMap< PlainObjectType, Options_, MakePointer_ >, DeviceType > device(const DeviceType &dev)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar * data()
Point2Pair means(const std::vector< Point2Pair > &abPointPairs)
Calculate the two means of a set of Point2 pairs.
#define CALL_SUBTEST(FUNC)
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
EIGEN_DEVICE_FUNC bool isApprox(const Scalar &x, const Scalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
static const float error_threshold
float operator()(const array< Eigen::DenseIndex, 1 > &coordinates) const