cxx11_tensor_forced_eval_sycl.cpp
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2016
5 // Mehdi Goli Codeplay Software Ltd.
6 // Ralph Potter Codeplay Software Ltd.
7 // Luke Iwanski Codeplay Software Ltd.
8 // Contact: <eigen@codeplay.com>
9 //
10 // This Source Code Form is subject to the terms of the Mozilla
11 // Public License v. 2.0. If a copy of the MPL was not distributed
12 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
13 
14 #define EIGEN_TEST_NO_LONGDOUBLE
15 #define EIGEN_TEST_NO_COMPLEX
16 
17 #define EIGEN_DEFAULT_DENSE_INDEX_TYPE int64_t
18 #define EIGEN_USE_SYCL
19 
20 #include "main.h"
21 #include <unsupported/Eigen/CXX11/Tensor>
22 
23 using Eigen::Tensor;
24 template <typename DataType, int DataLayout, typename IndexType>
25 void test_forced_eval_sycl(const Eigen::SyclDevice &sycl_device) {
26 
27  IndexType sizeDim1 = 100;
28  IndexType sizeDim2 = 20;
29  IndexType sizeDim3 = 20;
30  Eigen::array<IndexType, 3> tensorRange = {{sizeDim1, sizeDim2, sizeDim3}};
34 
35  DataType * gpu_in1_data = static_cast<DataType*>(sycl_device.allocate(in1.dimensions().TotalSize()*sizeof(DataType)));
36  DataType * gpu_in2_data = static_cast<DataType*>(sycl_device.allocate(in2.dimensions().TotalSize()*sizeof(DataType)));
37  DataType * gpu_out_data = static_cast<DataType*>(sycl_device.allocate(out.dimensions().TotalSize()*sizeof(DataType)));
38 
39  in1 = in1.random() + in1.constant(static_cast<DataType>(10.0f));
40  in2 = in2.random() + in2.constant(static_cast<DataType>(10.0f));
41 
42  // creating TensorMap from tensor
46  sycl_device.memcpyHostToDevice(gpu_in1_data, in1.data(),(in1.dimensions().TotalSize())*sizeof(DataType));
47  sycl_device.memcpyHostToDevice(gpu_in2_data, in2.data(),(in2.dimensions().TotalSize())*sizeof(DataType));
49  gpu_out.device(sycl_device) =(gpu_in1 + gpu_in2).eval() * gpu_in2;
50  sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.dimensions().TotalSize())*sizeof(DataType));
51  for (IndexType i = 0; i < sizeDim1; ++i) {
52  for (IndexType j = 0; j < sizeDim2; ++j) {
53  for (IndexType k = 0; k < sizeDim3; ++k) {
54  VERIFY_IS_APPROX(out(i, j, k),
55  (in1(i, j, k) + in2(i, j, k)) * in2(i, j, k));
56  }
57  }
58  }
59  printf("(a+b)*b Test Passed\n");
60  sycl_device.deallocate(gpu_in1_data);
61  sycl_device.deallocate(gpu_in2_data);
62  sycl_device.deallocate(gpu_out_data);
63 
64 }
65 
66 template <typename DataType, typename Dev_selector> void tensorForced_evalperDevice(Dev_selector s){
67  QueueInterface queueInterface(s);
68  auto sycl_device = Eigen::SyclDevice(&queueInterface);
69  test_forced_eval_sycl<DataType, RowMajor, int64_t>(sycl_device);
70  test_forced_eval_sycl<DataType, ColMajor, int64_t>(sycl_device);
71 }
72 EIGEN_DECLARE_TEST(cxx11_tensor_forced_eval_sycl) {
73  for (const auto& device :Eigen::get_sycl_supported_devices()) {
74  CALL_SUBTEST(tensorForced_evalperDevice<float>(device));
75  CALL_SUBTEST(tensorForced_evalperDevice<half>(device));
76  }
77 }
Eigen::Tensor
The tensor class.
Definition: Tensor.h:63
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(cxx11_tensor_forced_eval_sycl)
Definition: cxx11_tensor_forced_eval_sycl.cpp:72
s
RealScalar s
Definition: level1_cplx_impl.h:126
Eigen::array
Definition: EmulateArray.h:21
tensorForced_evalperDevice
void tensorForced_evalperDevice(Dev_selector s)
Definition: cxx11_tensor_forced_eval_sycl.cpp:66
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
Eigen::Tensor::dimensions
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE Dimensions & dimensions() const
Definition: Tensor.h:102
test_forced_eval_sycl
void test_forced_eval_sycl(const Eigen::SyclDevice &sycl_device)
Definition: cxx11_tensor_forced_eval_sycl.cpp:25
Eigen::DSizes::TotalSize
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex TotalSize() const
Definition: TensorDimensions.h:271
Eigen::TensorMap
A tensor expression mapping an existing array of data.
Definition: TensorForwardDeclarations.h:52
out
std::ofstream out("Result.txt")
tree::f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Definition: testExpression.cpp:218
VERIFY_IS_APPROX
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:15
main.h
Eigen::Tensor::data
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar * data()
Definition: Tensor.h:104
eval
internal::nested_eval< T, 1 >::type eval(const T &xpr)
Definition: sparse_permutations.cpp:38
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
CALL_SUBTEST
#define CALL_SUBTEST(FUNC)
Definition: main.h:399


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:08