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;
36 
37  enum {
38  Flags = 0
39  };
40  template <class T>
41  struct MakePointer {
42  // Intermediate typedef to workaround MSVC issue.
43  typedef MakePointer_<T> MakePointerT;
44  typedef typename MakePointerT::Type Type;
45 
46 
47  };
48 };
49 
50 template<typename XprType, template <class> class MakePointer_>
51 struct eval<TensorEvalToOp<XprType, MakePointer_>, Eigen::Dense>
52 {
54 };
55 
56 template<typename XprType, template <class> class MakePointer_>
57 struct nested<TensorEvalToOp<XprType, MakePointer_>, 1, typename eval<TensorEvalToOp<XprType, MakePointer_> >::type>
58 {
60 };
61 
62 } // end namespace internal
63 
64 
65 
66 
67 template<typename XprType, template <class> class MakePointer_>
68 class TensorEvalToOp : public TensorBase<TensorEvalToOp<XprType, MakePointer_>, ReadOnlyAccessors>
69 {
70  public:
78 
80 
82  : m_xpr(expr), m_buffer(buffer) {}
83 
86  expression() const { return m_xpr; }
87 
89 
90  protected:
91  typename XprType::Nested m_xpr;
93 };
94 
95 
96 
97 template<typename ArgType, typename Device, template <class> class MakePointer_>
98 struct TensorEvaluator<const TensorEvalToOp<ArgType, MakePointer_>, Device>
99 {
101  typedef typename ArgType::Scalar Scalar;
103  typedef typename XprType::Index Index;
110  enum {
113  BlockAccess = true,
116  CoordAccess = false, // to be implemented
117  RawAccess = true
118  };
119 
120  static const int NumDims = internal::traits<ArgType>::NumDimensions;
121 
122  //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===//
125 
128 
130  CoeffReturnType, NumDims, typename ArgTensorBlock::XprType, Index>
132  //===--------------------------------------------------------------------===//
133 
134  EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device)
135  : m_impl(op.expression(), device), m_buffer(device.get(op.buffer())), m_expression(op.expression()){}
136 
137 
139  }
140 
141 
142  EIGEN_DEVICE_FUNC const Dimensions& dimensions() const { return m_impl.dimensions(); }
143 
147  return m_impl.evalSubExprsIfNeeded(m_buffer);
148  }
149 
150 #ifdef EIGEN_USE_THREADS
151  template <typename EvalSubExprsCallback>
152  EIGEN_STRONG_INLINE void evalSubExprsIfNeededAsync(
153  EvaluatorPointerType scalar, EvalSubExprsCallback done) {
156  m_impl.evalSubExprsIfNeededAsync(m_buffer, std::move(done));
157  }
158 #endif
159 
161  m_buffer[i] = m_impl.coeff(i);
162  }
164  internal::pstoret<CoeffReturnType, PacketReturnType, Aligned>(m_buffer + i, m_impl.template packet<TensorEvaluator<ArgType, Device>::IsAligned ? Aligned : Unaligned>(i));
165  }
166 
169  return m_impl.getResourceRequirements();
170  }
171 
174  // Add `m_buffer` as destination buffer to the block descriptor.
175  desc.template AddDestinationBuffer<Layout>(
176  /*dst_base=*/m_buffer + desc.offset(),
177  /*dst_strides=*/internal::strides<Layout>(m_impl.dimensions()));
178 
180  m_impl.block(desc, scratch, /*root_of_expr_ast=*/true);
181 
182  // If block was evaluated into a destination buffer, there is no need to do
183  // an assignment.
185  TensorBlockAssignment::Run(
186  TensorBlockAssignment::target(
187  desc.dimensions(), internal::strides<Layout>(m_impl.dimensions()),
188  m_buffer, desc.offset()),
189  block.expr());
190  }
191  block.cleanup();
192  }
193 
195  m_impl.cleanup();
196  }
197 
199  {
200  return m_buffer[index];
201  }
202 
203  template<int LoadMode>
205  {
206  return internal::ploadt<PacketReturnType, LoadMode>(m_buffer + index);
207  }
208 
210  // We assume that evalPacket or evalScalar is called to perform the
211  // assignment and account for the cost of the write here.
212  return m_impl.costPerCoeff(vectorized) +
213  TensorOpCost(0, sizeof(CoeffReturnType), 0, vectorized, PacketSize);
214  }
215 
216  EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return m_buffer; }
217  ArgType expression() const { return m_expression; }
218  #ifdef EIGEN_USE_SYCL
219  // binding placeholder accessors to a command group handler for SYCL
220  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const {
221  m_impl.bind(cgh);
222  m_buffer.bind(cgh);
223  }
224  #endif
225 
226 
227  private:
230  const ArgType m_expression;
231 };
232 
233 
234 } // end namespace Eigen
235 
236 #endif // EIGEN_CXX11_TENSOR_TENSOR_EVAL_TO_H
Eigen::internal::TensorBlockScratchAllocator
Definition: TensorBlock.h:525
Eigen::TensorEvalToOp::buffer
EIGEN_DEVICE_FUNC PointerType buffer() const
Definition: TensorEvalTo.h:88
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::EvaluatorPointerType
Storage::Type EvaluatorPointerType
Definition: TensorEvalTo.h:109
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::m_impl
TensorEvaluator< ArgType, Device > m_impl
Definition: TensorEvalTo.h:228
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::TensorBlockScratch
internal::TensorBlockScratchAllocator< Device > TensorBlockScratch
Definition: TensorEvalTo.h:124
Eigen::CwiseBinaryOp
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:77
Eigen::internal::traits< TensorEvalToOp< XprType, MakePointer_ > >::StorageKind
XprTraits::StorageKind StorageKind
Definition: TensorEvalTo.h:29
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::expression
ArgType expression() const
Definition: TensorEvalTo.h:217
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::costPerCoeff
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
Definition: TensorEvalTo.h:209
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::coeff
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
Definition: TensorEvalTo.h:198
Eigen::internal::nested
Definition: TensorTraits.h:174
Eigen::Unaligned
@ Unaligned
Definition: Constants.h:233
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::XprType
TensorEvalToOp< ArgType, MakePointer_ > XprType
Definition: TensorEvalTo.h:100
Eigen::TensorEvalToOp::m_xpr
XprType::Nested m_xpr
Definition: TensorEvalTo.h:91
eigen_assert
#define eigen_assert(x)
Definition: Macros.h:1037
Eigen::TensorEvaluator::Layout
@ Layout
Definition: TensorEvaluator.h:50
Eigen::internal::traits< TensorEvalToOp< XprType, MakePointer_ > >::XprTraits
traits< XprType > XprTraits
Definition: TensorEvalTo.h:28
Eigen::TensorEvalToOp::Index
Eigen::internal::traits< TensorEvalToOp >::Index Index
Definition: TensorEvalTo.h:77
Eigen::internal::traits< TensorEvalToOp< XprType, MakePointer_ > >::Index
XprTraits::Index Index
Definition: TensorEvalTo.h:30
Eigen::internal::TensorMaterializedBlock
Definition: TensorBlock.h:656
Eigen::internal::eval< TensorEvalToOp< XprType, MakePointer_ >, Eigen::Dense >::type
const typedef TensorEvalToOp< XprType, MakePointer_ > & type
Definition: TensorEvalTo.h:53
buffer
Definition: pytypes.h:2270
Eigen::internal::traits< TensorEvalToOp< XprType, MakePointer_ > >::PointerType
MakePointer_< Scalar >::Type PointerType
Definition: TensorEvalTo.h:35
Eigen::TensorEvaluator::packet
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
Definition: TensorEvaluator.h:105
Eigen::TensorEvalToOp::TensorEvalToOp
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvalToOp(PointerType buffer, const XprType &expr)
Definition: TensorEvalTo.h:81
Eigen::TensorEvaluator::PacketSize
static const int PacketSize
Definition: TensorEvaluator.h:36
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::TensorEvaluator
EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
Definition: TensorEvalTo.h:134
make_changelog.desc
desc
Definition: make_changelog.py:71
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::ArgTensorBlock
TensorEvaluator< const ArgType, Device >::TensorBlock ArgTensorBlock
Definition: TensorEvalTo.h:127
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::data
EIGEN_DEVICE_FUNC EvaluatorPointerType data() const
Definition: TensorEvalTo.h:216
Eigen::PacketType
Definition: TensorMeta.h:50
Eigen::internal::nested< TensorEvalToOp< XprType, MakePointer_ >, 1, typename eval< TensorEvalToOp< XprType, MakePointer_ > >::type >::type
TensorEvalToOp< XprType, MakePointer_ > type
Definition: TensorEvalTo.h:59
Eigen::internal::TensorBlockDescriptor< NumDims, Index >
Eigen::internal::true_type
Definition: Meta.h:96
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::TensorBlockAssignment
internal::TensorBlockAssignment< CoeffReturnType, NumDims, typename ArgTensorBlock::XprType, Index > TensorBlockAssignment
Definition: TensorEvalTo.h:131
EIGEN_UNUSED_VARIABLE
#define EIGEN_UNUSED_VARIABLE(var)
Definition: Macros.h:1076
Eigen::TensorEvalToOp::PointerType
MakePointer_< CoeffReturnType >::Type PointerType
Definition: TensorEvalTo.h:74
scalar
mxArray * scalar(mxClassID classid)
Definition: matlab.h:82
Eigen::MakePointer
Definition: TensorForwardDeclarations.h:21
Eigen::TensorEvalToOp::StorageKind
Eigen::internal::traits< TensorEvalToOp >::StorageKind StorageKind
Definition: TensorEvalTo.h:76
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::cleanup
EIGEN_STRONG_INLINE void cleanup()
Definition: TensorEvalTo.h:194
Eigen::Architecture::Type
Type
Definition: Constants.h:471
EIGEN_STRONG_INLINE
#define EIGEN_STRONG_INLINE
Definition: Macros.h:917
Eigen::TensorEvalToOp::RealScalar
Eigen::NumTraits< Scalar >::Real RealScalar
Definition: TensorEvalTo.h:72
Eigen::TensorEvaluator::PreferBlockAccess
@ PreferBlockAccess
Definition: TensorEvaluator.h:49
Eigen::TensorEvalToOp::Scalar
Eigen::internal::traits< TensorEvalToOp >::Scalar Scalar
Definition: TensorEvalTo.h:71
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::Storage
StorageMemory< CoeffReturnType, Device > Storage
Definition: TensorEvalTo.h:108
Eigen::TensorEvalToOp::expression
const EIGEN_DEVICE_FUNC internal::remove_all< typename XprType::Nested >::type & expression() const
Definition: TensorEvalTo.h:86
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::TensorPointerType
Eigen::internal::traits< XprType >::PointerType TensorPointerType
Definition: TensorEvalTo.h:107
Eigen::internal::TensorMaterializedBlock::cleanup
void cleanup()
Definition: TensorBlock.h:682
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::getResourceRequirements
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE internal::TensorBlockResourceRequirements getResourceRequirements() const
Definition: TensorEvalTo.h:168
Eigen::Triplet< double >
Eigen::internal::traits< TensorEvalToOp< XprType, MakePointer_ > >::MakePointer::Type
MakePointerT::Type Type
Definition: TensorEvalTo.h:44
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::evalScalar
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalScalar(Index i)
Definition: TensorEvalTo.h:160
Eigen::StorageMemory
Definition: TensorForwardDeclarations.h:37
Eigen::internal::kMaterializedInOutput
@ kMaterializedInOutput
Definition: TensorBlock.h:610
Eigen::TensorBase
The tensor base class.
Definition: TensorBase.h:973
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::TensorBlockDesc
internal::TensorBlockDescriptor< NumDims, Index > TensorBlockDesc
Definition: TensorEvalTo.h:123
XprType
CwiseBinaryOp< internal::scalar_sum_op< double, double >, const CpyMatrixXd, const CpyMatrixXd > XprType
Definition: nestbyvalue.cpp:15
Eigen::TensorEvaluator::BlockAccess
@ BlockAccess
Definition: TensorEvaluator.h:48
Eigen::internal::TensorBlockAssignment
Definition: TensorBlock.h:1381
Eigen::TensorEvalToOp::Nested
Eigen::internal::nested< TensorEvalToOp >::type Nested
Definition: TensorEvalTo.h:75
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::m_buffer
EvaluatorPointerType m_buffer
Definition: TensorEvalTo.h:229
Eigen::internal::traits
Definition: ForwardDeclarations.h:17
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::Index
XprType::Index Index
Definition: TensorEvalTo.h:103
Eigen::TensorEvalToOp::NumDims
static const int NumDims
Definition: TensorEvalTo.h:79
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::PacketReturnType
PacketType< CoeffReturnType, Device >::type PacketReturnType
Definition: TensorEvalTo.h:105
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::packet
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
Definition: TensorEvalTo.h:204
Eigen::TensorEvaluator::EvaluatorPointerType
Storage::Type EvaluatorPointerType
Definition: TensorEvaluator.h:39
Eigen::internal::TensorBlockResourceRequirements
Definition: TensorBlock.h:75
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::m_expression
const ArgType m_expression
Definition: TensorEvalTo.h:230
Eigen::internal::traits< TensorEvalToOp< XprType, MakePointer_ > >::Nested
XprType::Nested Nested
Definition: TensorEvalTo.h:31
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::Scalar
ArgType::Scalar Scalar
Definition: TensorEvalTo.h:101
Eigen::TensorEvaluator
A cost model used to limit the number of threads used for evaluating tensor expression.
Definition: TensorEvaluator.h:28
Eigen::TensorEvalToOp::m_buffer
PointerType m_buffer
Definition: TensorEvalTo.h:92
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::~TensorEvaluator
EIGEN_STRONG_INLINE ~TensorEvaluator()
Definition: TensorEvalTo.h:138
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::evalSubExprsIfNeeded
EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType scalar)
Definition: TensorEvalTo.h:144
Eigen::internal::TensorMaterializedBlock::expr
const XprType & expr() const
Definition: TensorBlock.h:677
internal
Definition: BandTriangularSolver.h:13
Eigen::TensorEvaluator::CoeffReturnType
Derived::Scalar CoeffReturnType
Definition: TensorEvaluator.h:32
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::dimensions
const EIGEN_DEVICE_FUNC Dimensions & dimensions() const
Definition: TensorEvalTo.h:142
NULL
#define NULL
Definition: ccolamd.c:609
Eigen::internal::traits< TensorEvalToOp< XprType, MakePointer_ > >::MakePointer::MakePointerT
MakePointer_< T > MakePointerT
Definition: TensorEvalTo.h:43
Eigen::TensorEvaluator::IsAligned
@ IsAligned
Definition: TensorEvaluator.h:46
Eigen::internal::traits< TensorEvalToOp< XprType, MakePointer_ > >::_Nested
remove_reference< Nested >::type _Nested
Definition: TensorEvalTo.h:32
Eigen::TensorEvaluator::block
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock block(TensorBlockDesc &desc, TensorBlockScratch &scratch, bool=false) const
Definition: TensorEvaluator.h:158
Eigen::TensorEvalToOp::CoeffReturnType
internal::remove_const< typename XprType::CoeffReturnType >::type CoeffReturnType
Definition: TensorEvalTo.h:73
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::CoeffReturnType
internal::remove_const< typename XprType::CoeffReturnType >::type CoeffReturnType
Definition: TensorEvalTo.h:104
Eigen::internal::eval
Definition: XprHelper.h:332
Eigen::TensorEvaluator::PacketAccess
@ PacketAccess
Definition: TensorEvaluator.h:47
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::Dimensions
TensorEvaluator< ArgType, Device >::Dimensions Dimensions
Definition: TensorEvalTo.h:102
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::evalBlock
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalBlock(TensorBlockDesc &desc, TensorBlockScratch &scratch)
Definition: TensorEvalTo.h:172
get
Container::iterator get(Container &c, Position position)
Definition: stdlist_overload.cpp:29
Eigen::TensorOpCost
Definition: TensorCostModel.h:25
Eigen::TensorEvaluator< const TensorEvalToOp< ArgType, MakePointer_ >, Device >::evalPacket
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalPacket(Index i)
Definition: TensorEvalTo.h:163
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Eigen::internal::traits< TensorEvalToOp< XprType, MakePointer_ > >::Scalar
XprType::Scalar Scalar
Definition: TensorEvalTo.h:27
Eigen::TensorEvalToOp
Definition: TensorEvalTo.h:68
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Eigen::Aligned
@ Aligned
Definition: Constants.h:240
Eigen::Dense
Definition: Constants.h:507
Eigen::internal::TensorMaterializedBlock::kind
TensorBlockKind kind() const
Definition: TensorBlock.h:673


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:37:35