// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Mehdi Goli Codeplay Software Ltd. // Ralph Potter Codeplay Software Ltd. // Luke Iwanski Codeplay Software Ltd. // Contact: // // 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/. /***************************************************************** * TensorSyclExprConstructor.h * * \brief: * This file re-create an expression on the SYCL device in order * to use the original tensor evaluator. * *****************************************************************/ #ifndef UNSUPPORTED_EIGEN_CXX11_SRC_TENSOR_TENSORSYCL_EXPR_CONSTRUCTOR_HPP #define UNSUPPORTED_EIGEN_CXX11_SRC_TENSOR_TENSORSYCL_EXPR_CONSTRUCTOR_HPP namespace Eigen { namespace TensorSycl { namespace internal { /// this class is used by EvalToOp in order to create an lhs expression which is /// a pointer from an accessor on device-only buffer template struct EvalToLHSConstructor { PtrType expr; EvalToLHSConstructor(const utility::tuple::Tuple &t): expr((&(*(utility::tuple::get(t).get_pointer())))) {} }; /// \struct ExprConstructor is used to reconstruct the expression on the device and /// recreate the expression with MakeGlobalPointer containing the device address /// space for the TensorMap pointers used in eval function. /// It receives the original expression type, the functor of the node, the tuple /// of accessors, and the device expression type to re-instantiate the /// expression tree for the device template struct ExprConstructor; /// specialisation of the \ref ExprConstructor struct when the node type is /// TensorMap #define TENSORMAP(CVQual)\ template class MakePointer_, size_t N, typename... Params>\ struct ExprConstructor< CVQual TensorMap, Options2_, MakeGlobalPointer>,\ CVQual PlaceHolder, Options3_, MakePointer_>, N>, Params...>{\ typedef CVQual TensorMap, Options2_, MakeGlobalPointer> Type;\ Type expr;\ template \ ExprConstructor(FuncDetector &fd, const utility::tuple::Tuple &t)\ : expr(Type((&(*(utility::tuple::get(t).get_pointer()))), fd.dimensions())) {}\ }; TENSORMAP(const) TENSORMAP() #undef TENSORMAP #define UNARYCATEGORY(CVQual)\ template class UnaryCategory, typename OP, typename OrigRHSExpr, typename RHSExpr, typename... Params>\ struct ExprConstructor, CVQual UnaryCategory, Params...> {\ typedef ExprConstructor my_type;\ my_type rhsExpr;\ typedef CVQual UnaryCategory Type;\ Type expr;\ template \ ExprConstructor(FuncDetector &funcD, const utility::tuple::Tuple &t)\ : rhsExpr(funcD.rhsExpr, t), expr(rhsExpr.expr, funcD.func) {}\ }; UNARYCATEGORY(const) UNARYCATEGORY() #undef UNARYCATEGORY /// specialisation of the \ref ExprConstructor struct when the node type is /// TensorBinaryOp #define BINARYCATEGORY(CVQual)\ template class BinaryCategory, typename OP, typename OrigLHSExpr, typename OrigRHSExpr, typename LHSExpr,\ typename RHSExpr, typename... Params>\ struct ExprConstructor, CVQual BinaryCategory, Params...> {\ typedef ExprConstructor my_left_type;\ typedef ExprConstructor my_right_type;\ typedef CVQual BinaryCategory Type;\ my_left_type lhsExpr;\ my_right_type rhsExpr;\ Type expr;\ template \ ExprConstructor(FuncDetector &funcD, const utility::tuple::Tuple &t)\ : lhsExpr(funcD.lhsExpr, t),rhsExpr(funcD.rhsExpr, t), expr(lhsExpr.expr, rhsExpr.expr, funcD.func) {}\ }; BINARYCATEGORY(const) BINARYCATEGORY() #undef BINARYCATEGORY /// specialisation of the \ref ExprConstructor struct when the node type is /// TensorCwiseTernaryOp #define TERNARYCATEGORY(CVQual)\ template