CwiseMul.cpp File Reference
#include <iostream>
#include <unsupported/Eigen/CXX11/Tensor>

Macros

#define EIGEN_USE_SYCL
 

Functions

int main ()
 

Macro Definition Documentation

◆ EIGEN_USE_SYCL

#define EIGEN_USE_SYCL

Function Documentation

◆ main()

int main ( )
10  {
11  using DataType = float;
12  using IndexType = int64_t;
13  constexpr auto DataLayout = Eigen::RowMajor;
14 
15  auto devices = Eigen::get_sycl_supported_devices();
16  const auto device_selector = *devices.begin();
17  Eigen::QueueInterface queueInterface(device_selector);
18  auto sycl_device = Eigen::SyclDevice(&queueInterface);
19 
20  // create the tensors to be used in the operation
21  IndexType sizeDim1 = 3;
22  IndexType sizeDim2 = 3;
23  IndexType sizeDim3 = 3;
24  array<IndexType, 3> tensorRange = {{sizeDim1, sizeDim2, sizeDim3}};
25 
26  // initialize the tensors with the data we want manipulate to
30 
31  // set up some random data in the tensors to be multiplied
32  in1 = in1.random();
33  in2 = in2.random();
34 
35  // allocate memory for the tensors
36  DataType* gpu_in1_data = static_cast<DataType*>(sycl_device.allocate(in1.size() * sizeof(DataType)));
37  DataType* gpu_in2_data = static_cast<DataType*>(sycl_device.allocate(in2.size() * sizeof(DataType)));
38  DataType* gpu_out_data = static_cast<DataType*>(sycl_device.allocate(out.size() * sizeof(DataType)));
39 
40  //
41  TensorMap<Tensor<DataType, 3, DataLayout, IndexType>> gpu_in1(gpu_in1_data, tensorRange);
42  TensorMap<Tensor<DataType, 3, DataLayout, IndexType>> gpu_in2(gpu_in2_data, tensorRange);
43  TensorMap<Tensor<DataType, 3, DataLayout, IndexType>> gpu_out(gpu_out_data, tensorRange);
44 
45  // copy the memory to the device and do the c=a*b calculation
46  sycl_device.memcpyHostToDevice(gpu_in1_data, in1.data(), (in1.size()) * sizeof(DataType));
47  sycl_device.memcpyHostToDevice(gpu_in2_data, in2.data(), (in2.size()) * sizeof(DataType));
48  gpu_out.device(sycl_device) = gpu_in1 * gpu_in2;
49  sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data, (out.size()) * sizeof(DataType));
50  sycl_device.synchronize();
51 
52  // print out the results
53  for (IndexType i = 0; i < sizeDim1; ++i) {
54  for (IndexType j = 0; j < sizeDim2; ++j) {
55  for (IndexType k = 0; k < sizeDim3; ++k) {
56  std::cout << "device_out"
57  << "(" << i << ", " << j << ", " << k << ") : " << out(i, j, k) << " vs host_out"
58  << "(" << i << ", " << j << ", " << k << ") : " << in1(i, j, k) * in2(i, j, k) << "\n";
59  }
60  }
61  }
62  printf("c=a*b Done\n");
63 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
A tensor expression mapping an existing array of data.
Definition: TensorMap.h:33
The tensor class.
Definition: Tensor.h:68
static const int DataLayout
Definition: cxx11_tensor_image_patch_sycl.cpp:24
@ RowMajor
Definition: Constants.h:320
char char char int int * k
Definition: level2_impl.h:374
std::int64_t int64_t
Definition: Meta.h:43
std::ofstream out("Result.txt")
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::data(), DataLayout, Eigen::TensorBase< Derived, AccessLevel >::device(), i, j, k, out(), Eigen::RowMajor, and Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::size().