TensorEvalTo.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_EVAL_TO_H
11 #define EIGEN_CXX11_TENSOR_TENSOR_EVAL_TO_H
12 
13 namespace Eigen {
14 
22 namespace internal {
23 template<typename XprType, template <class> class MakePointer_>
24 struct traits<TensorEvalToOp<XprType, MakePointer_> >
25 {
26  // Type promotion to handle the case where the types of the lhs and the rhs are different.
27  typedef typename XprType::Scalar Scalar;
29  typedef typename XprTraits::StorageKind StorageKind;
30  typedef typename XprTraits::Index Index;
31  typedef typename XprType::Nested Nested;
33  static const int NumDimensions = XprTraits::NumDimensions;
34  static const int Layout = XprTraits::Layout;
35 
36  enum {
37  Flags = 0
38  };
39  template <class T>
40  struct MakePointer {
41  // Intermediate typedef to workaround MSVC issue.
42  typedef MakePointer_<T> MakePointerT;
43  typedef typename MakePointerT::Type Type;
44  };
45 };
46 
47 template<typename XprType, template <class> class MakePointer_>
48 struct eval<TensorEvalToOp<XprType, MakePointer_>, Eigen::Dense>
49 {
51 };
52 
53 template<typename XprType, template <class> class MakePointer_>
54 struct nested<TensorEvalToOp<XprType, MakePointer_>, 1, typename eval<TensorEvalToOp<XprType, MakePointer_> >::type>
55 {
57 };
58 
59 } // end namespace internal
60 
61 
62 
63 
64 template<typename XprType, template <class> class MakePointer_>
65 class TensorEvalToOp : public TensorBase<TensorEvalToOp<XprType, MakePointer_>, ReadOnlyAccessors>
66 {
67  public:
75 
76  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvalToOp(PointerType buffer, const XprType& expr)
77  : m_xpr(expr), m_buffer(buffer) {}
78 
79  EIGEN_DEVICE_FUNC
81  expression() const { return m_xpr; }
82 
83  EIGEN_DEVICE_FUNC PointerType buffer() const { return m_buffer; }
84 
85  protected:
86  typename XprType::Nested m_xpr;
87  PointerType m_buffer;
88 };
89 
90 
91 
92 template<typename ArgType, typename Device, template <class> class MakePointer_>
93 struct TensorEvaluator<const TensorEvalToOp<ArgType, MakePointer_>, Device>
94 {
96  typedef typename ArgType::Scalar Scalar;
98  typedef typename XprType::Index Index;
102 
103  enum {
107  CoordAccess = false, // to be implemented
108  RawAccess = true
109  };
110 
111  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device)
112  : m_impl(op.expression(), device), m_device(device),
113  m_buffer(op.buffer()), m_op(op), m_expression(op.expression())
114  { }
115 
116  // Used for accessor extraction in SYCL Managed TensorMap:
117  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const XprType& op() const {
118  return m_op;
119  }
120 
121  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ~TensorEvaluator() {
122  }
123 
125  EIGEN_DEVICE_FUNC const Dimensions& dimensions() const { return m_impl.dimensions(); }
126 
127  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(DevicePointer scalar) {
128  EIGEN_UNUSED_VARIABLE(scalar);
129  eigen_assert(scalar == NULL);
130  return m_impl.evalSubExprsIfNeeded(m_buffer);
131  }
132 
133  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalScalar(Index i) {
134  m_buffer[i] = m_impl.coeff(i);
135  }
136  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalPacket(Index i) {
137  internal::pstoret<CoeffReturnType, PacketReturnType, Aligned>(m_buffer + i, m_impl.template packet<TensorEvaluator<ArgType, Device>::IsAligned ? Aligned : Unaligned>(i));
138  }
139 
140  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() {
141  m_impl.cleanup();
142  }
143 
144  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
145  {
146  return m_buffer[index];
147  }
148 
149  template<int LoadMode>
150  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
151  {
152  return internal::ploadt<PacketReturnType, LoadMode>(m_buffer + index);
153  }
154 
155  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const {
156  // We assume that evalPacket or evalScalar is called to perform the
157  // assignment and account for the cost of the write here.
158  return m_impl.costPerCoeff(vectorized) +
159  TensorOpCost(0, sizeof(CoeffReturnType), 0, vectorized, PacketSize);
160  }
161 
162  EIGEN_DEVICE_FUNC DevicePointer data() const { return m_buffer; }
163  ArgType expression() const { return m_expression; }
164 
166  const TensorEvaluator<ArgType, Device>& impl() const { return m_impl; }
168  const Device& device() const{return m_device;}
169 
170  private:
172  const Device& m_device;
173  DevicePointer m_buffer;
174  const XprType& m_op;
175  const ArgType m_expression;
176 };
177 
178 
179 } // end namespace Eigen
180 
181 #endif // EIGEN_CXX11_TENSOR_TENSOR_EVAL_TO_H
const Device & device() const
added for sycl in order to construct the buffer from the sycl device
Definition: TensorEvalTo.h:168
EIGEN_DEVICE_FUNC const internal::remove_all< typename XprType::Nested >::type & expression() const
Definition: TensorEvalTo.h:81
#define EIGEN_STRONG_INLINE
Definition: Macros.h:493
const TensorEvaluator< ArgType, Device > & impl() const
required by sycl in order to extract the accessor
Definition: TensorEvalTo.h:166
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalPacket(Index i)
Definition: TensorEvalTo.h:136
Definition: LDLT.h:16
A cost model used to limit the number of threads used for evaluating tensor expression.
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(DevicePointer scalar)
Definition: TensorEvalTo.h:127
Eigen::internal::traits< TensorEvalToOp >::Scalar Scalar
Definition: TensorEvalTo.h:68
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
Definition: TensorEvalTo.h:155
Eigen::internal::nested< TensorEvalToOp >::type Nested
Definition: TensorEvalTo.h:72
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvalToOp(PointerType buffer, const XprType &expr)
Definition: TensorEvalTo.h:76
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const XprType & op() const
Definition: TensorEvalTo.h:117
Eigen::internal::traits< TensorEvalToOp >::Index Index
Definition: TensorEvalTo.h:74
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
#define eigen_assert(x)
Definition: Macros.h:577
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
Definition: TensorEvalTo.h:150
MakePointer_< CoeffReturnType >::Type PointerType
Definition: TensorEvalTo.h:71
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
Definition: TensorEvalTo.h:144
PointerType m_buffer
Definition: TensorEvalTo.h:87
The tensor base class.
Definition: TensorBase.h:827
EIGEN_DEVICE_FUNC PointerType buffer() const
Definition: TensorEvalTo.h:83
internal::remove_const< typename XprType::CoeffReturnType >::type CoeffReturnType
Definition: TensorEvalTo.h:70
Eigen::internal::traits< TensorEvalToOp >::StorageKind StorageKind
Definition: TensorEvalTo.h:73
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
Definition: TensorEvalTo.h:111
Eigen::NumTraits< Scalar >::Real RealScalar
Definition: TensorEvalTo.h:69
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalScalar(Index i)
Definition: TensorEvalTo.h:133
internal::remove_const< typename XprType::CoeffReturnType >::type CoeffReturnType
Definition: TensorEvalTo.h:99
#define EIGEN_UNUSED_VARIABLE(var)
Definition: Macros.h:616
internal::packet_traits< Scalar >::type type
Definition: TensorMeta.h:51
internal::traits< const TensorEvalToOp< ArgType, MakePointer_ > >::template MakePointer< CoeffReturnType >::Type DevicePointer
Definition: TensorEvalTo.h:124
XprType::Nested m_xpr
Definition: TensorEvalTo.h:86


hebiros
Author(s): Xavier Artache , Matthew Tesch
autogenerated on Thu Sep 3 2020 04:09:17