mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Modifying TensorDeviceSycl.h to always create buffer of type uint8_t and convert them to the actual type at the execution on the device; adding the queue interface class to separate the lifespan of sycl queue and buffers,created for that queue, from Eigen::SyclDevice; modifying sycl tests to support the evaluation of the results for both row major and column major data layout on all different devices that are supported by Sycl{CPU; GPU; and Host}.
This commit is contained in:
@@ -25,38 +25,47 @@ using Eigen::SyclDevice;
|
||||
using Eigen::Tensor;
|
||||
using Eigen::TensorMap;
|
||||
|
||||
template <typename DataType, int DataLayout>
|
||||
static void test_broadcast_sycl_fixed(const Eigen::SyclDevice &sycl_device){
|
||||
|
||||
// BROADCAST test:
|
||||
array<int, 4> in_range = {{2, 3, 5, 7}};
|
||||
array<int, 4> broadcasts = {{2, 3, 1, 4}};
|
||||
int inDim1=2;
|
||||
int inDim2=3;
|
||||
int inDim3=5;
|
||||
int inDim4=7;
|
||||
int bDim1=2;
|
||||
int bDim2=3;
|
||||
int bDim3=1;
|
||||
int bDim4=4;
|
||||
array<int, 4> in_range = {{inDim1, inDim2, inDim3, inDim4}};
|
||||
array<int, 4> broadcasts = {{bDim1, bDim2, bDim3, bDim4}};
|
||||
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);
|
||||
Tensor<DataType, 4, DataLayout> input(in_range);
|
||||
Tensor<DataType, 4, DataLayout> 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);
|
||||
input(i) = static_cast<DataType>(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)));
|
||||
DataType * gpu_in_data = static_cast<DataType*>(sycl_device.allocate(input.dimensions().TotalSize()*sizeof(DataType)));
|
||||
DataType * gpu_out_data = static_cast<DataType*>(sycl_device.allocate(out.dimensions().TotalSize()*sizeof(DataType)));
|
||||
|
||||
TensorMap<TensorFixedSize<float, Sizes<2, 3, 5, 7>>> 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));
|
||||
TensorMap<TensorFixedSize<DataType, Sizes<2, 3, 5, 7>, DataLayout>> gpu_in(gpu_in_data, in_range);
|
||||
TensorMap<Tensor<DataType, 4, DataLayout>> gpu_out(gpu_out_data, out_range);
|
||||
sycl_device.memcpyHostToDevice(gpu_in_data, input.data(),(input.dimensions().TotalSize())*sizeof(DataType));
|
||||
gpu_out.device(sycl_device) = gpu_in.broadcast(broadcasts);
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.dimensions().TotalSize())*sizeof(float));
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.dimensions().TotalSize())*sizeof(DataType));
|
||||
|
||||
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) {
|
||||
for (int i = 0; i < inDim1*bDim1; ++i) {
|
||||
for (int j = 0; j < inDim2*bDim2; ++j) {
|
||||
for (int k = 0; k < inDim3*bDim3; ++k) {
|
||||
for (int l = 0; l < inDim4*bDim4; ++l) {
|
||||
VERIFY_IS_APPROX(input(i%2,j%3,k%5,l%7), out(i,j,k,l));
|
||||
}
|
||||
}
|
||||
@@ -67,40 +76,48 @@ static void test_broadcast_sycl_fixed(const Eigen::SyclDevice &sycl_device){
|
||||
sycl_device.deallocate(gpu_out_data);
|
||||
}
|
||||
|
||||
|
||||
template <typename DataType, int DataLayout>
|
||||
static void test_broadcast_sycl(const Eigen::SyclDevice &sycl_device){
|
||||
|
||||
// BROADCAST test:
|
||||
array<int, 4> in_range = {{2, 3, 5, 7}};
|
||||
array<int, 4> broadcasts = {{2, 3, 1, 4}};
|
||||
int inDim1=2;
|
||||
int inDim2=3;
|
||||
int inDim3=5;
|
||||
int inDim4=7;
|
||||
int bDim1=2;
|
||||
int bDim2=3;
|
||||
int bDim3=1;
|
||||
int bDim4=4;
|
||||
array<int, 4> in_range = {{inDim1, inDim2, inDim3, inDim4}};
|
||||
array<int, 4> broadcasts = {{bDim1, bDim2, bDim3, bDim4}};
|
||||
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);
|
||||
Tensor<DataType, 4, DataLayout> input(in_range);
|
||||
Tensor<DataType, 4, DataLayout> 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);
|
||||
input(i) = static_cast<DataType>(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)));
|
||||
DataType * gpu_in_data = static_cast<DataType*>(sycl_device.allocate(input.dimensions().TotalSize()*sizeof(DataType)));
|
||||
DataType * gpu_out_data = static_cast<DataType*>(sycl_device.allocate(out.dimensions().TotalSize()*sizeof(DataType)));
|
||||
|
||||
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));
|
||||
TensorMap<Tensor<DataType, 4, DataLayout>> gpu_in(gpu_in_data, in_range);
|
||||
TensorMap<Tensor<DataType, 4, DataLayout>> gpu_out(gpu_out_data, out_range);
|
||||
sycl_device.memcpyHostToDevice(gpu_in_data, input.data(),(input.dimensions().TotalSize())*sizeof(DataType));
|
||||
gpu_out.device(sycl_device) = gpu_in.broadcast(broadcasts);
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.dimensions().TotalSize())*sizeof(float));
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.dimensions().TotalSize())*sizeof(DataType));
|
||||
|
||||
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));
|
||||
for (int i = 0; i < inDim1*bDim1; ++i) {
|
||||
for (int j = 0; j < inDim2*bDim2; ++j) {
|
||||
for (int k = 0; k < inDim3*bDim3; ++k) {
|
||||
for (int l = 0; l < inDim4*bDim4; ++l) {
|
||||
VERIFY_IS_APPROX(input(i%inDim1,j%inDim2,k%inDim3,l%inDim4), out(i,j,k,l));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,10 +127,21 @@ static void test_broadcast_sycl(const Eigen::SyclDevice &sycl_device){
|
||||
sycl_device.deallocate(gpu_out_data);
|
||||
}
|
||||
|
||||
template<typename DataType, typename dev_Selector> void sycl_broadcast_test_per_device(dev_Selector s){
|
||||
QueueInterface queueInterface(s);
|
||||
auto sycl_device = Eigen::SyclDevice(&queueInterface);
|
||||
test_broadcast_sycl_fixed<DataType, RowMajor>(sycl_device);
|
||||
test_broadcast_sycl<DataType, RowMajor>(sycl_device);
|
||||
test_broadcast_sycl_fixed<DataType, ColMajor>(sycl_device);
|
||||
test_broadcast_sycl<DataType, ColMajor>(sycl_device);
|
||||
}
|
||||
|
||||
void test_cxx11_tensor_broadcast_sycl() {
|
||||
cl::sycl::gpu_selector s;
|
||||
Eigen::SyclDevice sycl_device(s);
|
||||
CALL_SUBTEST(test_broadcast_sycl_fixed(sycl_device));
|
||||
CALL_SUBTEST(test_broadcast_sycl(sycl_device));
|
||||
printf("Test on GPU: OpenCL\n");
|
||||
CALL_SUBTEST(sycl_broadcast_test_per_device<float>((cl::sycl::gpu_selector())));
|
||||
printf("repeating the test on CPU: OpenCL\n");
|
||||
CALL_SUBTEST(sycl_broadcast_test_per_device<float>((cl::sycl::cpu_selector())));
|
||||
printf("repeating the test on CPU: HOST\n");
|
||||
CALL_SUBTEST(sycl_broadcast_test_per_device<float>((cl::sycl::host_selector())));
|
||||
printf("Test Passed******************\n" );
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ template <typename T> T inverse(T x) { return 1 / x; }
|
||||
|
||||
#define TEST_IS_THAT_RETURNS_BOOL(SCALAR, FUNC) \
|
||||
{ \
|
||||
/* out OPERATOR in.FUNC() */ \
|
||||
/* out = in.FUNC() */ \
|
||||
Tensor<SCALAR, 3> in(tensorRange); \
|
||||
Tensor<bool, 3> out(tensorRange); \
|
||||
in = in.random() + static_cast<SCALAR>(0.01); \
|
||||
@@ -136,11 +136,13 @@ static void test_builtin_unary_sycl(const Eigen::SyclDevice &sycl_device) {
|
||||
array<int, 3> tensorRange = {{sizeDim1, sizeDim2, sizeDim3}};
|
||||
|
||||
TEST_UNARY_BUILTINS(float)
|
||||
/// your GPU must support double. Otherwise, disable the double test.
|
||||
TEST_UNARY_BUILTINS(double)
|
||||
}
|
||||
|
||||
void test_cxx11_tensor_builtins_sycl() {
|
||||
cl::sycl::gpu_selector s;
|
||||
Eigen::SyclDevice sycl_device(s);
|
||||
QueueInterface queueInterface(s);
|
||||
Eigen::SyclDevice sycl_device(&queueInterface);
|
||||
CALL_SUBTEST(test_builtin_unary_sycl(sycl_device));
|
||||
}
|
||||
|
||||
@@ -21,42 +21,59 @@
|
||||
#include <unsupported/Eigen/CXX11/Tensor>
|
||||
#include<stdint.h>
|
||||
|
||||
void test_device_memory(const Eigen::SyclDevice &sycl_device) {
|
||||
std::cout << "Running on: "
|
||||
<< sycl_device.m_queue.get_device(). template get_info<cl::sycl::info::device::name>()
|
||||
<< std::endl;
|
||||
template <typename DataType, int DataLayout>
|
||||
void test_device_sycl(const Eigen::SyclDevice &sycl_device) {
|
||||
std::cout <<"Hello from ComputeCpp: the requested device exists and the device name is : "
|
||||
<< sycl_device.sycl_queue().get_device(). template get_info<cl::sycl::info::device::name>() <<std::endl;
|
||||
int sizeDim1 = 100;
|
||||
|
||||
array<int, 1> tensorRange = {{sizeDim1}};
|
||||
Tensor<int, 1> in(tensorRange);
|
||||
Tensor<int, 1> in1(tensorRange);
|
||||
memset(in1.data(), 1,in1.size()*sizeof(int));
|
||||
int* gpu_in_data = static_cast<int*>(sycl_device.allocate(in.size()*sizeof(int)));
|
||||
sycl_device.memset(gpu_in_data, 1, in.size()*sizeof(int) );
|
||||
sycl_device.memcpyDeviceToHost(in.data(), gpu_in_data, in.size()*sizeof(int) );
|
||||
Tensor<DataType, 1, DataLayout> in(tensorRange);
|
||||
Tensor<DataType, 1, DataLayout> in1(tensorRange);
|
||||
memset(in1.data(), 1,in1.size()*sizeof(DataType));
|
||||
DataType * gpu_in_data = static_cast<DataType*>(sycl_device.allocate(in.size()*sizeof(DataType)));
|
||||
sycl_device.memset(gpu_in_data, 1,in.size()*sizeof(DataType) );
|
||||
sycl_device.memcpyDeviceToHost(in.data(), gpu_in_data, in.size()*sizeof(DataType) );
|
||||
for (int i=0; i<in.size(); i++) {
|
||||
VERIFY_IS_APPROX(in(i), in1(i));
|
||||
}
|
||||
sycl_device.deallocate(gpu_in_data);
|
||||
}
|
||||
|
||||
|
||||
template <typename DataType, int DataLayout>
|
||||
void test_device_exceptions(const Eigen::SyclDevice &sycl_device) {
|
||||
VERIFY(sycl_device.ok());
|
||||
array<int, 1> tensorDims = {{100}};
|
||||
int* gpu_data = static_cast<int*>(sycl_device.allocate(100*sizeof(int)));
|
||||
TensorMap<Tensor<int, 1>> in(gpu_data, tensorDims);
|
||||
TensorMap<Tensor<int, 1>> out(gpu_data, tensorDims);
|
||||
out.device(sycl_device) = in / in.constant(0);
|
||||
VERIFY(!sycl_device.ok());
|
||||
bool threw_exception = false;
|
||||
int sizeDim1 = 100;
|
||||
array<int, 1> tensorDims = {{sizeDim1}};
|
||||
DataType* gpu_data = static_cast<DataType*>(sycl_device.allocate(sizeDim1*sizeof(DataType)));
|
||||
TensorMap<Tensor<DataType, 1,DataLayout>> in(gpu_data, tensorDims);
|
||||
TensorMap<Tensor<DataType, 1,DataLayout>> out(gpu_data, tensorDims);
|
||||
try {
|
||||
out.device(sycl_device) = in / in.constant(0);
|
||||
} catch(...) {
|
||||
threw_exception = true;
|
||||
}
|
||||
VERIFY(threw_exception);
|
||||
sycl_device.deallocate(gpu_data);
|
||||
}
|
||||
|
||||
template<typename DataType, typename dev_Selector> void sycl_device_test_per_device(dev_Selector s){
|
||||
QueueInterface queueInterface(s);
|
||||
auto sycl_device = Eigen::SyclDevice(&queueInterface);
|
||||
test_device_sycl<DataType, RowMajor>(sycl_device);
|
||||
test_device_sycl<DataType, ColMajor>(sycl_device);
|
||||
/// this test throw an exeption. enable it if you want to see the exception
|
||||
// test_device_exceptions<DataType, RowMajor>(sycl_device);
|
||||
/// this test throw an exeption. enable it if you want to see the exception
|
||||
// test_device_exceptions<DataType, ColMajor>(sycl_device);
|
||||
|
||||
}
|
||||
|
||||
void test_cxx11_tensor_device_sycl() {
|
||||
cl::sycl::gpu_selector s;
|
||||
Eigen::SyclDevice sycl_device(s);
|
||||
CALL_SUBTEST(test_device_memory(sycl_device));
|
||||
// This deadlocks
|
||||
//CALL_SUBTEST(test_device_exceptions(sycl_device));
|
||||
printf("Test on GPU: OpenCL\n");
|
||||
CALL_SUBTEST(sycl_device_test_per_device<int>((cl::sycl::gpu_selector())));
|
||||
printf("repeating the test on CPU: OpenCL\n");
|
||||
CALL_SUBTEST(sycl_device_test_per_device<int>((cl::sycl::cpu_selector())));
|
||||
printf("repeating the test on CPU: HOST\n");
|
||||
CALL_SUBTEST(sycl_device_test_per_device<int>((cl::sycl::host_selector())));
|
||||
printf("Test Passed******************\n" );
|
||||
}
|
||||
|
||||
@@ -21,33 +21,33 @@
|
||||
#include <unsupported/Eigen/CXX11/Tensor>
|
||||
|
||||
using Eigen::Tensor;
|
||||
|
||||
template <typename DataType, int DataLayout>
|
||||
void test_forced_eval_sycl(const Eigen::SyclDevice &sycl_device) {
|
||||
|
||||
int sizeDim1 = 100;
|
||||
int sizeDim2 = 200;
|
||||
int sizeDim3 = 200;
|
||||
int sizeDim2 = 20;
|
||||
int sizeDim3 = 20;
|
||||
Eigen::array<int, 3> tensorRange = {{sizeDim1, sizeDim2, sizeDim3}};
|
||||
Eigen::Tensor<float, 3> in1(tensorRange);
|
||||
Eigen::Tensor<float, 3> in2(tensorRange);
|
||||
Eigen::Tensor<float, 3> out(tensorRange);
|
||||
Eigen::Tensor<DataType, 3, DataLayout> in1(tensorRange);
|
||||
Eigen::Tensor<DataType, 3, DataLayout> in2(tensorRange);
|
||||
Eigen::Tensor<DataType, 3, DataLayout> 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)));
|
||||
DataType * gpu_in1_data = static_cast<DataType*>(sycl_device.allocate(in1.dimensions().TotalSize()*sizeof(DataType)));
|
||||
DataType * gpu_in2_data = static_cast<DataType*>(sycl_device.allocate(in2.dimensions().TotalSize()*sizeof(DataType)));
|
||||
DataType * gpu_out_data = static_cast<DataType*>(sycl_device.allocate(out.dimensions().TotalSize()*sizeof(DataType)));
|
||||
|
||||
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(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));
|
||||
Eigen::TensorMap<Eigen::Tensor<DataType, 3, DataLayout>> gpu_in1(gpu_in1_data, tensorRange);
|
||||
Eigen::TensorMap<Eigen::Tensor<DataType, 3, DataLayout>> gpu_in2(gpu_in2_data, tensorRange);
|
||||
Eigen::TensorMap<Eigen::Tensor<DataType, 3, DataLayout>> gpu_out(gpu_out_data, tensorRange);
|
||||
sycl_device.memcpyHostToDevice(gpu_in1_data, in1.data(),(in1.dimensions().TotalSize())*sizeof(DataType));
|
||||
sycl_device.memcpyHostToDevice(gpu_in2_data, in2.data(),(in1.dimensions().TotalSize())*sizeof(DataType));
|
||||
/// c=(a+b)*b
|
||||
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));
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.dimensions().TotalSize())*sizeof(DataType));
|
||||
for (int i = 0; i < sizeDim1; ++i) {
|
||||
for (int j = 0; j < sizeDim2; ++j) {
|
||||
for (int k = 0; k < sizeDim3; ++k) {
|
||||
@@ -63,8 +63,19 @@ void test_forced_eval_sycl(const Eigen::SyclDevice &sycl_device) {
|
||||
|
||||
}
|
||||
|
||||
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));
|
||||
template <typename DataType, typename Dev_selector> void tensorForced_evalperDevice(Dev_selector s){
|
||||
QueueInterface queueInterface(s);
|
||||
auto sycl_device = Eigen::SyclDevice(&queueInterface);
|
||||
test_forced_eval_sycl<DataType, RowMajor>(sycl_device);
|
||||
test_forced_eval_sycl<DataType, ColMajor>(sycl_device);
|
||||
}
|
||||
void test_cxx11_tensor_forced_eval_sycl() {
|
||||
|
||||
printf("Test on GPU: OpenCL\n");
|
||||
CALL_SUBTEST(tensorForced_evalperDevice<float>((cl::sycl::gpu_selector())));
|
||||
printf("repeating the test on CPU: OpenCL\n");
|
||||
CALL_SUBTEST(tensorForced_evalperDevice<float>((cl::sycl::cpu_selector())));
|
||||
printf("repeating the test on CPU: HOST\n");
|
||||
CALL_SUBTEST(tensorForced_evalperDevice<float>((cl::sycl::host_selector())));
|
||||
printf("Test Passed******************\n" );
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ using Eigen::SyclDevice;
|
||||
using Eigen::Tensor;
|
||||
using Eigen::TensorMap;
|
||||
|
||||
|
||||
template <typename DataType, int DataLayout>
|
||||
static void test_simple_slice(const Eigen::SyclDevice &sycl_device)
|
||||
{
|
||||
int sizeDim1 = 2;
|
||||
@@ -37,31 +37,31 @@ static void test_simple_slice(const Eigen::SyclDevice &sycl_device)
|
||||
int sizeDim4 = 7;
|
||||
int sizeDim5 = 11;
|
||||
array<int, 5> tensorRange = {{sizeDim1, sizeDim2, sizeDim3, sizeDim4, sizeDim5}};
|
||||
Tensor<float, 5> tensor(tensorRange);
|
||||
Tensor<DataType, 5,DataLayout> tensor(tensorRange);
|
||||
tensor.setRandom();
|
||||
array<int, 5> slice1_range ={{1, 1, 1, 1, 1}};
|
||||
Tensor<float, 5> slice1(slice1_range);
|
||||
Tensor<DataType, 5,DataLayout> slice1(slice1_range);
|
||||
|
||||
float* gpu_data1 = static_cast<float*>(sycl_device.allocate(tensor.size()*sizeof(float)));
|
||||
float* gpu_data2 = static_cast<float*>(sycl_device.allocate(slice1.size()*sizeof(float)));
|
||||
TensorMap<Tensor<float, 5>> gpu1(gpu_data1, tensorRange);
|
||||
TensorMap<Tensor<float, 5>> gpu2(gpu_data2, slice1_range);
|
||||
DataType* gpu_data1 = static_cast<DataType*>(sycl_device.allocate(tensor.size()*sizeof(DataType)));
|
||||
DataType* gpu_data2 = static_cast<DataType*>(sycl_device.allocate(slice1.size()*sizeof(DataType)));
|
||||
TensorMap<Tensor<DataType, 5,DataLayout>> gpu1(gpu_data1, tensorRange);
|
||||
TensorMap<Tensor<DataType, 5,DataLayout>> gpu2(gpu_data2, slice1_range);
|
||||
Eigen::DSizes<ptrdiff_t, 5> indices(1,2,3,4,5);
|
||||
Eigen::DSizes<ptrdiff_t, 5> sizes(1,1,1,1,1);
|
||||
sycl_device.memcpyHostToDevice(gpu_data1, tensor.data(),(tensor.size())*sizeof(float));
|
||||
sycl_device.memcpyHostToDevice(gpu_data1, tensor.data(),(tensor.size())*sizeof(DataType));
|
||||
gpu2.device(sycl_device)=gpu1.slice(indices, sizes);
|
||||
sycl_device.memcpyDeviceToHost(slice1.data(), gpu_data2,(slice1.size())*sizeof(float));
|
||||
sycl_device.memcpyDeviceToHost(slice1.data(), gpu_data2,(slice1.size())*sizeof(DataType));
|
||||
VERIFY_IS_EQUAL(slice1(0,0,0,0,0), tensor(1,2,3,4,5));
|
||||
|
||||
|
||||
array<int, 5> slice2_range ={{1,1,2,2,3}};
|
||||
Tensor<float, 5> slice2(slice2_range);
|
||||
float* gpu_data3 = static_cast<float*>(sycl_device.allocate(slice2.size()*sizeof(float)));
|
||||
TensorMap<Tensor<float, 5>> gpu3(gpu_data3, slice2_range);
|
||||
Tensor<DataType, 5,DataLayout> slice2(slice2_range);
|
||||
DataType* gpu_data3 = static_cast<DataType*>(sycl_device.allocate(slice2.size()*sizeof(DataType)));
|
||||
TensorMap<Tensor<DataType, 5,DataLayout>> gpu3(gpu_data3, slice2_range);
|
||||
Eigen::DSizes<ptrdiff_t, 5> indices2(1,1,3,4,5);
|
||||
Eigen::DSizes<ptrdiff_t, 5> sizes2(1,1,2,2,3);
|
||||
gpu3.device(sycl_device)=gpu1.slice(indices2, sizes2);
|
||||
sycl_device.memcpyDeviceToHost(slice2.data(), gpu_data3,(slice2.size())*sizeof(float));
|
||||
sycl_device.memcpyDeviceToHost(slice2.data(), gpu_data3,(slice2.size())*sizeof(DataType));
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
for (int j = 0; j < 2; ++j) {
|
||||
for (int k = 0; k < 3; ++k) {
|
||||
@@ -74,11 +74,22 @@ static void test_simple_slice(const Eigen::SyclDevice &sycl_device)
|
||||
sycl_device.deallocate(gpu_data3);
|
||||
}
|
||||
|
||||
template<typename DataType, typename dev_Selector> void sycl_slicing_test_per_device(dev_Selector s){
|
||||
QueueInterface queueInterface(s);
|
||||
auto sycl_device = Eigen::SyclDevice(&queueInterface);
|
||||
test_simple_slice<DataType, RowMajor>(sycl_device);
|
||||
test_simple_slice<DataType, ColMajor>(sycl_device);
|
||||
}
|
||||
void test_cxx11_tensor_morphing_sycl()
|
||||
{
|
||||
/// Currentlly it only works on cpu. Adding GPU cause LLVM ERROR in cunstructing OpenCL Kernel at runtime.
|
||||
cl::sycl::cpu_selector s;
|
||||
Eigen::SyclDevice sycl_device(s);
|
||||
CALL_SUBTEST(test_simple_slice(sycl_device));
|
||||
// printf("Test on GPU: OpenCL\n");
|
||||
// CALL_SUBTEST(sycl_device_test_per_device((cl::sycl::gpu_selector())));
|
||||
printf("repeating the test on CPU: OpenCL\n");
|
||||
CALL_SUBTEST(sycl_slicing_test_per_device<float>((cl::sycl::cpu_selector())));
|
||||
printf("repeating the test on CPU: HOST\n");
|
||||
CALL_SUBTEST(sycl_slicing_test_per_device<float>((cl::sycl::host_selector())));
|
||||
printf("Test Passed******************\n" );
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -21,37 +21,37 @@
|
||||
#include <unsupported/Eigen/CXX11/Tensor>
|
||||
|
||||
|
||||
|
||||
template <typename DataType, int DataLayout>
|
||||
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;
|
||||
Tensor<DataType, 2, DataLayout> in(tensorRange);
|
||||
Tensor<DataType, 0, DataLayout> full_redux;
|
||||
Tensor<DataType, 0, DataLayout> 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));
|
||||
DataType* gpu_in_data = static_cast<DataType*>(sycl_device.allocate(in.dimensions().TotalSize()*sizeof(DataType)));
|
||||
DataType* gpu_out_data =(DataType*)sycl_device.allocate(sizeof(DataType));
|
||||
|
||||
TensorMap<Tensor<float, 2> > in_gpu(gpu_in_data, tensorRange);
|
||||
TensorMap<Tensor<float, 0> > out_gpu(gpu_out_data);
|
||||
TensorMap<Tensor<DataType, 2, DataLayout> > in_gpu(gpu_in_data, tensorRange);
|
||||
TensorMap<Tensor<DataType, 0, DataLayout> > out_gpu(gpu_out_data);
|
||||
|
||||
sycl_device.memcpyHostToDevice(gpu_in_data, in.data(),(in.dimensions().TotalSize())*sizeof(float));
|
||||
sycl_device.memcpyHostToDevice(gpu_in_data, in.data(),(in.dimensions().TotalSize())*sizeof(DataType));
|
||||
out_gpu.device(sycl_device) = in_gpu.sum();
|
||||
sycl_device.memcpyDeviceToHost(full_redux_gpu.data(), gpu_out_data, sizeof(float));
|
||||
sycl_device.memcpyDeviceToHost(full_redux_gpu.data(), gpu_out_data, sizeof(DataType));
|
||||
// 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);
|
||||
}
|
||||
|
||||
template <typename DataType, int DataLayout>
|
||||
static void test_first_dim_reductions_sycl(const Eigen::SyclDevice& sycl_device) {
|
||||
|
||||
int dim_x = 145;
|
||||
@@ -63,23 +63,23 @@ static void test_first_dim_reductions_sycl(const Eigen::SyclDevice& sycl_device)
|
||||
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);
|
||||
Tensor<DataType, 3, DataLayout> in(tensorRange);
|
||||
Tensor<DataType, 2, DataLayout> redux(reduced_tensorRange);
|
||||
Tensor<DataType, 2, DataLayout> 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)));
|
||||
DataType* gpu_in_data = static_cast<DataType*>(sycl_device.allocate(in.dimensions().TotalSize()*sizeof(DataType)));
|
||||
DataType* gpu_out_data = static_cast<DataType*>(sycl_device.allocate(redux_gpu.dimensions().TotalSize()*sizeof(DataType)));
|
||||
|
||||
TensorMap<Tensor<float, 3> > in_gpu(gpu_in_data, tensorRange);
|
||||
TensorMap<Tensor<float, 2> > out_gpu(gpu_out_data, reduced_tensorRange);
|
||||
TensorMap<Tensor<DataType, 3, DataLayout> > in_gpu(gpu_in_data, tensorRange);
|
||||
TensorMap<Tensor<DataType, 2, DataLayout> > out_gpu(gpu_out_data, reduced_tensorRange);
|
||||
|
||||
sycl_device.memcpyHostToDevice(gpu_in_data, in.data(),(in.dimensions().TotalSize())*sizeof(float));
|
||||
sycl_device.memcpyHostToDevice(gpu_in_data, in.data(),(in.dimensions().TotalSize())*sizeof(DataType));
|
||||
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));
|
||||
sycl_device.memcpyDeviceToHost(redux_gpu.data(), gpu_out_data, redux_gpu.dimensions().TotalSize()*sizeof(DataType));
|
||||
|
||||
// Check that the CPU and GPU reductions return the same result.
|
||||
for(int j=0; j<reduced_tensorRange[0]; j++ )
|
||||
@@ -90,6 +90,7 @@ static void test_first_dim_reductions_sycl(const Eigen::SyclDevice& sycl_device)
|
||||
sycl_device.deallocate(gpu_out_data);
|
||||
}
|
||||
|
||||
template <typename DataType, int DataLayout>
|
||||
static void test_last_dim_reductions_sycl(const Eigen::SyclDevice &sycl_device) {
|
||||
|
||||
int dim_x = 567;
|
||||
@@ -101,23 +102,23 @@ static void test_last_dim_reductions_sycl(const Eigen::SyclDevice &sycl_device)
|
||||
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);
|
||||
Tensor<DataType, 3, DataLayout> in(tensorRange);
|
||||
Tensor<DataType, 2, DataLayout> redux(reduced_tensorRange);
|
||||
Tensor<DataType, 2, DataLayout> 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)));
|
||||
DataType* gpu_in_data = static_cast<DataType*>(sycl_device.allocate(in.dimensions().TotalSize()*sizeof(DataType)));
|
||||
DataType* gpu_out_data = static_cast<DataType*>(sycl_device.allocate(redux_gpu.dimensions().TotalSize()*sizeof(DataType)));
|
||||
|
||||
TensorMap<Tensor<float, 3> > in_gpu(gpu_in_data, tensorRange);
|
||||
TensorMap<Tensor<float, 2> > out_gpu(gpu_out_data, reduced_tensorRange);
|
||||
TensorMap<Tensor<DataType, 3, DataLayout> > in_gpu(gpu_in_data, tensorRange);
|
||||
TensorMap<Tensor<DataType, 2, DataLayout> > out_gpu(gpu_out_data, reduced_tensorRange);
|
||||
|
||||
sycl_device.memcpyHostToDevice(gpu_in_data, in.data(),(in.dimensions().TotalSize())*sizeof(float));
|
||||
sycl_device.memcpyHostToDevice(gpu_in_data, in.data(),(in.dimensions().TotalSize())*sizeof(DataType));
|
||||
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));
|
||||
sycl_device.memcpyDeviceToHost(redux_gpu.data(), gpu_out_data, redux_gpu.dimensions().TotalSize()*sizeof(DataType));
|
||||
// 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++ )
|
||||
@@ -127,12 +128,22 @@ static void test_last_dim_reductions_sycl(const Eigen::SyclDevice &sycl_device)
|
||||
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)));
|
||||
|
||||
template<typename DataType, typename dev_Selector> void sycl_reduction_test_per_device(dev_Selector s){
|
||||
QueueInterface queueInterface(s);
|
||||
auto sycl_device = Eigen::SyclDevice(&queueInterface);
|
||||
test_full_reductions_sycl<DataType, RowMajor>(sycl_device);
|
||||
test_first_dim_reductions_sycl<DataType, RowMajor>(sycl_device);
|
||||
test_last_dim_reductions_sycl<DataType, RowMajor>(sycl_device);
|
||||
test_full_reductions_sycl<DataType, ColMajor>(sycl_device);
|
||||
test_first_dim_reductions_sycl<DataType, ColMajor>(sycl_device);
|
||||
test_last_dim_reductions_sycl<DataType, ColMajor>(sycl_device);
|
||||
}
|
||||
void test_cxx11_tensor_reduction_sycl() {
|
||||
printf("Test on GPU: OpenCL\n");
|
||||
CALL_SUBTEST(sycl_reduction_test_per_device<float>((cl::sycl::gpu_selector())));
|
||||
printf("repeating the test on CPU: OpenCL\n");
|
||||
CALL_SUBTEST(sycl_reduction_test_per_device<float>((cl::sycl::cpu_selector())));
|
||||
printf("repeating the test on CPU: HOST\n");
|
||||
CALL_SUBTEST(sycl_reduction_test_per_device<float>((cl::sycl::host_selector())));
|
||||
printf("Test Passed******************\n" );
|
||||
}
|
||||
|
||||
@@ -26,35 +26,32 @@ using Eigen::array;
|
||||
using Eigen::SyclDevice;
|
||||
using Eigen::Tensor;
|
||||
using Eigen::TensorMap;
|
||||
|
||||
template <typename DataType, int DataLayout>
|
||||
void test_sycl_mem_transfers(const Eigen::SyclDevice &sycl_device) {
|
||||
int sizeDim1 = 100;
|
||||
int sizeDim2 = 100;
|
||||
int sizeDim3 = 100;
|
||||
int sizeDim2 = 10;
|
||||
int sizeDim3 = 20;
|
||||
array<int, 3> tensorRange = {{sizeDim1, sizeDim2, sizeDim3}};
|
||||
Tensor<float, 3> in1(tensorRange);
|
||||
Tensor<float, 3> out1(tensorRange);
|
||||
Tensor<float, 3> out2(tensorRange);
|
||||
Tensor<float, 3> out3(tensorRange);
|
||||
Tensor<DataType, 3, DataLayout> in1(tensorRange);
|
||||
Tensor<DataType, 3, DataLayout> out1(tensorRange);
|
||||
Tensor<DataType, 3, DataLayout> out2(tensorRange);
|
||||
Tensor<DataType, 3, DataLayout> out3(tensorRange);
|
||||
|
||||
in1 = in1.random();
|
||||
|
||||
float* gpu_data1 = static_cast<float*>(sycl_device.allocate(in1.size()*sizeof(float)));
|
||||
float* gpu_data2 = static_cast<float*>(sycl_device.allocate(out1.size()*sizeof(float)));
|
||||
//float* gpu_data = static_cast<float*>(sycl_device.allocate(out2.size()*sizeof(float)));
|
||||
DataType* gpu_data1 = static_cast<DataType*>(sycl_device.allocate(in1.size()*sizeof(DataType)));
|
||||
DataType* gpu_data2 = static_cast<DataType*>(sycl_device.allocate(out1.size()*sizeof(DataType)));
|
||||
|
||||
TensorMap<Tensor<float, 3>> gpu1(gpu_data1, tensorRange);
|
||||
TensorMap<Tensor<float, 3>> gpu2(gpu_data2, tensorRange);
|
||||
//TensorMap<Tensor<float, 3>> gpu_out2(gpu_out2_data, tensorRange);
|
||||
|
||||
sycl_device.memcpyHostToDevice(gpu_data1, in1.data(),(in1.size())*sizeof(float));
|
||||
sycl_device.memcpyHostToDevice(gpu_data2, in1.data(),(in1.size())*sizeof(float));
|
||||
TensorMap<Tensor<DataType, 3, DataLayout>> gpu1(gpu_data1, tensorRange);
|
||||
TensorMap<Tensor<DataType, 3, DataLayout>> gpu2(gpu_data2, tensorRange);
|
||||
|
||||
sycl_device.memcpyHostToDevice(gpu_data1, in1.data(),(in1.size())*sizeof(DataType));
|
||||
sycl_device.memcpyHostToDevice(gpu_data2, in1.data(),(in1.size())*sizeof(DataType));
|
||||
gpu1.device(sycl_device) = gpu1 * 3.14f;
|
||||
gpu2.device(sycl_device) = gpu2 * 2.7f;
|
||||
sycl_device.memcpyDeviceToHost(out1.data(), gpu_data1,(out1.size())*sizeof(float));
|
||||
sycl_device.memcpyDeviceToHost(out2.data(), gpu_data1,(out2.size())*sizeof(float));
|
||||
sycl_device.memcpyDeviceToHost(out3.data(), gpu_data2,(out3.size())*sizeof(float));
|
||||
// sycl_device.Synchronize();
|
||||
sycl_device.memcpyDeviceToHost(out1.data(), gpu_data1,(out1.size())*sizeof(DataType));
|
||||
sycl_device.memcpyDeviceToHost(out2.data(), gpu_data1,(out2.size())*sizeof(DataType));
|
||||
sycl_device.memcpyDeviceToHost(out3.data(), gpu_data2,(out3.size())*sizeof(DataType));
|
||||
|
||||
for (int i = 0; i < in1.size(); ++i) {
|
||||
VERIFY_IS_APPROX(out1(i), in1(i) * 3.14f);
|
||||
@@ -65,34 +62,34 @@ void test_sycl_mem_transfers(const Eigen::SyclDevice &sycl_device) {
|
||||
sycl_device.deallocate(gpu_data1);
|
||||
sycl_device.deallocate(gpu_data2);
|
||||
}
|
||||
|
||||
template <typename DataType, int DataLayout>
|
||||
void test_sycl_computations(const Eigen::SyclDevice &sycl_device) {
|
||||
|
||||
int sizeDim1 = 100;
|
||||
int sizeDim2 = 100;
|
||||
int sizeDim3 = 100;
|
||||
int sizeDim2 = 10;
|
||||
int sizeDim3 = 20;
|
||||
array<int, 3> tensorRange = {{sizeDim1, sizeDim2, sizeDim3}};
|
||||
Tensor<float, 3> in1(tensorRange);
|
||||
Tensor<float, 3> in2(tensorRange);
|
||||
Tensor<float, 3> in3(tensorRange);
|
||||
Tensor<float, 3> out(tensorRange);
|
||||
Tensor<DataType, 3,DataLayout> in1(tensorRange);
|
||||
Tensor<DataType, 3,DataLayout> in2(tensorRange);
|
||||
Tensor<DataType, 3,DataLayout> in3(tensorRange);
|
||||
Tensor<DataType, 3,DataLayout> out(tensorRange);
|
||||
|
||||
in2 = in2.random();
|
||||
in3 = in3.random();
|
||||
|
||||
float * gpu_in1_data = static_cast<float*>(sycl_device.allocate(in1.size()*sizeof(float)));
|
||||
float * gpu_in2_data = static_cast<float*>(sycl_device.allocate(in2.size()*sizeof(float)));
|
||||
float * gpu_in3_data = static_cast<float*>(sycl_device.allocate(in3.size()*sizeof(float)));
|
||||
float * gpu_out_data = static_cast<float*>(sycl_device.allocate(out.size()*sizeof(float)));
|
||||
DataType * gpu_in1_data = static_cast<DataType*>(sycl_device.allocate(in1.size()*sizeof(DataType)));
|
||||
DataType * gpu_in2_data = static_cast<DataType*>(sycl_device.allocate(in2.size()*sizeof(DataType)));
|
||||
DataType * gpu_in3_data = static_cast<DataType*>(sycl_device.allocate(in3.size()*sizeof(DataType)));
|
||||
DataType * gpu_out_data = static_cast<DataType*>(sycl_device.allocate(out.size()*sizeof(DataType)));
|
||||
|
||||
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);
|
||||
TensorMap<Tensor<DataType, 3, DataLayout>> gpu_in1(gpu_in1_data, tensorRange);
|
||||
TensorMap<Tensor<DataType, 3, DataLayout>> gpu_in2(gpu_in2_data, tensorRange);
|
||||
TensorMap<Tensor<DataType, 3, DataLayout>> gpu_in3(gpu_in3_data, tensorRange);
|
||||
TensorMap<Tensor<DataType, 3, DataLayout>> gpu_out(gpu_out_data, tensorRange);
|
||||
|
||||
/// a=1.2f
|
||||
gpu_in1.device(sycl_device) = gpu_in1.constant(1.2f);
|
||||
sycl_device.memcpyDeviceToHost(in1.data(), gpu_in1_data ,(in1.size())*sizeof(float));
|
||||
sycl_device.memcpyDeviceToHost(in1.data(), gpu_in1_data ,(in1.size())*sizeof(DataType));
|
||||
for (int i = 0; i < sizeDim1; ++i) {
|
||||
for (int j = 0; j < sizeDim2; ++j) {
|
||||
for (int k = 0; k < sizeDim3; ++k) {
|
||||
@@ -104,7 +101,7 @@ void test_sycl_computations(const Eigen::SyclDevice &sycl_device) {
|
||||
|
||||
/// a=b*1.2f
|
||||
gpu_out.device(sycl_device) = gpu_in1 * 1.2f;
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data ,(out.size())*sizeof(float));
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data ,(out.size())*sizeof(DataType));
|
||||
for (int i = 0; i < sizeDim1; ++i) {
|
||||
for (int j = 0; j < sizeDim2; ++j) {
|
||||
for (int k = 0; k < sizeDim3; ++k) {
|
||||
@@ -116,9 +113,9 @@ void test_sycl_computations(const Eigen::SyclDevice &sycl_device) {
|
||||
printf("a=b*1.2f Test Passed\n");
|
||||
|
||||
/// c=a*b
|
||||
sycl_device.memcpyHostToDevice(gpu_in2_data, in2.data(),(in2.size())*sizeof(float));
|
||||
sycl_device.memcpyHostToDevice(gpu_in2_data, in2.data(),(in2.size())*sizeof(DataType));
|
||||
gpu_out.device(sycl_device) = gpu_in1 * gpu_in2;
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.size())*sizeof(float));
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.size())*sizeof(DataType));
|
||||
for (int i = 0; i < sizeDim1; ++i) {
|
||||
for (int j = 0; j < sizeDim2; ++j) {
|
||||
for (int k = 0; k < sizeDim3; ++k) {
|
||||
@@ -132,7 +129,7 @@ void test_sycl_computations(const Eigen::SyclDevice &sycl_device) {
|
||||
|
||||
/// c=a+b
|
||||
gpu_out.device(sycl_device) = gpu_in1 + gpu_in2;
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.size())*sizeof(float));
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.size())*sizeof(DataType));
|
||||
for (int i = 0; i < sizeDim1; ++i) {
|
||||
for (int j = 0; j < sizeDim2; ++j) {
|
||||
for (int k = 0; k < sizeDim3; ++k) {
|
||||
@@ -146,7 +143,7 @@ void test_sycl_computations(const Eigen::SyclDevice &sycl_device) {
|
||||
|
||||
/// c=a*a
|
||||
gpu_out.device(sycl_device) = gpu_in1 * gpu_in1;
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.size())*sizeof(float));
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.size())*sizeof(DataType));
|
||||
for (int i = 0; i < sizeDim1; ++i) {
|
||||
for (int j = 0; j < sizeDim2; ++j) {
|
||||
for (int k = 0; k < sizeDim3; ++k) {
|
||||
@@ -160,7 +157,7 @@ void test_sycl_computations(const Eigen::SyclDevice &sycl_device) {
|
||||
|
||||
//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.memcpyDeviceToHost(out.data(),gpu_out_data,(out.size())*sizeof(float));
|
||||
sycl_device.memcpyDeviceToHost(out.data(),gpu_out_data,(out.size())*sizeof(DataType));
|
||||
for (int i = 0; i < sizeDim1; ++i) {
|
||||
for (int j = 0; j < sizeDim2; ++j) {
|
||||
for (int k = 0; k < sizeDim3; ++k) {
|
||||
@@ -173,9 +170,9 @@ void test_sycl_computations(const Eigen::SyclDevice &sycl_device) {
|
||||
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.size())*sizeof(float));
|
||||
sycl_device.memcpyHostToDevice(gpu_in3_data, in3.data(),(in3.size())*sizeof(DataType));
|
||||
gpu_out.device(sycl_device) =(gpu_in1 > gpu_in1.constant(0.5f)).select(gpu_in2, gpu_in3);
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.size())*sizeof(float));
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.size())*sizeof(DataType));
|
||||
for (int i = 0; i < sizeDim1; ++i) {
|
||||
for (int j = 0; j < sizeDim2; ++j) {
|
||||
for (int k = 0; k < sizeDim3; ++k) {
|
||||
@@ -191,10 +188,20 @@ void test_sycl_computations(const Eigen::SyclDevice &sycl_device) {
|
||||
sycl_device.deallocate(gpu_in3_data);
|
||||
sycl_device.deallocate(gpu_out_data);
|
||||
}
|
||||
|
||||
void test_cxx11_tensor_sycl() {
|
||||
cl::sycl::gpu_selector s;
|
||||
Eigen::SyclDevice sycl_device(s);
|
||||
CALL_SUBTEST(test_sycl_mem_transfers(sycl_device));
|
||||
CALL_SUBTEST(test_sycl_computations(sycl_device));
|
||||
template<typename DataType, typename dev_Selector> void sycl_computing_test_per_device(dev_Selector s){
|
||||
QueueInterface queueInterface(s);
|
||||
auto sycl_device = Eigen::SyclDevice(&queueInterface);
|
||||
test_sycl_mem_transfers<DataType, RowMajor>(sycl_device);
|
||||
test_sycl_computations<DataType, RowMajor>(sycl_device);
|
||||
test_sycl_mem_transfers<DataType, ColMajor>(sycl_device);
|
||||
test_sycl_computations<DataType, ColMajor>(sycl_device);
|
||||
}
|
||||
void test_cxx11_tensor_sycl() {
|
||||
printf("Test on GPU: OpenCL\n");
|
||||
CALL_SUBTEST(sycl_computing_test_per_device<float>((cl::sycl::gpu_selector())));
|
||||
printf("repeating the test on CPU: OpenCL\n");
|
||||
CALL_SUBTEST(sycl_computing_test_per_device<float>((cl::sycl::cpu_selector())));
|
||||
printf("repeating the test on CPU: HOST\n");
|
||||
CALL_SUBTEST(sycl_computing_test_per_device<float>((cl::sycl::host_selector())));
|
||||
printf("Test Passed******************\n" );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user