cxx11_tensor_device_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 #include <stdint.h>
23 #include <iostream>
24 
25 template <typename DataType, int DataLayout, typename IndexType>
26 void test_device_memory(const Eigen::SyclDevice &sycl_device) {
27  std::cout << "Running on : "
28  << sycl_device.sycl_queue().get_device(). template get_info<cl::sycl::info::device::name>()
29  <<std::endl;
30  IndexType sizeDim1 = 100;
31  array<IndexType, 1> tensorRange = {{sizeDim1}};
34  memset(in1.data(), 1, in1.size() * sizeof(DataType));
35  DataType* gpu_in_data = static_cast<DataType*>(sycl_device.allocate(in.size()*sizeof(DataType)));
36  sycl_device.memset(gpu_in_data, 1, in.size()*sizeof(DataType));
37  sycl_device.memcpyDeviceToHost(in.data(), gpu_in_data, in.size()*sizeof(DataType));
38  for (IndexType i=0; i<in.size(); i++) {
39  VERIFY_IS_EQUAL(in(i), in1(i));
40  }
41  sycl_device.deallocate(gpu_in_data);
42 }
43 
44 template <typename DataType, int DataLayout, typename IndexType>
45 void test_device_exceptions(const Eigen::SyclDevice &sycl_device) {
46  VERIFY(sycl_device.ok());
47  IndexType sizeDim1 = 100;
48  array<IndexType, 1> tensorDims = {{sizeDim1}};
49  DataType* gpu_data = static_cast<DataType*>(sycl_device.allocate(sizeDim1*sizeof(DataType)));
50  sycl_device.memset(gpu_data, 1, sizeDim1*sizeof(DataType));
51 
54  out.device(sycl_device) = in / in.constant(0);
55 
56  sycl_device.synchronize();
57  VERIFY(!sycl_device.ok());
58  sycl_device.deallocate(gpu_data);
59 }
60 
61 template<typename DataType> void sycl_device_test_per_device(const cl::sycl::device& d){
62  std::cout << "Running on " << d.template get_info<cl::sycl::info::device::name>() << std::endl;
63  QueueInterface queueInterface(d);
64  auto sycl_device = Eigen::SyclDevice(&queueInterface);
65  test_device_memory<DataType, RowMajor, int64_t>(sycl_device);
66  test_device_memory<DataType, ColMajor, int64_t>(sycl_device);
68  //test_device_exceptions<DataType, RowMajor>(sycl_device);
70  //test_device_exceptions<DataType, ColMajor>(sycl_device);
71 }
72 
73 EIGEN_DECLARE_TEST(cxx11_tensor_device_sycl) {
74  for (const auto& device :Eigen::get_sycl_supported_devices()) {
75  CALL_SUBTEST(sycl_device_test_per_device<float>(device));
76  }
77 }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const
Definition: Tensor.h:103
std::ofstream out("Result.txt")
EIGEN_DECLARE_TEST(cxx11_tensor_device_sycl)
void test_device_memory(const Eigen::SyclDevice &sycl_device)
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:386
A tensor expression mapping an existing array of data.
void test_device_exceptions(const Eigen::SyclDevice &sycl_device)
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
#define VERIFY(a)
Definition: main.h:380
void sycl_device_test_per_device(const cl::sycl::device &d)
The tensor class.
Definition: Tensor.h:63


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