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 #define EIGEN_TEST_FUNC cxx11_tensor_forced_eval_sycl
17 #define EIGEN_DEFAULT_DENSE_INDEX_TYPE int
18 #define EIGEN_USE_SYCL
19 
20 #include "main.h"
21 #include <unsupported/Eigen/CXX11/Tensor>
22 
23 using Eigen::Tensor;
24 
25 void test_forced_eval_sycl(const Eigen::SyclDevice &sycl_device) {
26 
27  int sizeDim1 = 100;
28  int sizeDim2 = 200;
29  int sizeDim3 = 200;
30  Eigen::array<int, 3> tensorRange = {{sizeDim1, sizeDim2, sizeDim3}};
31  Eigen::Tensor<float, 3> in1(tensorRange);
32  Eigen::Tensor<float, 3> in2(tensorRange);
33  Eigen::Tensor<float, 3> out(tensorRange);
34 
35  float * gpu_in1_data = static_cast<float*>(sycl_device.allocate(in1.dimensions().TotalSize()*sizeof(float)));
36  float * gpu_in2_data = static_cast<float*>(sycl_device.allocate(in2.dimensions().TotalSize()*sizeof(float)));
37  float * gpu_out_data = static_cast<float*>(sycl_device.allocate(out.dimensions().TotalSize()*sizeof(float)));
38 
39  in1 = in1.random() + in1.constant(10.0f);
40  in2 = in2.random() + in2.constant(10.0f);
41 
42  // creating TensorMap from tensor
43  Eigen::TensorMap<Eigen::Tensor<float, 3>> gpu_in1(gpu_in1_data, tensorRange);
44  Eigen::TensorMap<Eigen::Tensor<float, 3>> gpu_in2(gpu_in2_data, tensorRange);
45  Eigen::TensorMap<Eigen::Tensor<float, 3>> gpu_out(gpu_out_data, tensorRange);
46  sycl_device.memcpyHostToDevice(gpu_in1_data, in1.data(),(in1.dimensions().TotalSize())*sizeof(float));
47  sycl_device.memcpyHostToDevice(gpu_in2_data, in2.data(),(in1.dimensions().TotalSize())*sizeof(float));
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(float));
51  for (int i = 0; i < sizeDim1; ++i) {
52  for (int j = 0; j < sizeDim2; ++j) {
53  for (int 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 
67  cl::sycl::gpu_selector s;
68  Eigen::SyclDevice sycl_device(s);
69  CALL_SUBTEST(test_forced_eval_sycl(sycl_device));
70 }
void test_forced_eval_sycl(const Eigen::SyclDevice &sycl_device)
TensorDevice< TensorMap< PlainObjectType, Options_, MakePointer_ >, DeviceType > device(const DeviceType &device)
Definition: TensorBase.h:999
void test_cxx11_tensor_forced_eval_sycl()
#define VERIFY_IS_APPROX(a, b)
A tensor expression mapping an existing array of data.
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex TotalSize() const
RealScalar s
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar * data()
Definition: Tensor.h:104
#define CALL_SUBTEST(FUNC)
Definition: main.h:342
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
Definition: Tensor.h:102
internal::nested_eval< T, 1 >::type eval(const T &xpr)
std::ptrdiff_t j
The tensor class.
Definition: Tensor.h:63


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:41:55