aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported/test/cxx11_tensor_reduction_sycl.cpp
diff options
context:
space:
mode:
authorGravatar Mehdi Goli <mehdi.goli@codeplay.com>2016-11-18 16:20:42 +0000
committerGravatar Mehdi Goli <mehdi.goli@codeplay.com>2016-11-18 16:20:42 +0000
commit622805a0c5d216141eca3090e80d58c159e175ee (patch)
tree536147ee41965ef1b9fbe7d5a11b7fd872804b22 /unsupported/test/cxx11_tensor_reduction_sycl.cpp
parent5159675c338ffef579fa7015fe5e05eb27bcbdb5 (diff)
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}.
Diffstat (limited to 'unsupported/test/cxx11_tensor_reduction_sycl.cpp')
-rw-r--r--unsupported/test/cxx11_tensor_reduction_sycl.cpp83
1 files changed, 47 insertions, 36 deletions
diff --git a/unsupported/test/cxx11_tensor_reduction_sycl.cpp b/unsupported/test/cxx11_tensor_reduction_sycl.cpp
index a9ef82907..6b62737b8 100644
--- a/unsupported/test/cxx11_tensor_reduction_sycl.cpp
+++ b/unsupported/test/cxx11_tensor_reduction_sycl.cpp
@@ -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);
}
-
+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() {
- 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)));
-
+ 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" );
}