From 0ee97b60c256b31a98838324ce1909247a0133d2 Mon Sep 17 00:00:00 2001 From: Mehdi Goli Date: Tue, 7 Feb 2017 15:43:17 +0000 Subject: Adding mean to TensorReductionSycl.h --- unsupported/test/cxx11_tensor_reduction_sycl.cpp | 53 ++++++++++++++++++++---- 1 file changed, 44 insertions(+), 9 deletions(-) (limited to 'unsupported/test/cxx11_tensor_reduction_sycl.cpp') diff --git a/unsupported/test/cxx11_tensor_reduction_sycl.cpp b/unsupported/test/cxx11_tensor_reduction_sycl.cpp index 251091f5b..440d48bca 100644 --- a/unsupported/test/cxx11_tensor_reduction_sycl.cpp +++ b/unsupported/test/cxx11_tensor_reduction_sycl.cpp @@ -22,7 +22,7 @@ template -static void test_full_reductions_sycl(const Eigen::SyclDevice& sycl_device) { +static void test_full_reductions_mean_sycl(const Eigen::SyclDevice& sycl_device) { const IndexType num_rows = 452; const IndexType num_cols = 765; @@ -34,6 +34,37 @@ static void test_full_reductions_sycl(const Eigen::SyclDevice& sycl_device) { in.setRandom(); + full_redux = in.mean(); + + DataType* gpu_in_data = static_cast(sycl_device.allocate(in.dimensions().TotalSize()*sizeof(DataType))); + DataType* gpu_out_data =(DataType*)sycl_device.allocate(sizeof(DataType)); + + TensorMap > in_gpu(gpu_in_data, tensorRange); + TensorMap > out_gpu(gpu_out_data); + + sycl_device.memcpyHostToDevice(gpu_in_data, in.data(),(in.dimensions().TotalSize())*sizeof(DataType)); + out_gpu.device(sycl_device) = in_gpu.mean(); + 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 +static void test_full_reductions_min_sycl(const Eigen::SyclDevice& sycl_device) { + + const IndexType num_rows = 876; + const IndexType num_cols = 953; + array tensorRange = {{num_rows, num_cols}}; + + Tensor in(tensorRange); + Tensor full_redux; + Tensor full_redux_gpu; + + in.setRandom(); + full_redux = in.minimum(); DataType* gpu_in_data = static_cast(sycl_device.allocate(in.dimensions().TotalSize()*sizeof(DataType))); @@ -50,8 +81,10 @@ static void test_full_reductions_sycl(const Eigen::SyclDevice& sycl_device) { sycl_device.deallocate(gpu_in_data); sycl_device.deallocate(gpu_out_data); } + + template -static void test_first_dim_reductions_sycl(const Eigen::SyclDevice& sycl_device) { +static void test_first_dim_reductions_max_sycl(const Eigen::SyclDevice& sycl_device) { IndexType dim_x = 145; IndexType dim_y = 1; @@ -90,7 +123,7 @@ static void test_first_dim_reductions_sycl(const Eigen::SyclDevice& sycl_device) } template -static void test_last_dim_reductions_sycl(const Eigen::SyclDevice &sycl_device) { +static void test_last_dim_reductions_sum_sycl(const Eigen::SyclDevice &sycl_device) { IndexType dim_x = 567; IndexType dim_y = 1; @@ -132,12 +165,14 @@ template void sycl_reduction_test_per_device(const cl::sycl:: QueueInterface queueInterface(d); auto sycl_device = Eigen::SyclDevice(&queueInterface); - test_full_reductions_sycl(sycl_device); - test_first_dim_reductions_sycl(sycl_device); - test_last_dim_reductions_sycl(sycl_device); - test_full_reductions_sycl(sycl_device); - test_first_dim_reductions_sycl(sycl_device); - test_last_dim_reductions_sycl(sycl_device); + test_full_reductions_mean_sycl(sycl_device); + test_full_reductions_min_sycl(sycl_device); + test_first_dim_reductions_max_sycl(sycl_device); + test_last_dim_reductions_sum_sycl(sycl_device); + test_full_reductions_mean_sycl(sycl_device); + test_full_reductions_min_sycl(sycl_device); + test_first_dim_reductions_max_sycl(sycl_device); + test_last_dim_reductions_sum_sycl(sycl_device); } void test_cxx11_tensor_reduction_sycl() { for (const auto& device :Eigen::get_sycl_supported_devices()) { -- cgit v1.2.3