3 #include <unsupported/Eigen/CXX11/Tensor> 6 using Eigen::SyclDevice;
12 using DataType =
float;
16 auto devices = Eigen::get_sycl_supported_devices();
17 const auto device_selector = *devices.begin();
18 Eigen::QueueInterface queueInterface(device_selector);
19 auto sycl_device = Eigen::SyclDevice(&queueInterface);
22 IndexType sizeDim1 = 3;
23 IndexType sizeDim2 = 3;
24 IndexType sizeDim3 = 3;
37 DataType * gpu_in1_data =
static_cast<DataType*
>(sycl_device.allocate(in1.
size()*
sizeof(DataType)));
38 DataType * gpu_in2_data =
static_cast<DataType*
>(sycl_device.allocate(in2.
size()*
sizeof(DataType)));
39 DataType * gpu_out_data =
static_cast<DataType*
>(sycl_device.allocate(out.
size()*
sizeof(DataType)));
47 sycl_device.memcpyHostToDevice(gpu_in1_data, in1.
data(),(in1.
size())*
sizeof(DataType));
48 sycl_device.memcpyHostToDevice(gpu_in2_data, in2.
data(),(in2.
size())*
sizeof(DataType));
49 gpu_out.
device(sycl_device) = gpu_in1 * gpu_in2;
50 sycl_device.memcpyDeviceToHost(out.
data(), gpu_out_data,(out.
size())*
sizeof(DataType));
51 sycl_device.synchronize();
54 for (IndexType
i = 0;
i < sizeDim1; ++
i) {
55 for (IndexType
j = 0;
j < sizeDim2; ++
j) {
56 for (IndexType k = 0; k < sizeDim3; ++k) {
57 std::cout <<
"device_out" <<
"(" <<
i <<
", " <<
j <<
", " << k <<
") : " <<
out(
i,
j,k)
58 <<
" vs host_out" <<
"(" <<
i <<
", " <<
j <<
", " << k <<
") : " << in1(
i,
j,k) * in2(
i,
j,k) <<
"\n";
62 printf(
"c=a*b Done\n");
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const
std::ofstream out("Result.txt")
A tensor expression mapping an existing array of data.
TensorDevice< TensorMap< PlainObjectType, Options_, MakePointer_ >, DeviceType > device(const DeviceType &dev)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar * data()
static const int DataLayout