TensorForcedEval.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_FORCED_EVAL_H
11 #define EIGEN_CXX11_TENSOR_TENSOR_FORCED_EVAL_H
12 
13 namespace Eigen {
14 
15 namespace internal {
16 template<typename XprType, template <class> class MakePointer_>
17 struct traits<TensorForcedEvalOp<XprType, MakePointer_> >
18 {
19  // Type promotion to handle the case where the types of the lhs and the rhs are different.
20  typedef typename XprType::Scalar Scalar;
23  typedef typename traits<XprType>::Index Index;
24  typedef typename XprType::Nested Nested;
26  static const int NumDimensions = XprTraits::NumDimensions;
27  static const int Layout = XprTraits::Layout;
28 
29  enum {
30  Flags = 0
31  };
32  template <class T> struct MakePointer {
33  // Intermediate typedef to workaround MSVC issue.
34  typedef MakePointer_<T> MakePointerT;
35  typedef typename MakePointerT::Type Type;
36  };
37 };
38 
39 template<typename XprType, template <class> class MakePointer_>
40 struct eval<TensorForcedEvalOp<XprType, MakePointer_>, Eigen::Dense>
41 {
43 };
44 
45 template<typename XprType, template <class> class MakePointer_>
46 struct nested<TensorForcedEvalOp<XprType, MakePointer_>, 1, typename eval<TensorForcedEvalOp<XprType, MakePointer_> >::type>
47 {
49 };
50 
51 } // end namespace internal
52 
53 
54 
55 // FIXME use proper doxygen documentation (e.g. \tparam MakePointer_)
56 
64 template<typename XprType, template <class> class MakePointer_>
71 class TensorForcedEvalOp : public TensorBase<TensorForcedEvalOp<XprType, MakePointer_>, ReadOnlyAccessors>
72 {
73  public:
80 
81  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorForcedEvalOp(const XprType& expr)
82  : m_xpr(expr) {}
83 
84  EIGEN_DEVICE_FUNC
86  expression() const { return m_xpr; }
87 
88  protected:
89  typename XprType::Nested m_xpr;
90 };
91 
92 
93 template<typename ArgType, typename Device, template <class> class MakePointer_>
94 struct TensorEvaluator<const TensorForcedEvalOp<ArgType, MakePointer_>, Device>
95 {
97  typedef typename ArgType::Scalar Scalar;
99  typedef typename XprType::Index Index;
103 
104  enum {
105  IsAligned = true,
106  PacketAccess = (PacketSize > 1),
108  RawAccess = true
109  };
110 
111  EIGEN_DEVICE_FUNC TensorEvaluator(const XprType& op, const Device& device)
113  : m_impl(op.expression(), device), m_op(op.expression()), m_device(device), m_buffer(NULL)
114  { }
115 
116  EIGEN_DEVICE_FUNC const Dimensions& dimensions() const { return m_impl.dimensions(); }
117 
119  const Index numValues = internal::array_prod(m_impl.dimensions());
120  m_buffer = (CoeffReturnType*)m_device.allocate(numValues * sizeof(CoeffReturnType));
121  // Should initialize the memory in case we're dealing with non POD types.
123  for (Index i = 0; i < numValues; ++i) {
124  new(m_buffer+i) CoeffReturnType();
125  }
126  }
128  EvalTo evalToTmp(m_buffer, m_op);
131  return true;
132  }
133  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() {
134  m_device.deallocate(m_buffer);
135  m_buffer = NULL;
136  }
137 
138  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
139  {
140  return m_buffer[index];
141  }
142 
143  template<int LoadMode>
144  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
145  {
146  return internal::ploadt<PacketReturnType, LoadMode>(m_buffer + index);
147  }
148 
149  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const {
150  return TensorOpCost(sizeof(CoeffReturnType), 0, 0, vectorized, PacketSize);
151  }
152 
153  EIGEN_DEVICE_FUNC typename MakePointer<Scalar>::Type data() const { return m_buffer; }
154 
158  const Device& device() const{return m_device;}
159  private:
161  const ArgType m_op;
162  const Device& m_device;
164 };
165 
166 
167 } // end namespace Eigen
168 
169 #endif // EIGEN_CXX11_TENSOR_TENSOR_FORCED_EVAL_H
Eigen::TensorForcedEvalOp::m_xpr
XprType::Nested m_xpr
Definition: TensorForcedEval.h:89
Eigen::TensorEvaluator::device
const Device & device() const
required by sycl in order to construct sycl buffer from raw pointer
Definition: TensorEvaluator.h:114
Eigen::internal::traits< TensorForcedEvalOp< XprType, MakePointer_ > >::StorageKind
traits< XprType >::StorageKind StorageKind
Definition: TensorForcedEval.h:22
Eigen
Definition: common.h:73
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType, MakePointer_ >, Device >::m_impl
TensorEvaluator< ArgType, Device > m_impl
Definition: TensorForcedEval.h:160
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType, MakePointer_ >, Device >::XprType
TensorForcedEvalOp< ArgType, MakePointer_ > XprType
Definition: TensorForcedEval.h:96
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType, MakePointer_ >, Device >::cleanup
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup()
Definition: TensorForcedEval.h:133
Eigen::internal::IsVectorizable
Definition: TensorForwardDeclarations.h:91
Eigen::TensorEvaluator::m_device
const Device & m_device
Definition: TensorEvaluator.h:119
Eigen::internal::nested
Definition: TensorTraits.h:170
Eigen::TensorEvaluator::PacketAccess
@ PacketAccess
Definition: TensorEvaluator.h:42
Eigen::TensorForcedEvalOp::expression
const EIGEN_DEVICE_FUNC internal::remove_all< typename XprType::Nested >::type & expression() const
Definition: TensorForcedEval.h:86
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType, MakePointer_ >, Device >::costPerCoeff
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
Definition: TensorForcedEval.h:149
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType, MakePointer_ >, Device >::evalSubExprsIfNeeded
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(CoeffReturnType *)
Definition: TensorForcedEval.h:118
Eigen::internal::traits< TensorForcedEvalOp< XprType, MakePointer_ > >::MakePointer::MakePointerT
MakePointer_< T > MakePointerT
Definition: TensorForcedEval.h:34
Eigen::TensorEvaluator::m_impl
const Derived & m_impl
Definition: TensorEvaluator.h:120
Eigen::PacketType::type
internal::packet_traits< Scalar >::type type
Definition: TensorMeta.h:51
Eigen::internal::remove_all::type
T type
Definition: Meta.h:78
Scalar
SCALAR Scalar
Definition: common.h:84
Eigen::TensorForcedEvalOp::RealScalar
Eigen::NumTraits< Scalar >::Real RealScalar
Definition: TensorForcedEval.h:75
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType, MakePointer_ >, Device >::impl
const TensorEvaluator< ArgType, Device > & impl()
required by sycl in order to extract the sycl accessor
Definition: TensorForcedEval.h:156
Eigen::TensorForcedEvalOp
Tensor reshaping class.
Definition: TensorForcedEval.h:71
Eigen::TensorForcedEvalOp::Index
Eigen::internal::traits< TensorForcedEvalOp >::Index Index
Definition: TensorForcedEval.h:79
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType, MakePointer_ >, Device >::dimensions
const EIGEN_DEVICE_FUNC Dimensions & dimensions() const
Definition: TensorForcedEval.h:116
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType, MakePointer_ >, Device >::m_device
const Device & m_device
Definition: TensorForcedEval.h:162
Eigen::internal::true_type
Definition: Meta.h:54
Eigen::internal::remove_reference::type
T type
Definition: Meta.h:66
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType, MakePointer_ >, Device >::device
const Device & device() const
used by sycl in order to build the sycl buffer
Definition: TensorForcedEval.h:158
Eigen::TensorForcedEvalOp::Nested
Eigen::internal::nested< TensorForcedEvalOp >::type Nested
Definition: TensorForcedEval.h:77
Eigen::MakePointer
Definition: TensorForwardDeclarations.h:21
Eigen::internal::unpacket_traits
Definition: XprHelper.h:158
Eigen::Architecture::Type
Type
Definition: Constants.h:461
Eigen::TensorEvaluator::IsAligned
@ IsAligned
Definition: TensorEvaluator.h:41
Eigen::internal::traits< TensorForcedEvalOp< XprType, MakePointer_ > >::_Nested
remove_reference< Nested >::type _Nested
Definition: TensorForcedEval.h:25
EIGEN_STRONG_INLINE
#define EIGEN_STRONG_INLINE
Definition: Macros.h:494
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType, MakePointer_ >, Device >::PacketReturnType
PacketType< CoeffReturnType, Device >::type PacketReturnType
Definition: TensorForcedEval.h:101
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType, MakePointer_ >, Device >::m_op
const ArgType m_op
Definition: TensorForcedEval.h:161
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType, MakePointer_ >, Device >::data
EIGEN_DEVICE_FUNC MakePointer< Scalar >::Type data() const
Definition: TensorForcedEval.h:153
Eigen::TensorForcedEvalOp::Scalar
Eigen::internal::traits< TensorForcedEvalOp >::Scalar Scalar
Definition: TensorForcedEval.h:74
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType, MakePointer_ >, Device >::CoeffReturnType
XprType::CoeffReturnType CoeffReturnType
Definition: TensorForcedEval.h:100
Eigen::internal::traits< TensorForcedEvalOp< XprType, MakePointer_ > >::MakePointer::Type
MakePointerT::Type Type
Definition: TensorForcedEval.h:35
Eigen::TensorBase
The tensor base class.
Definition: TensorBase.h:829
Eigen::TensorEvaluator::Layout
@ Layout
Definition: TensorEvaluator.h:43
Eigen::internal::array_prod
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_prod(const Sizes< Indices... > &)
Definition: TensorDimensions.h:138
Eigen::internal::traits< TensorForcedEvalOp< XprType, MakePointer_ > >::XprTraits
traits< XprType > XprTraits
Definition: TensorForcedEval.h:21
Eigen::internal::remove_const::type
T type
Definition: Meta.h:73
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType, MakePointer_ >, Device >::packet
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
Definition: TensorForcedEval.h:144
Eigen::internal::TensorExecutor
Definition: TensorExecutor.h:27
Eigen::internal::nested< TensorForcedEvalOp< XprType, MakePointer_ >, 1, typename eval< TensorForcedEvalOp< XprType, MakePointer_ > >::type >::type
TensorForcedEvalOp< XprType, MakePointer_ > type
Definition: TensorForcedEval.h:48
Eigen::internal::eval< TensorForcedEvalOp< XprType, MakePointer_ >, Eigen::Dense >::type
const typedef TensorForcedEvalOp< XprType, MakePointer_ > & type
Definition: TensorForcedEval.h:42
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType, MakePointer_ >, Device >::Scalar
ArgType::Scalar Scalar
Definition: TensorForcedEval.h:97
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType, MakePointer_ >, Device >::TensorEvaluator
EIGEN_DEVICE_FUNC TensorEvaluator(const XprType &op, const Device &device)
op_ is used for sycl
Definition: TensorForcedEval.h:111
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType, MakePointer_ >, Device >::Dimensions
TensorEvaluator< ArgType, Device >::Dimensions Dimensions
Definition: TensorForcedEval.h:98
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType, MakePointer_ >, Device >::Index
XprType::Index Index
Definition: TensorForcedEval.h:99
Eigen::internal::traits
Definition: ForwardDeclarations.h:17
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType, MakePointer_ >, Device >::m_buffer
MakePointer< CoeffReturnType >::Type m_buffer
Definition: TensorForcedEval.h:163
Eigen::TensorSycl::run
void run(Expr &expr, Dev &dev)
Definition: TensorSyclRun.h:47
Eigen::internal::traits< TensorForcedEvalOp< XprType, MakePointer_ > >::Index
traits< XprType >::Index Index
Definition: TensorForcedEval.h:23
Eigen::TensorEvaluator
A cost model used to limit the number of threads used for evaluating tensor expression.
Definition: TensorEvaluator.h:28
Eigen::internal::traits< TensorForcedEvalOp< XprType, MakePointer_ > >::Scalar
XprType::Scalar Scalar
Definition: TensorForcedEval.h:20
internal
Definition: BandTriangularSolver.h:13
Eigen::TensorForcedEvalOp::StorageKind
Eigen::internal::traits< TensorForcedEvalOp >::StorageKind StorageKind
Definition: TensorForcedEval.h:78
Eigen::TensorEvaluator::CoeffReturnType
Derived::Scalar CoeffReturnType
Definition: TensorEvaluator.h:32
Eigen::internal::eval
Definition: XprHelper.h:312
Eigen::internal::traits< TensorForcedEvalOp< XprType, MakePointer_ > >::Nested
XprType::Nested Nested
Definition: TensorForcedEval.h:24
Eigen::TensorOpCost
Definition: TensorCostModel.h:25
Eigen::NumTraits
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:150
Eigen::TensorForcedEvalOp::TensorForcedEvalOp
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorForcedEvalOp(const XprType &expr)
Definition: TensorForcedEval.h:81
Eigen::TensorForcedEvalOp::CoeffReturnType
internal::remove_const< typename XprType::CoeffReturnType >::type CoeffReturnType
Definition: TensorForcedEval.h:76
Eigen::GenericNumTraits::Real
T Real
Definition: NumTraits.h:100
Eigen::TensorEvalToOp
Definition: TensorEvalTo.h:65
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType, MakePointer_ >, Device >::coeff
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
Definition: TensorForcedEval.h:138
Eigen::Dense
Definition: Constants.h:491
Eigen::MakePointer::Type
T * Type
Definition: TensorForwardDeclarations.h:22


control_box_rst
Author(s): Christoph Rösmann
autogenerated on Wed Mar 2 2022 00:06:44