• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * TensorSyclConvertToDeviceExpression.h
15  *
16  * \brief:
17  *  Conversion from host pointer to device pointer
18  *  inside leaf nodes of the expression.
19  *
20 *****************************************************************/
21 
22 #ifndef UNSUPPORTED_EIGEN_CXX11_SRC_TENSOR_TENSORSYCL_CONVERT_TO_DEVICE_EXPRESSION_HPP
23 #define UNSUPPORTED_EIGEN_CXX11_SRC_TENSOR_TENSORSYCL_CONVERT_TO_DEVICE_EXPRESSION_HPP
24 
25 namespace Eigen {
26 namespace TensorSycl {
27 namespace internal {
28 
29 /// \struct ConvertToDeviceExpression
30 /// \brief This struct is used to convert the MakePointer in the host expression
31 /// to the MakeGlobalPointer for the device expression. For the leafNodes
32 /// containing the pointer. This is due to the fact that the address space of
33 /// the pointer T* is different on the host and the device.
34 template <typename Expr>
35 struct ConvertToDeviceExpression;
36 
37 template<template<class...> class NonOpCategory, bool IsConst, typename... Args>
38 struct NonOpConversion{
39   typedef typename GetType<IsConst, NonOpCategory<typename ConvertToDeviceExpression<Args>::Type...> >::Type Type;
40 };
41 
42 
43 template<template<class, template <class> class > class NonOpCategory, bool IsConst, typename Args>
44 struct DeviceConvertor{
45   typedef typename GetType<IsConst, NonOpCategory<typename ConvertToDeviceExpression<Args>::Type, MakeGlobalPointer> >::Type Type;
46 };
47 
48 /// specialisation of the \ref ConvertToDeviceExpression struct when the node
49 /// type is TensorMap
50 #define TENSORMAPCONVERT(CVQual)\
51 template <typename Scalar_, int Options_, int Options2_, int NumIndices_, typename IndexType_, template <class> class MakePointer_>\
52 struct ConvertToDeviceExpression<CVQual TensorMap<Tensor<Scalar_, NumIndices_, Options_, IndexType_>, Options2_, MakePointer_> > {\
53   typedef CVQual TensorMap<Tensor<Scalar_, NumIndices_, Options_, IndexType_>, Options2_, MakeGlobalPointer> Type;\
54 };
55 
56 TENSORMAPCONVERT(const)
57 TENSORMAPCONVERT()
58 #undef TENSORMAPCONVERT
59 
60 /// specialisation of the \ref ConvertToDeviceExpression struct when the node
61 /// type is TensorCwiseNullaryOp, TensorCwiseUnaryOp, TensorCwiseBinaryOp, TensorCwiseTernaryOp, TensorBroadcastingOp
62 #define CATEGORYCONVERT(CVQual)\
63 template <template<class, class...> class Category, typename OP, typename... subExprs>\
64 struct ConvertToDeviceExpression<CVQual Category<OP, subExprs...> > {\
65   typedef CVQual Category<OP, typename ConvertToDeviceExpression<subExprs>::Type... > Type;\
66 };
67 CATEGORYCONVERT(const)
68 CATEGORYCONVERT()
69 #undef CATEGORYCONVERT
70 
71 
72 /// specialisation of the \ref ConvertToDeviceExpression struct when the node
73 /// type is  TensorCwiseSelectOp
74 #define SELECTOPCONVERT(CVQual, Res)\
75 template <typename IfExpr, typename ThenExpr, typename ElseExpr>\
76 struct ConvertToDeviceExpression<CVQual TensorSelectOp<IfExpr, ThenExpr, ElseExpr> >\
77 : NonOpConversion<TensorSelectOp, Res, IfExpr, ThenExpr, ElseExpr> {};
78 SELECTOPCONVERT(const, true)
79 SELECTOPCONVERT(, false)
80 #undef SELECTOPCONVERT
81 
82 /// specialisation of the \ref ConvertToDeviceExpression struct when the node
83 /// type is const AssingOP
84 #define ASSIGNCONVERT(CVQual, Res)\
85 template <typename LHSExpr, typename RHSExpr>\
86 struct ConvertToDeviceExpression<CVQual TensorAssignOp<LHSExpr, RHSExpr> >\
87 : NonOpConversion<TensorAssignOp, Res, LHSExpr, RHSExpr>{};
88 
89 ASSIGNCONVERT(const, true)
90 ASSIGNCONVERT(, false)
91 #undef ASSIGNCONVERT
92 
93 /// specialisation of the \ref ConvertToDeviceExpression struct when the node
94 /// type is either TensorForcedEvalOp or TensorEvalToOp
95 #define KERNELBROKERCONVERT(CVQual, Res, ExprNode)\
96 template <typename Expr>\
97 struct ConvertToDeviceExpression<CVQual ExprNode<Expr> > \
98 : DeviceConvertor<ExprNode, Res, Expr>{};
99 
100 KERNELBROKERCONVERT(const, true, TensorForcedEvalOp)
101 KERNELBROKERCONVERT(, false, TensorForcedEvalOp)
102 KERNELBROKERCONVERT(const, true, TensorEvalToOp)
103 KERNELBROKERCONVERT(, false, TensorEvalToOp)
104 #undef KERNELBROKERCONVERT
105 
106 /// specialisation of the \ref ConvertToDeviceExpression struct when the node type is TensorReductionOp
107 #define KERNELBROKERCONVERTREDUCTION(CVQual)\
108 template <typename OP, typename Dim, typename subExpr, template <class> class MakePointer_>\
109 struct ConvertToDeviceExpression<CVQual TensorReductionOp<OP, Dim, subExpr, MakePointer_> > {\
110   typedef CVQual TensorReductionOp<OP, Dim, typename ConvertToDeviceExpression<subExpr>::Type, MakeGlobalPointer> Type;\
111 };
112 
113 KERNELBROKERCONVERTREDUCTION(const)
114 KERNELBROKERCONVERTREDUCTION()
115 #undef KERNELBROKERCONVERTREDUCTION
116 
117 }  // namespace internal
118 }  // namespace TensorSycl
119 }  // namespace Eigen
120 
121 #endif  // UNSUPPORTED_EIGEN_CXX1
122