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 }
void test_forced_eval_sycl(const Eigen::SyclDevice &sycl_device)
EIGEN_DECLARE_TEST(cxx11_tensor_forced_eval_sycl)
std::ofstream out("Result.txt")
#define VERIFY_IS_APPROX(a, b)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex TotalSize() const
A tensor expression mapping an existing array of data.
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
RealScalar s
TensorDevice< TensorMap< PlainObjectType, Options_, MakePointer_ >, DeviceType > device(const DeviceType &dev)
Definition: TensorBase.h:1145
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar * data()
Definition: Tensor.h:104
#define CALL_SUBTEST(FUNC)
Definition: main.h:399
void tensorForced_evalperDevice(Dev_selector s)
internal::nested_eval< T, 1 >::type eval(const T &xpr)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
Definition: Tensor.h:102
std::ptrdiff_t j
The tensor class.
Definition: Tensor.h:63


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:07