From 109005c6c9a3e6e1e42ff9efc71be3a899519ed4 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Tue, 30 Jun 2015 13:08:12 -0700 Subject: Added a test for multithreaded full reductions --- unsupported/test/cxx11_tensor_thread_pool.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'unsupported/test/cxx11_tensor_thread_pool.cpp') diff --git a/unsupported/test/cxx11_tensor_thread_pool.cpp b/unsupported/test/cxx11_tensor_thread_pool.cpp index 0a20a01a4..5ec7c8bf4 100644 --- a/unsupported/test/cxx11_tensor_thread_pool.cpp +++ b/unsupported/test/cxx11_tensor_thread_pool.cpp @@ -228,6 +228,29 @@ static void test_multithread_contraction_agrees_with_singlethread() { } +template +static void test_multithreaded_reductions() { + const int num_threads = internal::random(3, 11); + ThreadPool thread_pool(num_threads); + Eigen::ThreadPoolDevice thread_pool_device(&thread_pool, num_threads); + + const int num_rows = internal::random(13, 732); + const int num_cols = internal::random(13, 732); + Tensor t1(num_rows, num_cols); + t1.setRandom(); + + Tensor full_redux(1); + full_redux = t1.sum(); + + Tensor full_redux_tp(1); + full_redux_tp.device(thread_pool_device) = t1.sum(); + + // Check that the single threaded and the multi threaded reductions return + // the same result. + VERIFY_IS_APPROX(full_redux(0), full_redux_tp(0)); +} + + static void test_memcpy() { for (int i = 0; i < 5; ++i) { @@ -271,6 +294,9 @@ void test_cxx11_tensor_thread_pool() CALL_SUBTEST(test_contraction_corner_cases()); CALL_SUBTEST(test_contraction_corner_cases()); + CALL_SUBTEST(test_multithreaded_reductions()); + CALL_SUBTEST(test_multithreaded_reductions()); + CALL_SUBTEST(test_memcpy()); CALL_SUBTEST(test_multithread_random()); -- cgit v1.2.3