From 6913221c43c6ad41b1fbfc0d263d2764abd11ad2 Mon Sep 17 00:00:00 2001 From: Eugene Zhulenev Date: Wed, 25 Jul 2018 13:51:10 -0700 Subject: Add tiled evaluation support to TensorExecutor --- unsupported/test/cxx11_tensor_executor.cpp | 81 ++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 unsupported/test/cxx11_tensor_executor.cpp (limited to 'unsupported/test/cxx11_tensor_executor.cpp') diff --git a/unsupported/test/cxx11_tensor_executor.cpp b/unsupported/test/cxx11_tensor_executor.cpp new file mode 100644 index 000000000..5ae45ac5b --- /dev/null +++ b/unsupported/test/cxx11_tensor_executor.cpp @@ -0,0 +1,81 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2018 Eugene Zhulenev +// +// 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_USE_THREADS + +#include "main.h" + +#include + +using Eigen::Index; +using Eigen::Tensor; +using Eigen::RowMajor; +using Eigen::ColMajor; + +// A set of tests to verify that different TensorExecutor strategies yields the +// same results for all the ops, supporting tiled execution. + +template +static void test_execute_binary_expr(Device d) { + // Pick a large enough tensor size to bypass small tensor block evaluation + // optimization. + Tensor lhs(840, 390, 37); + Tensor rhs(840, 390, 37); + Tensor dst(840, 390, 37); + + lhs.setRandom(); + rhs.setRandom(); + + const auto expr = lhs + rhs; + + using Assign = TensorAssignOp; + using Executor = + internal::TensorExecutor; + + Executor::run(Assign(dst, expr), d); + + for (int i = 0; i < 840; ++i) { + for (int j = 0; j < 390; ++j) { + for (int k = 0; k < 37; ++k) { + float sum = lhs(i, j, k) + rhs(i, j, k); + VERIFY_IS_EQUAL(sum, dst(i, j, k)); + } + } + } +} + +#define CALL_SUBTEST_COMBINATIONS(NAME) \ + CALL_SUBTEST((NAME(default_device))); \ + CALL_SUBTEST((NAME(default_device))); \ + CALL_SUBTEST((NAME(default_device))); \ + CALL_SUBTEST((NAME(default_device))); \ + CALL_SUBTEST((NAME(default_device))); \ + CALL_SUBTEST((NAME(default_device))); \ + CALL_SUBTEST((NAME(default_device))); \ + CALL_SUBTEST((NAME(default_device))); \ + CALL_SUBTEST((NAME(tp_device))); \ + CALL_SUBTEST((NAME(tp_device))); \ + CALL_SUBTEST((NAME(tp_device))); \ + CALL_SUBTEST((NAME(tp_device))); \ + CALL_SUBTEST((NAME(tp_device))); \ + CALL_SUBTEST((NAME(tp_device))); \ + CALL_SUBTEST((NAME(tp_device))); \ + CALL_SUBTEST((NAME(tp_device))) + +EIGEN_DECLARE_TEST(cxx11_tensor_executor) { + Eigen::DefaultDevice default_device; + + const auto num_threads = internal::random(1, 24); + Eigen::ThreadPool tp(num_threads); + Eigen::ThreadPoolDevice tp_device(&tp, num_threads); + + CALL_SUBTEST_COMBINATIONS(test_execute_binary_expr); +} + +#undef CALL_SUBTEST_COMBINATIONS -- cgit v1.2.3