Loading...
Searching...
No Matches
TensorSyclExtractAccessor.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Mehdi Goli Codeplay Software Ltd.
5// Ralph Potter Codeplay Software Ltd.
6// Luke Iwanski Codeplay Software Ltd.
7// Contact: <eigen@codeplay.com>
8//
9// This Source Code Form is subject to the terms of the Mozilla
10// Public License v. 2.0. If a copy of the MPL was not distributed
11// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
12
13/*****************************************************************
14 * TensorSyclExtractAccessor.h
15 *
16 * \brief:
17 * ExtractAccessor takes Expression placeHolder expression and the tuple of sycl
18 * buffers as an input. Using pre-order tree traversal, ExtractAccessor
19 * recursively calls itself for its children in the expression tree. The
20 * leaf node in the PlaceHolder expression is nothing but a container preserving
21 * the order of the actual data in the tuple of sycl buffer. By invoking the
22 * extract accessor for the PlaceHolder<N>, an accessor is created for the Nth
23 * buffer in the tuple of buffers. This accessor is then added as an Nth
24 * element in the tuple of accessors. In this case we preserve the order of data
25 * in the expression tree.
26 *
27 * This is the specialisation of extract accessor method for different operation
28 * type in the PlaceHolder expression.
29 *
30*****************************************************************/
31
32#ifndef UNSUPPORTED_EIGEN_CXX11_SRC_TENSOR_TENSORSYCL_EXTRACT_ACCESSOR_HPP
33#define UNSUPPORTED_EIGEN_CXX11_SRC_TENSOR_TENSORSYCL_EXTRACT_ACCESSOR_HPP
34
35namespace Eigen {
36namespace TensorSycl {
37namespace internal {
42template <typename Evaluator>
43struct ExtractAccessor;
44
45struct AccessorConstructor{
46 template<typename Arg> static inline auto getTuple(cl::sycl::handler& cgh, Arg eval)
47 -> decltype(ExtractAccessor<Arg>::getTuple(cgh, eval)) {
48 return ExtractAccessor<Arg>::getTuple(cgh, eval);
49 }
50
51 template<typename Arg1, typename Arg2> static inline auto getTuple(cl::sycl::handler& cgh, Arg1 eval1, Arg2 eval2)
52 -> decltype(utility::tuple::append(ExtractAccessor<Arg1>::getTuple(cgh, eval1), ExtractAccessor<Arg2>::getTuple(cgh, eval2))) {
53 return utility::tuple::append(ExtractAccessor<Arg1>::getTuple(cgh, eval1), ExtractAccessor<Arg2>::getTuple(cgh, eval2));
54 }
55 template<typename Arg1, typename Arg2, typename Arg3> static inline auto getTuple(cl::sycl::handler& cgh, Arg1 eval1 , Arg2 eval2 , Arg3 eval3)
56 -> decltype(utility::tuple::append(ExtractAccessor<Arg1>::getTuple(cgh, eval1),utility::tuple::append(ExtractAccessor<Arg2>::getTuple(cgh, eval2), ExtractAccessor<Arg3>::getTuple(cgh, eval3)))) {
57 return utility::tuple::append(ExtractAccessor<Arg1>::getTuple(cgh, eval1),utility::tuple::append(ExtractAccessor<Arg2>::getTuple(cgh, eval2), ExtractAccessor<Arg3>::getTuple(cgh, eval3)));
58 }
59 template< cl::sycl::access::mode AcM, typename Arg> static inline auto getAccessor(cl::sycl::handler& cgh, Arg eval)
60 -> decltype(utility::tuple::make_tuple( eval.device().template get_sycl_accessor<AcM,
61 typename Eigen::internal::remove_all<typename Arg::CoeffReturnType>::type>(eval.dimensions().TotalSize(), cgh,eval.data()))){
62 return utility::tuple::make_tuple(eval.device().template get_sycl_accessor<AcM, typename Eigen::internal::remove_all<typename Arg::CoeffReturnType>::type>(eval.dimensions().TotalSize(), cgh,eval.data()));
63 }
64};
65
68template <template<class, class> class UnaryCategory, typename OP, typename RHSExpr, typename Dev>
69struct ExtractAccessor<TensorEvaluator<const UnaryCategory<OP, RHSExpr>, Dev> > {
70 static inline auto getTuple(cl::sycl::handler& cgh, const TensorEvaluator<const UnaryCategory<OP, RHSExpr>, Dev> eval)
71 -> decltype(AccessorConstructor::getTuple(cgh, eval.impl())){
72 return AccessorConstructor::getTuple(cgh, eval.impl());
73 }
74};
75
77template <template<class, class> class UnaryCategory, typename OP, typename RHSExpr, typename Dev>
78struct ExtractAccessor<TensorEvaluator<UnaryCategory<OP, RHSExpr>, Dev> >
79: ExtractAccessor<TensorEvaluator<const UnaryCategory<OP, RHSExpr>, Dev> > {};
80
82template <template<class, class, class> class BinaryCategory, typename OP, typename LHSExpr, typename RHSExpr, typename Dev>
83struct ExtractAccessor<TensorEvaluator<const BinaryCategory<OP, LHSExpr, RHSExpr>, Dev> > {
84 static inline auto getTuple(cl::sycl::handler& cgh, const TensorEvaluator<const BinaryCategory<OP, LHSExpr, RHSExpr>, Dev> eval)
85 -> decltype(AccessorConstructor::getTuple(cgh, eval.left_impl(), eval.right_impl())){
86 return AccessorConstructor::getTuple(cgh, eval.left_impl(), eval.right_impl());
87 }
88};
90template <template<class, class, class> class BinaryCategory, typename OP, typename LHSExpr, typename RHSExpr, typename Dev>
91struct ExtractAccessor<TensorEvaluator<BinaryCategory<OP, LHSExpr, RHSExpr>, Dev> >
92: ExtractAccessor<TensorEvaluator<const BinaryCategory<OP, LHSExpr, RHSExpr>, Dev> >{};
93
96template <template<class, class, class, class> class TernaryCategory, typename OP, typename Arg1Expr, typename Arg2Expr, typename Arg3Expr, typename Dev>
97struct ExtractAccessor<TensorEvaluator<const TernaryCategory<OP, Arg1Expr, Arg2Expr, Arg3Expr>, Dev> > {
98 static inline auto getTuple(cl::sycl::handler& cgh, const TensorEvaluator<const TernaryCategory<OP, Arg1Expr, Arg2Expr, Arg3Expr>, Dev> eval)
99 -> decltype(AccessorConstructor::getTuple(cgh, eval.arg1Impl(), eval.arg2Impl(), eval.arg3Impl())){
100 return AccessorConstructor::getTuple(cgh, eval.arg1Impl(), eval.arg2Impl(), eval.arg3Impl());
101 }
102};
103
105template <template<class, class, class, class> class TernaryCategory, typename OP, typename Arg1Expr, typename Arg2Expr, typename Arg3Expr, typename Dev>
106struct ExtractAccessor<TensorEvaluator<TernaryCategory<OP, Arg1Expr, Arg2Expr, Arg3Expr>, Dev> >
107: ExtractAccessor<TensorEvaluator<const TernaryCategory<OP, Arg1Expr, Arg2Expr, Arg3Expr>, Dev> >{};
108
111template <typename IfExpr, typename ThenExpr, typename ElseExpr, typename Dev>
112struct ExtractAccessor<TensorEvaluator<const TensorSelectOp<IfExpr, ThenExpr, ElseExpr>, Dev> > {
113 static inline auto getTuple(cl::sycl::handler& cgh, const TensorEvaluator<const TensorSelectOp<IfExpr, ThenExpr, ElseExpr>, Dev> eval)
114 -> decltype(AccessorConstructor::getTuple(cgh, eval.cond_impl(), eval.then_impl(), eval.else_impl())){
115 return AccessorConstructor::getTuple(cgh, eval.cond_impl(), eval.then_impl(), eval.else_impl());
116 }
117};
118
121template <typename IfExpr, typename ThenExpr, typename ElseExpr, typename Dev>
122struct ExtractAccessor<TensorEvaluator<TensorSelectOp<IfExpr, ThenExpr, ElseExpr>, Dev> >
123: ExtractAccessor<TensorEvaluator<const TensorSelectOp<IfExpr, ThenExpr, ElseExpr>, Dev> >{};
124
126template <typename LHSExpr, typename RHSExpr, typename Dev>
127struct ExtractAccessor<TensorEvaluator<const TensorAssignOp<LHSExpr, RHSExpr>, Dev> > {
128 static inline auto getTuple(cl::sycl::handler& cgh, const TensorEvaluator<const TensorAssignOp<LHSExpr, RHSExpr>, Dev> eval)
129 -> decltype(AccessorConstructor::getTuple(cgh, eval.left_impl(), eval.right_impl())){
130 return AccessorConstructor::getTuple(cgh, eval.left_impl(), eval.right_impl());
131 }
132};
133
135template <typename LHSExpr, typename RHSExpr, typename Dev>
136struct ExtractAccessor<TensorEvaluator<TensorAssignOp<LHSExpr, RHSExpr>, Dev> >
137: ExtractAccessor<TensorEvaluator<const TensorAssignOp<LHSExpr, RHSExpr>, Dev> >{};
138
140#define TENSORMAPEXPR(CVQual, ACCType)\
141template <typename PlainObjectType, int Options_, typename Dev>\
142struct ExtractAccessor<TensorEvaluator<CVQual TensorMap<PlainObjectType, Options_>, Dev> > {\
143 static inline auto getTuple(cl::sycl::handler& cgh,const TensorEvaluator<CVQual TensorMap<PlainObjectType, Options_>, Dev> eval)\
144 -> decltype(AccessorConstructor::template getAccessor<ACCType>(cgh, eval)){\
145 return AccessorConstructor::template getAccessor<ACCType>(cgh, eval);\
146 }\
147};
148TENSORMAPEXPR(const, cl::sycl::access::mode::read)
149TENSORMAPEXPR(, cl::sycl::access::mode::read_write)
150#undef TENSORMAPEXPR
151
153template <typename Expr, typename Dev>
154struct ExtractAccessor<TensorEvaluator<const TensorForcedEvalOp<Expr>, Dev> > {
155 static inline auto getTuple(cl::sycl::handler& cgh, const TensorEvaluator<const TensorForcedEvalOp<Expr>, Dev> eval)
156 -> decltype(AccessorConstructor::template getAccessor<cl::sycl::access::mode::read>(cgh, eval)){
157 return AccessorConstructor::template getAccessor<cl::sycl::access::mode::read>(cgh, eval);
158 }
159};
160
162template <typename Expr, typename Dev>
163struct ExtractAccessor<TensorEvaluator<TensorForcedEvalOp<Expr>, Dev> >
164: ExtractAccessor<TensorEvaluator<const TensorForcedEvalOp<Expr>, Dev> >{};
165
167template <typename Expr, typename Dev>
168struct ExtractAccessor<TensorEvaluator<const TensorEvalToOp<Expr>, Dev> > {
169 static inline auto getTuple(cl::sycl::handler& cgh,const TensorEvaluator<const TensorEvalToOp<Expr>, Dev> eval)
170 -> decltype(utility::tuple::append(AccessorConstructor::template getAccessor<cl::sycl::access::mode::write>(cgh, eval), AccessorConstructor::getTuple(cgh, eval.impl()))){
171 return utility::tuple::append(AccessorConstructor::template getAccessor<cl::sycl::access::mode::write>(cgh, eval), AccessorConstructor::getTuple(cgh, eval.impl()));
172 }
173};
174
176template <typename Expr, typename Dev>
177struct ExtractAccessor<TensorEvaluator<TensorEvalToOp<Expr>, Dev> >
178: ExtractAccessor<TensorEvaluator<const TensorEvalToOp<Expr>, Dev> >{};
179
181template <typename OP, typename Dim, typename Expr, typename Dev>
182struct ExtractAccessor<TensorEvaluator<const TensorReductionOp<OP, Dim, Expr>, Dev> > {
183 static inline auto getTuple(cl::sycl::handler& cgh, const TensorEvaluator<const TensorReductionOp<OP, Dim, Expr>, Dev> eval)
184 -> decltype(AccessorConstructor::template getAccessor<cl::sycl::access::mode::read>(cgh, eval)){
185 return AccessorConstructor::template getAccessor<cl::sycl::access::mode::read>(cgh, eval);
186 }
187};
188
190template <typename OP, typename Dim, typename Expr, typename Dev>
191struct ExtractAccessor<TensorEvaluator<TensorReductionOp<OP, Dim, Expr>, Dev> >
192: ExtractAccessor<TensorEvaluator<const TensorReductionOp<OP, Dim, Expr>, Dev> >{};
193
195template <typename Evaluator>
196auto createTupleOfAccessors(cl::sycl::handler& cgh, const Evaluator& expr)
197-> decltype(ExtractAccessor<Evaluator>::getTuple(cgh, expr)) {
198 return ExtractAccessor<Evaluator>::getTuple(cgh, expr);
199}
200
201}
202}
203}
204#endif // UNSUPPORTED_EIGEN_CXX11_SRC_TENSOR_TENSORSYCL_EXTRACT_ACCESSOR_HPP
Namespace containing all symbols from the Eigen library.
Definition: AdolcForward:45