cxx11_tensor_random_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_DEFAULT_DENSE_INDEX_TYPE int64_t
17 #define EIGEN_USE_SYCL
18 
19 #include "main.h"
20 #include <unsupported/Eigen/CXX11/Tensor>
21 
22 template <typename DataType, int DataLayout, typename IndexType>
23 static void test_sycl_random_uniform(const Eigen::SyclDevice& sycl_device)
24 {
26  out.setZero();
27 
28  std::size_t out_bytes = out.size() * sizeof(DataType);
29 
30  IndexType sizeDim0 = 72;
31  IndexType sizeDim1 = 97;
32 
33  array<IndexType, 2> tensorRange = {{sizeDim0, sizeDim1}};
34 
35  DataType* d_out = static_cast<DataType*>(sycl_device.allocate(out_bytes));
36  TensorMap<Tensor<DataType, 2, DataLayout, IndexType>> gpu_out(d_out, tensorRange);
37 
38  gpu_out.device(sycl_device)=gpu_out.random();
39  sycl_device.memcpyDeviceToHost(out.data(), d_out,out_bytes);
40  for(IndexType i=1; i<sizeDim0; i++)
41  for(IndexType j=1; j<sizeDim1; j++)
42  {
45  VERIFY_IS_NOT_EQUAL(out(i,j), out(i-1,j-1)); }
46 
47  // For now we just check thes code doesn't crash.
48  // TODO: come up with a valid test of randomness
49  sycl_device.deallocate(d_out);
50 }
51 
52 template <typename DataType, int DataLayout, typename IndexType>
53 void test_sycl_random_normal(const Eigen::SyclDevice& sycl_device)
54 {
56  out.setZero();
57  std::size_t out_bytes = out.size() * sizeof(DataType);
58 
59  IndexType sizeDim0 = 72;
60  IndexType sizeDim1 = 97;
61 
62  array<IndexType, 2> tensorRange = {{sizeDim0, sizeDim1}};
63 
64  DataType* d_out = static_cast<DataType*>(sycl_device.allocate(out_bytes));
65  TensorMap<Tensor<DataType, 2, DataLayout, IndexType>> gpu_out(d_out, tensorRange);
67  gpu_out.device(sycl_device)=gpu_out.random(gen);
68  sycl_device.memcpyDeviceToHost(out.data(), d_out,out_bytes);
69  for(IndexType i=1; i<sizeDim0; i++)
70  for(IndexType j=1; j<sizeDim1; j++)
71  {
74  VERIFY_IS_NOT_EQUAL(out(i,j), out(i-1,j-1));
75 
76  }
77 
78  // For now we just check thes code doesn't crash.
79  // TODO: come up with a valid test of randomness
80  sycl_device.deallocate(d_out);
81 }
82 
83 template<typename DataType, typename dev_Selector> void sycl_random_test_per_device(dev_Selector s){
84  QueueInterface queueInterface(s);
85  auto sycl_device = Eigen::SyclDevice(&queueInterface);
86  test_sycl_random_uniform<DataType, RowMajor, int64_t>(sycl_device);
87  test_sycl_random_uniform<DataType, ColMajor, int64_t>(sycl_device);
88  test_sycl_random_normal<DataType, RowMajor, int64_t>(sycl_device);
89  test_sycl_random_normal<DataType, ColMajor, int64_t>(sycl_device);
90 
91 }
92 EIGEN_DECLARE_TEST(cxx11_tensor_random_sycl)
93 {
94  for (const auto& device :Eigen::get_sycl_supported_devices()) {
95  CALL_SUBTEST(sycl_random_test_per_device<float>(device));
96 #ifdef EIGEN_SYCL_DOUBLE_SUPPORT
97  CALL_SUBTEST(sycl_random_test_per_device<double>(device));
98 #endif
99  }
100 }
Eigen::Tensor
The tensor class.
Definition: Tensor.h:63
test_sycl_random_normal
void test_sycl_random_normal(const Eigen::SyclDevice &sycl_device)
Definition: cxx11_tensor_random_sycl.cpp:53
s
RealScalar s
Definition: level1_cplx_impl.h:126
Eigen::array
Definition: EmulateArray.h:21
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
Eigen::TensorMap
A tensor expression mapping an existing array of data.
Definition: TensorForwardDeclarations.h:52
sycl_random_test_per_device
void sycl_random_test_per_device(dev_Selector s)
Definition: cxx11_tensor_random_sycl.cpp:83
size_t
std::size_t size_t
Definition: wrap/pybind11/include/pybind11/detail/common.h:490
test_sycl_random_uniform
static void test_sycl_random_uniform(const Eigen::SyclDevice &sycl_device)
Definition: cxx11_tensor_random_sycl.cpp:23
out
std::ofstream out("Result.txt")
VERIFY_IS_NOT_EQUAL
#define VERIFY_IS_NOT_EQUAL(a, b)
Definition: main.h:387
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(cxx11_tensor_random_sycl)
Definition: cxx11_tensor_random_sycl.cpp:92
main.h
Eigen::internal::NormalRandomGenerator
Definition: TensorRandom.h:238
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:09