mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Merged in benoitsteiner/opencl (pull request PR-246)
Improved support for OpenCL
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# generate split test header file only if it does not yet exist
|
||||
# in order to prevent a rebuild everytime cmake is configured
|
||||
if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/split_test_helper.h)
|
||||
if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/split_test_helper.h)
|
||||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/split_test_helper.h "")
|
||||
foreach(i RANGE 1 999)
|
||||
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/split_test_helper.h
|
||||
@@ -16,11 +16,11 @@ endif()
|
||||
set_property(GLOBAL PROPERTY EIGEN_CURRENT_SUBPROJECT "Unsupported")
|
||||
add_custom_target(BuildUnsupported)
|
||||
|
||||
include_directories(../../test ../../unsupported ../../Eigen
|
||||
include_directories(../../test ../../unsupported ../../Eigen
|
||||
${CMAKE_CURRENT_BINARY_DIR}/../../test)
|
||||
|
||||
find_package (Threads)
|
||||
|
||||
|
||||
find_package(GoogleHash)
|
||||
if(GOOGLEHASH_FOUND)
|
||||
add_definitions("-DEIGEN_GOOGLEHASH_SUPPORT")
|
||||
@@ -134,7 +134,7 @@ ei_add_test(cxx11_tensor_roundings)
|
||||
ei_add_test(cxx11_tensor_layout_swap)
|
||||
ei_add_test(cxx11_tensor_io)
|
||||
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
|
||||
# This test requires __uint128_t which is only available on 64bit systems
|
||||
# This test requires __uint128_t which is only available on 64bit systems
|
||||
ei_add_test(cxx11_tensor_uint128)
|
||||
endif()
|
||||
endif()
|
||||
@@ -145,6 +145,7 @@ if(EIGEN_TEST_CXX11)
|
||||
ei_add_test_sycl(cxx11_tensor_forced_eval_sycl "-std=c++11")
|
||||
ei_add_test_sycl(cxx11_tensor_broadcast_sycl "-std=c++11")
|
||||
ei_add_test_sycl(cxx11_tensor_device_sycl "-std=c++11")
|
||||
ei_add_test_sycl(cxx11_tensor_reduction_sycl "-std=c++11")
|
||||
endif(EIGEN_TEST_SYCL)
|
||||
# It should be safe to always run these tests as there is some fallback code for
|
||||
# older compiler that don't support cxx11.
|
||||
|
||||
@@ -25,55 +25,50 @@ using Eigen::SyclDevice;
|
||||
using Eigen::Tensor;
|
||||
using Eigen::TensorMap;
|
||||
|
||||
// Types used in tests:
|
||||
using TestTensor = Tensor<float, 3>;
|
||||
using TestTensorMap = TensorMap<Tensor<float, 3>>;
|
||||
static void test_broadcast_sycl(){
|
||||
static void test_broadcast_sycl(const Eigen::SyclDevice &sycl_device){
|
||||
|
||||
cl::sycl::gpu_selector s;
|
||||
cl::sycl::queue q(s, [=](cl::sycl::exception_list l) {
|
||||
for (const auto& e : l) {
|
||||
try {
|
||||
std::rethrow_exception(e);
|
||||
} catch (cl::sycl::exception e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
// BROADCAST test:
|
||||
array<int, 4> in_range = {{2, 3, 5, 7}};
|
||||
array<int, 4> broadcasts = {{2, 3, 1, 4}};
|
||||
array<int, 4> out_range; // = in_range * broadcasts
|
||||
for (size_t i = 0; i < out_range.size(); ++i)
|
||||
out_range[i] = in_range[i] * broadcasts[i];
|
||||
|
||||
Tensor<float, 4> input(in_range);
|
||||
Tensor<float, 4> out(out_range);
|
||||
|
||||
for (size_t i = 0; i < in_range.size(); ++i)
|
||||
VERIFY_IS_EQUAL(out.dimension(i), out_range[i]);
|
||||
|
||||
|
||||
for (int i = 0; i < input.size(); ++i)
|
||||
input(i) = static_cast<float>(i);
|
||||
|
||||
float * gpu_in_data = static_cast<float*>(sycl_device.allocate(input.dimensions().TotalSize()*sizeof(float)));
|
||||
float * gpu_out_data = static_cast<float*>(sycl_device.allocate(out.dimensions().TotalSize()*sizeof(float)));
|
||||
|
||||
TensorMap<Tensor<float, 4>> gpu_in(gpu_in_data, in_range);
|
||||
TensorMap<Tensor<float, 4>> gpu_out(gpu_out_data, out_range);
|
||||
sycl_device.memcpyHostToDevice(gpu_in_data, input.data(),(input.dimensions().TotalSize())*sizeof(float));
|
||||
gpu_out.device(sycl_device) = gpu_in.broadcast(broadcasts);
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.dimensions().TotalSize())*sizeof(float));
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
for (int j = 0; j < 9; ++j) {
|
||||
for (int k = 0; k < 5; ++k) {
|
||||
for (int l = 0; l < 28; ++l) {
|
||||
VERIFY_IS_APPROX(input(i%2,j%3,k%5,l%7), out(i,j,k,l));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
SyclDevice sycl_device(q);
|
||||
// BROADCAST test:
|
||||
array<int, 4> in_range = {{2, 3, 5, 7}};
|
||||
array<int, in_range.size()> broadcasts = {{2, 3, 1, 4}};
|
||||
array<int, in_range.size()> out_range; // = in_range * broadcasts
|
||||
for (size_t i = 0; i < out_range.size(); ++i)
|
||||
out_range[i] = in_range[i] * broadcasts[i];
|
||||
|
||||
Tensor<float, in_range.size()> input(in_range);
|
||||
Tensor<float, out_range.size()> output(out_range);
|
||||
|
||||
for (int i = 0; i < input.size(); ++i)
|
||||
input(i) = static_cast<float>(i);
|
||||
|
||||
TensorMap<decltype(input)> gpu_in(input.data(), in_range);
|
||||
TensorMap<decltype(output)> gpu_out(output.data(), out_range);
|
||||
gpu_out.device(sycl_device) = gpu_in.broadcast(broadcasts);
|
||||
sycl_device.deallocate(output.data());
|
||||
|
||||
for (size_t i = 0; i < in_range.size(); ++i)
|
||||
VERIFY_IS_EQUAL(output.dimension(i), out_range[i]);
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
for (int j = 0; j < 9; ++j) {
|
||||
for (int k = 0; k < 5; ++k) {
|
||||
for (int l = 0; l < 28; ++l) {
|
||||
VERIFY_IS_APPROX(input(i%2,j%3,k%5,l%7), output(i,j,k,l));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("Broadcast Test Passed\n");
|
||||
}
|
||||
printf("Broadcast Test Passed\n");
|
||||
sycl_device.deallocate(gpu_in_data);
|
||||
sycl_device.deallocate(gpu_out_data);
|
||||
}
|
||||
|
||||
void test_cxx11_tensor_broadcast_sycl() {
|
||||
CALL_SUBTEST(test_broadcast_sycl());
|
||||
cl::sycl::gpu_selector s;
|
||||
Eigen::SyclDevice sycl_device(s);
|
||||
CALL_SUBTEST(test_broadcast_sycl(sycl_device));
|
||||
}
|
||||
|
||||
@@ -20,20 +20,12 @@
|
||||
#include "main.h"
|
||||
#include <unsupported/Eigen/CXX11/Tensor>
|
||||
|
||||
void test_device_sycl() {
|
||||
cl::sycl::gpu_selector s;
|
||||
cl::sycl::queue q(s, [=](cl::sycl::exception_list l) {
|
||||
for (const auto& e : l) {
|
||||
try {
|
||||
std::rethrow_exception(e);
|
||||
} catch (cl::sycl::exception e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
});
|
||||
Eigen::SyclDevice sycl_device(q);
|
||||
printf("Helo from ComputeCpp: Device Exists\n");
|
||||
void test_device_sycl(const Eigen::SyclDevice &sycl_device) {
|
||||
std::cout <<"Helo from ComputeCpp: the requested device exists and the device name is : "
|
||||
<< sycl_device.m_queue.get_device(). template get_info<cl::sycl::info::device::name>() <<std::endl;;
|
||||
}
|
||||
void test_cxx11_tensor_device_sycl() {
|
||||
CALL_SUBTEST(test_device_sycl());
|
||||
cl::sycl::gpu_selector s;
|
||||
Eigen::SyclDevice sycl_device(s);
|
||||
CALL_SUBTEST(test_device_sycl(sycl_device));
|
||||
}
|
||||
|
||||
@@ -22,18 +22,7 @@
|
||||
|
||||
using Eigen::Tensor;
|
||||
|
||||
void test_forced_eval_sycl() {
|
||||
cl::sycl::gpu_selector s;
|
||||
cl::sycl::queue q(s, [=](cl::sycl::exception_list l) {
|
||||
for (const auto& e : l) {
|
||||
try {
|
||||
std::rethrow_exception(e);
|
||||
} catch (cl::sycl::exception e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
});
|
||||
SyclDevice sycl_device(q);
|
||||
void test_forced_eval_sycl(const Eigen::SyclDevice &sycl_device) {
|
||||
|
||||
int sizeDim1 = 100;
|
||||
int sizeDim2 = 200;
|
||||
@@ -43,17 +32,22 @@ void test_forced_eval_sycl() {
|
||||
Eigen::Tensor<float, 3> in2(tensorRange);
|
||||
Eigen::Tensor<float, 3> out(tensorRange);
|
||||
|
||||
float * gpu_in1_data = static_cast<float*>(sycl_device.allocate(in1.dimensions().TotalSize()*sizeof(float)));
|
||||
float * gpu_in2_data = static_cast<float*>(sycl_device.allocate(in2.dimensions().TotalSize()*sizeof(float)));
|
||||
float * gpu_out_data = static_cast<float*>(sycl_device.allocate(out.dimensions().TotalSize()*sizeof(float)));
|
||||
|
||||
in1 = in1.random() + in1.constant(10.0f);
|
||||
in2 = in2.random() + in2.constant(10.0f);
|
||||
|
||||
// creating TensorMap from tensor
|
||||
Eigen::TensorMap<Eigen::Tensor<float, 3>> gpu_in1(in1.data(), tensorRange);
|
||||
Eigen::TensorMap<Eigen::Tensor<float, 3>> gpu_in2(in2.data(), tensorRange);
|
||||
Eigen::TensorMap<Eigen::Tensor<float, 3>> gpu_out(out.data(), tensorRange);
|
||||
|
||||
// creating TensorMap from tensor
|
||||
Eigen::TensorMap<Eigen::Tensor<float, 3>> gpu_in1(gpu_in1_data, tensorRange);
|
||||
Eigen::TensorMap<Eigen::Tensor<float, 3>> gpu_in2(gpu_in2_data, tensorRange);
|
||||
Eigen::TensorMap<Eigen::Tensor<float, 3>> gpu_out(gpu_out_data, tensorRange);
|
||||
sycl_device.memcpyHostToDevice(gpu_in1_data, in1.data(),(in1.dimensions().TotalSize())*sizeof(float));
|
||||
sycl_device.memcpyHostToDevice(gpu_in2_data, in2.data(),(in1.dimensions().TotalSize())*sizeof(float));
|
||||
/// c=(a+b)*b
|
||||
gpu_out.device(sycl_device) =(gpu_in1 + gpu_in2).eval() * gpu_in2;
|
||||
sycl_device.deallocate(out.data());
|
||||
gpu_out.device(sycl_device) =(gpu_in1 + gpu_in2).eval() * gpu_in2;
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.dimensions().TotalSize())*sizeof(float));
|
||||
for (int i = 0; i < sizeDim1; ++i) {
|
||||
for (int j = 0; j < sizeDim2; ++j) {
|
||||
for (int k = 0; k < sizeDim3; ++k) {
|
||||
@@ -62,7 +56,15 @@ void test_forced_eval_sycl() {
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("(a+b)*b Test Passed\n");
|
||||
printf("(a+b)*b Test Passed\n");
|
||||
sycl_device.deallocate(gpu_in1_data);
|
||||
sycl_device.deallocate(gpu_in2_data);
|
||||
sycl_device.deallocate(gpu_out_data);
|
||||
|
||||
}
|
||||
|
||||
void test_cxx11_tensor_forced_eval_sycl() { CALL_SUBTEST(test_forced_eval_sycl()); }
|
||||
void test_cxx11_tensor_forced_eval_sycl() {
|
||||
cl::sycl::gpu_selector s;
|
||||
Eigen::SyclDevice sycl_device(s);
|
||||
CALL_SUBTEST(test_forced_eval_sycl(sycl_device));
|
||||
}
|
||||
|
||||
138
unsupported/test/cxx11_tensor_reduction_sycl.cpp
Normal file
138
unsupported/test/cxx11_tensor_reduction_sycl.cpp
Normal file
@@ -0,0 +1,138 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra.
|
||||
//
|
||||
// Copyright (C) 2015
|
||||
// Mehdi Goli Codeplay Software Ltd.
|
||||
// Ralph Potter Codeplay Software Ltd.
|
||||
// Luke Iwanski Codeplay Software Ltd.
|
||||
// Contact: <eigen@codeplay.com>
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla
|
||||
// Public License v. 2.0. If a copy of the MPL was not distributed
|
||||
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#define EIGEN_TEST_NO_LONGDOUBLE
|
||||
#define EIGEN_TEST_NO_COMPLEX
|
||||
#define EIGEN_TEST_FUNC cxx11_tensor_reduction_sycl
|
||||
#define EIGEN_DEFAULT_DENSE_INDEX_TYPE int
|
||||
#define EIGEN_USE_SYCL
|
||||
|
||||
#include "main.h"
|
||||
#include <unsupported/Eigen/CXX11/Tensor>
|
||||
|
||||
|
||||
|
||||
static void test_full_reductions_sycl(const Eigen::SyclDevice& sycl_device) {
|
||||
|
||||
const int num_rows = 452;
|
||||
const int num_cols = 765;
|
||||
array<int, 2> tensorRange = {{num_rows, num_cols}};
|
||||
|
||||
Tensor<float, 2> in(tensorRange);
|
||||
Tensor<float, 0> full_redux;
|
||||
Tensor<float, 0> full_redux_gpu;
|
||||
|
||||
in.setRandom();
|
||||
|
||||
full_redux = in.sum();
|
||||
|
||||
float* gpu_in_data = static_cast<float*>(sycl_device.allocate(in.dimensions().TotalSize()*sizeof(float)));
|
||||
float* gpu_out_data =(float*)sycl_device.allocate(sizeof(float));
|
||||
|
||||
TensorMap<Tensor<float, 2> > in_gpu(gpu_in_data, tensorRange);
|
||||
TensorMap<Tensor<float, 0> > out_gpu(gpu_out_data);
|
||||
|
||||
sycl_device.memcpyHostToDevice(gpu_in_data, in.data(),(in.dimensions().TotalSize())*sizeof(float));
|
||||
out_gpu.device(sycl_device) = in_gpu.sum();
|
||||
sycl_device.memcpyDeviceToHost(full_redux_gpu.data(), gpu_out_data, sizeof(float));
|
||||
// Check that the CPU and GPU reductions return the same result.
|
||||
VERIFY_IS_APPROX(full_redux_gpu(), full_redux());
|
||||
|
||||
sycl_device.deallocate(gpu_in_data);
|
||||
sycl_device.deallocate(gpu_out_data);
|
||||
}
|
||||
|
||||
static void test_first_dim_reductions_sycl(const Eigen::SyclDevice& sycl_device) {
|
||||
|
||||
int dim_x = 145;
|
||||
int dim_y = 1;
|
||||
int dim_z = 67;
|
||||
|
||||
array<int, 3> tensorRange = {{dim_x, dim_y, dim_z}};
|
||||
Eigen::array<int, 1> red_axis;
|
||||
red_axis[0] = 0;
|
||||
array<int, 2> reduced_tensorRange = {{dim_y, dim_z}};
|
||||
|
||||
Tensor<float, 3> in(tensorRange);
|
||||
Tensor<float, 2> redux(reduced_tensorRange);
|
||||
Tensor<float, 2> redux_gpu(reduced_tensorRange);
|
||||
|
||||
in.setRandom();
|
||||
|
||||
redux= in.sum(red_axis);
|
||||
|
||||
float* gpu_in_data = static_cast<float*>(sycl_device.allocate(in.dimensions().TotalSize()*sizeof(float)));
|
||||
float* gpu_out_data = static_cast<float*>(sycl_device.allocate(redux_gpu.dimensions().TotalSize()*sizeof(float)));
|
||||
|
||||
TensorMap<Tensor<float, 3> > in_gpu(gpu_in_data, tensorRange);
|
||||
TensorMap<Tensor<float, 2> > out_gpu(gpu_out_data, reduced_tensorRange);
|
||||
|
||||
sycl_device.memcpyHostToDevice(gpu_in_data, in.data(),(in.dimensions().TotalSize())*sizeof(float));
|
||||
out_gpu.device(sycl_device) = in_gpu.sum(red_axis);
|
||||
sycl_device.memcpyDeviceToHost(redux_gpu.data(), gpu_out_data, redux_gpu.dimensions().TotalSize()*sizeof(float));
|
||||
|
||||
// Check that the CPU and GPU reductions return the same result.
|
||||
for(int j=0; j<reduced_tensorRange[0]; j++ )
|
||||
for(int k=0; k<reduced_tensorRange[1]; k++ )
|
||||
VERIFY_IS_APPROX(redux_gpu(j,k), redux(j,k));
|
||||
|
||||
sycl_device.deallocate(gpu_in_data);
|
||||
sycl_device.deallocate(gpu_out_data);
|
||||
}
|
||||
|
||||
static void test_last_dim_reductions_sycl(const Eigen::SyclDevice &sycl_device) {
|
||||
|
||||
int dim_x = 567;
|
||||
int dim_y = 1;
|
||||
int dim_z = 47;
|
||||
|
||||
array<int, 3> tensorRange = {{dim_x, dim_y, dim_z}};
|
||||
Eigen::array<int, 1> red_axis;
|
||||
red_axis[0] = 2;
|
||||
array<int, 2> reduced_tensorRange = {{dim_x, dim_y}};
|
||||
|
||||
Tensor<float, 3> in(tensorRange);
|
||||
Tensor<float, 2> redux(reduced_tensorRange);
|
||||
Tensor<float, 2> redux_gpu(reduced_tensorRange);
|
||||
|
||||
in.setRandom();
|
||||
|
||||
redux= in.sum(red_axis);
|
||||
|
||||
float* gpu_in_data = static_cast<float*>(sycl_device.allocate(in.dimensions().TotalSize()*sizeof(float)));
|
||||
float* gpu_out_data = static_cast<float*>(sycl_device.allocate(redux_gpu.dimensions().TotalSize()*sizeof(float)));
|
||||
|
||||
TensorMap<Tensor<float, 3> > in_gpu(gpu_in_data, tensorRange);
|
||||
TensorMap<Tensor<float, 2> > out_gpu(gpu_out_data, reduced_tensorRange);
|
||||
|
||||
sycl_device.memcpyHostToDevice(gpu_in_data, in.data(),(in.dimensions().TotalSize())*sizeof(float));
|
||||
out_gpu.device(sycl_device) = in_gpu.sum(red_axis);
|
||||
sycl_device.memcpyDeviceToHost(redux_gpu.data(), gpu_out_data, redux_gpu.dimensions().TotalSize()*sizeof(float));
|
||||
// Check that the CPU and GPU reductions return the same result.
|
||||
for(int j=0; j<reduced_tensorRange[0]; j++ )
|
||||
for(int k=0; k<reduced_tensorRange[1]; k++ )
|
||||
VERIFY_IS_APPROX(redux_gpu(j,k), redux(j,k));
|
||||
|
||||
sycl_device.deallocate(gpu_in_data);
|
||||
sycl_device.deallocate(gpu_out_data);
|
||||
|
||||
}
|
||||
|
||||
void test_cxx11_tensor_reduction_sycl() {
|
||||
cl::sycl::gpu_selector s;
|
||||
Eigen::SyclDevice sycl_device(s);
|
||||
CALL_SUBTEST((test_full_reductions_sycl(sycl_device)));
|
||||
CALL_SUBTEST((test_first_dim_reductions_sycl(sycl_device)));
|
||||
CALL_SUBTEST((test_last_dim_reductions_sycl(sycl_device)));
|
||||
|
||||
}
|
||||
@@ -27,42 +27,33 @@ using Eigen::SyclDevice;
|
||||
using Eigen::Tensor;
|
||||
using Eigen::TensorMap;
|
||||
|
||||
// Types used in tests:
|
||||
using TestTensor = Tensor<float, 3>;
|
||||
using TestTensorMap = TensorMap<Tensor<float, 3>>;
|
||||
|
||||
void test_sycl_cpu() {
|
||||
cl::sycl::gpu_selector s;
|
||||
cl::sycl::queue q(s, [=](cl::sycl::exception_list l) {
|
||||
for (const auto& e : l) {
|
||||
try {
|
||||
std::rethrow_exception(e);
|
||||
} catch (cl::sycl::exception e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
});
|
||||
SyclDevice sycl_device(q);
|
||||
void test_sycl_cpu(const Eigen::SyclDevice &sycl_device) {
|
||||
|
||||
int sizeDim1 = 100;
|
||||
int sizeDim2 = 100;
|
||||
int sizeDim3 = 100;
|
||||
array<int, 3> tensorRange = {{sizeDim1, sizeDim2, sizeDim3}};
|
||||
TestTensor in1(tensorRange);
|
||||
TestTensor in2(tensorRange);
|
||||
TestTensor in3(tensorRange);
|
||||
TestTensor out(tensorRange);
|
||||
in1 = in1.random();
|
||||
Tensor<float, 3> in1(tensorRange);
|
||||
Tensor<float, 3> in2(tensorRange);
|
||||
Tensor<float, 3> in3(tensorRange);
|
||||
Tensor<float, 3> out(tensorRange);
|
||||
|
||||
in2 = in2.random();
|
||||
in3 = in3.random();
|
||||
TestTensorMap gpu_in1(in1.data(), tensorRange);
|
||||
TestTensorMap gpu_in2(in2.data(), tensorRange);
|
||||
TestTensorMap gpu_in3(in3.data(), tensorRange);
|
||||
TestTensorMap gpu_out(out.data(), tensorRange);
|
||||
|
||||
float * gpu_in1_data = static_cast<float*>(sycl_device.allocate(in1.dimensions().TotalSize()*sizeof(float)));
|
||||
float * gpu_in2_data = static_cast<float*>(sycl_device.allocate(in2.dimensions().TotalSize()*sizeof(float)));
|
||||
float * gpu_in3_data = static_cast<float*>(sycl_device.allocate(in3.dimensions().TotalSize()*sizeof(float)));
|
||||
float * gpu_out_data = static_cast<float*>(sycl_device.allocate(out.dimensions().TotalSize()*sizeof(float)));
|
||||
|
||||
TensorMap<Tensor<float, 3>> gpu_in1(gpu_in1_data, tensorRange);
|
||||
TensorMap<Tensor<float, 3>> gpu_in2(gpu_in2_data, tensorRange);
|
||||
TensorMap<Tensor<float, 3>> gpu_in3(gpu_in3_data, tensorRange);
|
||||
TensorMap<Tensor<float, 3>> gpu_out(gpu_out_data, tensorRange);
|
||||
|
||||
/// a=1.2f
|
||||
gpu_in1.device(sycl_device) = gpu_in1.constant(1.2f);
|
||||
sycl_device.deallocate(in1.data());
|
||||
sycl_device.memcpyDeviceToHost(in1.data(), gpu_in1_data ,(in1.dimensions().TotalSize())*sizeof(float));
|
||||
for (int i = 0; i < sizeDim1; ++i) {
|
||||
for (int j = 0; j < sizeDim2; ++j) {
|
||||
for (int k = 0; k < sizeDim3; ++k) {
|
||||
@@ -74,7 +65,7 @@ void test_sycl_cpu() {
|
||||
|
||||
/// a=b*1.2f
|
||||
gpu_out.device(sycl_device) = gpu_in1 * 1.2f;
|
||||
sycl_device.deallocate(out.data());
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data ,(out.dimensions().TotalSize())*sizeof(float));
|
||||
for (int i = 0; i < sizeDim1; ++i) {
|
||||
for (int j = 0; j < sizeDim2; ++j) {
|
||||
for (int k = 0; k < sizeDim3; ++k) {
|
||||
@@ -86,8 +77,9 @@ void test_sycl_cpu() {
|
||||
printf("a=b*1.2f Test Passed\n");
|
||||
|
||||
/// c=a*b
|
||||
sycl_device.memcpyHostToDevice(gpu_in2_data, in2.data(),(in2.dimensions().TotalSize())*sizeof(float));
|
||||
gpu_out.device(sycl_device) = gpu_in1 * gpu_in2;
|
||||
sycl_device.deallocate(out.data());
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.dimensions().TotalSize())*sizeof(float));
|
||||
for (int i = 0; i < sizeDim1; ++i) {
|
||||
for (int j = 0; j < sizeDim2; ++j) {
|
||||
for (int k = 0; k < sizeDim3; ++k) {
|
||||
@@ -101,7 +93,7 @@ void test_sycl_cpu() {
|
||||
|
||||
/// c=a+b
|
||||
gpu_out.device(sycl_device) = gpu_in1 + gpu_in2;
|
||||
sycl_device.deallocate(out.data());
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.dimensions().TotalSize())*sizeof(float));
|
||||
for (int i = 0; i < sizeDim1; ++i) {
|
||||
for (int j = 0; j < sizeDim2; ++j) {
|
||||
for (int k = 0; k < sizeDim3; ++k) {
|
||||
@@ -115,7 +107,7 @@ void test_sycl_cpu() {
|
||||
|
||||
/// c=a*a
|
||||
gpu_out.device(sycl_device) = gpu_in1 * gpu_in1;
|
||||
sycl_device.deallocate(out.data());
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.dimensions().TotalSize())*sizeof(float));
|
||||
for (int i = 0; i < sizeDim1; ++i) {
|
||||
for (int j = 0; j < sizeDim2; ++j) {
|
||||
for (int k = 0; k < sizeDim3; ++k) {
|
||||
@@ -125,12 +117,11 @@ void test_sycl_cpu() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("c= a*a Test Passed\n");
|
||||
|
||||
//a*3.14f + b*2.7f
|
||||
gpu_out.device(sycl_device) = gpu_in1 * gpu_in1.constant(3.14f) + gpu_in2 * gpu_in2.constant(2.7f);
|
||||
sycl_device.deallocate(out.data());
|
||||
sycl_device.memcpyDeviceToHost(out.data(),gpu_out_data,(out.dimensions().TotalSize())*sizeof(float));
|
||||
for (int i = 0; i < sizeDim1; ++i) {
|
||||
for (int j = 0; j < sizeDim2; ++j) {
|
||||
for (int k = 0; k < sizeDim3; ++k) {
|
||||
@@ -143,8 +134,9 @@ void test_sycl_cpu() {
|
||||
printf("a*3.14f + b*2.7f Test Passed\n");
|
||||
|
||||
///d= (a>0.5? b:c)
|
||||
sycl_device.memcpyHostToDevice(gpu_in3_data, in3.data(),(in3.dimensions().TotalSize())*sizeof(float));
|
||||
gpu_out.device(sycl_device) =(gpu_in1 > gpu_in1.constant(0.5f)).select(gpu_in2, gpu_in3);
|
||||
sycl_device.deallocate(out.data());
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.dimensions().TotalSize())*sizeof(float));
|
||||
for (int i = 0; i < sizeDim1; ++i) {
|
||||
for (int j = 0; j < sizeDim2; ++j) {
|
||||
for (int k = 0; k < sizeDim3; ++k) {
|
||||
@@ -155,8 +147,13 @@ void test_sycl_cpu() {
|
||||
}
|
||||
}
|
||||
printf("d= (a>0.5? b:c) Test Passed\n");
|
||||
|
||||
sycl_device.deallocate(gpu_in1_data);
|
||||
sycl_device.deallocate(gpu_in2_data);
|
||||
sycl_device.deallocate(gpu_in3_data);
|
||||
sycl_device.deallocate(gpu_out_data);
|
||||
}
|
||||
void test_cxx11_tensor_sycl() {
|
||||
CALL_SUBTEST(test_sycl_cpu());
|
||||
cl::sycl::gpu_selector s;
|
||||
Eigen::SyclDevice sycl_device(s);
|
||||
CALL_SUBTEST(test_sycl_cpu(sycl_device));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user