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 
22 namespace internal {
23 template<typename XprType>
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;
30  typedef typename traits<XprType>::Index Index;
31  typedef typename XprType::Nested Nested;
33  static const int NumDimensions = XprTraits::NumDimensions;
34  static const int Layout = XprTraits::Layout;
35  typedef typename XprTraits::PointerType PointerType;
36 
37  enum {
38  Flags = 0
39  };
40 };
41 
42 template<typename XprType>
44 {
46 };
47 
48 template<typename XprType>
50 {
52 };
53 
54 } // end namespace internal
55 
56 
57 
58 template<typename XprType>
59 class TensorForcedEvalOp : public TensorBase<TensorForcedEvalOp<XprType>, ReadOnlyAccessors>
60 {
61  public:
68 
70  : m_xpr(expr) {}
71 
74  expression() const { return m_xpr; }
75 
76  protected:
77  typename XprType::Nested m_xpr;
78 };
79 
80 namespace internal {
81 template <typename Device, typename CoeffReturnType>
83  template <typename StorageType>
84 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void operator()(Index numValues, StorageType m_buffer) {
85  // Initialize non-trivially constructible types.
87  for (Index i = 0; i < numValues; ++i) new (m_buffer + i) CoeffReturnType();
88  }
89 }
90 };
91 
92 // SYCL does not support non-integral types
93 // having new (m_buffer + i) CoeffReturnType() causes the following compiler error for SYCL Devices
94 // no matching function for call to 'operator new'
95 template <typename CoeffReturnType>
96 struct non_integral_type_placement_new<Eigen::SyclDevice, CoeffReturnType> {
97  template <typename StorageType>
99 }
100 };
101 } // end namespace internal
102 
103 template<typename ArgType_, typename Device>
104 struct TensorEvaluator<const TensorForcedEvalOp<ArgType_>, Device>
105 {
108  typedef typename ArgType::Scalar Scalar;
110  typedef typename XprType::Index Index;
117 
118  enum {
119  IsAligned = true,
124  RawAccess = true
125  };
126 
127  static const int NumDims = internal::traits<ArgType>::NumDimensions;
128 
129  //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===//
132 
133  typedef typename internal::TensorMaterializedBlock<CoeffReturnType, NumDims,
134  Layout, Index>
136  //===--------------------------------------------------------------------===//
137 
138  TensorEvaluator(const XprType& op, const Device& device)
139  : m_impl(op.expression(), device), m_op(op.expression()),
140  m_device(device), m_buffer(NULL)
141  { }
142 
143  EIGEN_DEVICE_FUNC const Dimensions& dimensions() const { return m_impl.dimensions(); }
144 
146  const Index numValues = internal::array_prod(m_impl.dimensions());
147  m_buffer = m_device.get((CoeffReturnType*)m_device.allocate_temp(numValues * sizeof(CoeffReturnType)));
148 
150 
152  EvalTo evalToTmp(m_device.get(m_buffer), m_op);
153 
155  const EvalTo, typename internal::remove_const<Device>::type,
158  run(evalToTmp, m_device);
159 
160  return true;
161  }
162 
163 #ifdef EIGEN_USE_THREADS
164  template <typename EvalSubExprsCallback>
165  EIGEN_STRONG_INLINE void evalSubExprsIfNeededAsync(
166  EvaluatorPointerType, EvalSubExprsCallback done) {
167  const Index numValues = internal::array_prod(m_impl.dimensions());
168  m_buffer = m_device.get((CoeffReturnType*)m_device.allocate_temp(
169  numValues * sizeof(CoeffReturnType)));
171  EvalTo;
172  EvalTo evalToTmp(m_device.get(m_buffer), m_op);
173 
174  auto on_done = std::bind([](EvalSubExprsCallback done_) { done_(true); },
175  std::move(done));
176  internal::TensorAsyncExecutor<
177  const EvalTo, typename internal::remove_const<Device>::type,
178  decltype(on_done),
181  runAsync(evalToTmp, m_device, std::move(on_done));
182  }
183 #endif
184 
186  m_device.deallocate_temp(m_buffer);
187  m_buffer = NULL;
188  }
189 
191  {
192  return m_buffer[index];
193  }
194 
195  template<int LoadMode>
197  {
198  return internal::ploadt<PacketReturnType, LoadMode>(m_buffer + index);
199  }
200 
204  }
205 
208  bool /*root_of_expr_ast*/ = false) const {
209  assert(m_buffer != NULL);
210  return TensorBlock::materialize(m_buffer, m_impl.dimensions(), desc, scratch);
211  }
212 
214  return TensorOpCost(sizeof(CoeffReturnType), 0, 0, vectorized, PacketSize);
215  }
216 
218  EvaluatorPointerType data() const { return m_buffer; }
219 
220 #ifdef EIGEN_USE_SYCL
221  // binding placeholder accessors to a command group handler for SYCL
222  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const {
223  m_buffer.bind(cgh);
224  m_impl.bind(cgh);
225  }
226 #endif
227  private:
229  const ArgType m_op;
232 };
233 
234 
235 } // end namespace Eigen
236 
237 #endif // EIGEN_CXX11_TENSOR_TENSOR_FORCED_EVAL_H
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::PacketReturnType
PacketType< CoeffReturnType, Device >::type PacketReturnType
Definition: TensorForcedEval.h:112
Eigen::internal::TensorBlockScratchAllocator
Definition: TensorBlock.h:525
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::internal::TensorMaterializedBlock::materialize
static EIGEN_STRONG_INLINE TensorMaterializedBlock materialize(const Scalar *data, const DataDimensions &data_dims, TensorBlockDesc &desc, TensorBlockScratch &scratch)
Definition: TensorBlock.h:762
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::block
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock block(TensorBlockDesc &desc, TensorBlockScratch &scratch, bool=false) const
Definition: TensorForcedEval.h:207
Eigen::TensorForcedEvalOp::StorageKind
Eigen::internal::traits< TensorForcedEvalOp >::StorageKind StorageKind
Definition: TensorForcedEval.h:66
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::CoeffReturnType
XprType::CoeffReturnType CoeffReturnType
Definition: TensorForcedEval.h:111
Eigen::CwiseBinaryOp
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:77
Eigen::internal::IsVectorizable
Definition: TensorForwardDeclarations.h:147
Eigen::internal::nested
Definition: TensorTraits.h:174
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::TensorBlock
internal::TensorMaterializedBlock< CoeffReturnType, NumDims, Layout, Index > TensorBlock
Definition: TensorForcedEval.h:135
Eigen::TensorEvaluator::TensorBlock
internal::TensorMaterializedBlock< ScalarNoConst, NumCoords, Layout, Index > TensorBlock
Definition: TensorEvaluator.h:63
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::cleanup
EIGEN_STRONG_INLINE void cleanup()
Definition: TensorForcedEval.h:185
Eigen::TensorForcedEvalOp::m_xpr
XprType::Nested m_xpr
Definition: TensorForcedEval.h:77
Eigen::internal::IsTileable::value
static const TiledEvaluation value
Definition: TensorForwardDeclarations.h:172
Eigen::TensorEvaluator::Layout
@ Layout
Definition: TensorEvaluator.h:50
Eigen::internal::non_integral_type_placement_new
Definition: TensorForcedEval.h:82
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::m_buffer
EvaluatorPointerType m_buffer
Definition: TensorForcedEval.h:231
Eigen::internal::TensorMaterializedBlock
Definition: TensorBlock.h:656
Eigen::internal::IsVectorizable::value
static const bool value
Definition: TensorForwardDeclarations.h:148
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::Dimensions
TensorEvaluator< ArgType, Device >::Dimensions Dimensions
Definition: TensorForcedEval.h:109
Eigen::internal::eval< TensorForcedEvalOp< XprType >, Eigen::Dense >::type
const typedef TensorForcedEvalOp< XprType > & type
Definition: TensorForcedEval.h:45
Eigen::TensorForcedEvalOp::Nested
Eigen::internal::nested< TensorForcedEvalOp >::type Nested
Definition: TensorForcedEval.h:65
Eigen::TensorEvaluator::PacketSize
static const int PacketSize
Definition: TensorEvaluator.h:36
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::TensorBlockScratch
internal::TensorBlockScratchAllocator< Device > TensorBlockScratch
Definition: TensorForcedEval.h:131
Eigen::TensorForcedEvalOp
Definition: TensorForcedEval.h:59
make_changelog.desc
desc
Definition: make_changelog.py:71
Eigen::internal::non_integral_type_placement_new::operator()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void operator()(Index numValues, StorageType m_buffer)
Definition: TensorForcedEval.h:84
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::TensorPointerType
Eigen::internal::traits< XprType >::PointerType TensorPointerType
Definition: TensorForcedEval.h:114
Eigen::PacketType
Definition: TensorMeta.h:50
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::m_impl
TensorEvaluator< ArgType, Device > m_impl
Definition: TensorForcedEval.h:228
Eigen::internal::TensorBlockDescriptor< NumDims, Index >
Eigen::internal::true_type
Definition: Meta.h:96
Eigen::internal::traits< TensorForcedEvalOp< XprType > >::Nested
XprType::Nested Nested
Definition: TensorForcedEval.h:31
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::EvaluatorPointerType
Storage::Type EvaluatorPointerType
Definition: TensorForcedEval.h:116
Eigen::TensorForcedEvalOp::TensorForcedEvalOp
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorForcedEvalOp(const XprType &expr)
Definition: TensorForcedEval.h:69
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::XprType
TensorForcedEvalOp< ArgType > XprType
Definition: TensorForcedEval.h:107
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::getResourceRequirements
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE internal::TensorBlockResourceRequirements getResourceRequirements() const
Definition: TensorForcedEval.h:202
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::coeff
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
Definition: TensorForcedEval.h:190
Eigen::TensorForcedEvalOp::CoeffReturnType
internal::remove_const< typename XprType::CoeffReturnType >::type CoeffReturnType
Definition: TensorForcedEval.h:64
Eigen::internal::traits< TensorForcedEvalOp< XprType > >::StorageKind
traits< XprType >::StorageKind StorageKind
Definition: TensorForcedEval.h:29
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::TensorBlockDesc
internal::TensorBlockDescriptor< NumDims, Index > TensorBlockDesc
Definition: TensorForcedEval.h:130
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::packet
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
Definition: TensorForcedEval.h:196
EIGEN_STRONG_INLINE
#define EIGEN_STRONG_INLINE
Definition: Macros.h:917
Eigen::TensorEvaluator::PreferBlockAccess
@ PreferBlockAccess
Definition: TensorEvaluator.h:49
Eigen::TensorForcedEvalOp::expression
const EIGEN_DEVICE_FUNC internal::remove_all< typename XprType::Nested >::type & expression() const
Definition: TensorForcedEval.h:74
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::costPerCoeff
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
Definition: TensorForcedEval.h:213
gtsam.examples.DogLegOptimizerExample.run
def run(args)
Definition: DogLegOptimizerExample.py:21
Eigen::Triplet< double >
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::Scalar
ArgType::Scalar Scalar
Definition: TensorForcedEval.h:108
Eigen::internal::traits< TensorForcedEvalOp< XprType > >::XprTraits
traits< XprType > XprTraits
Definition: TensorForcedEval.h:28
Eigen::TensorEvaluator::m_device
const Device EIGEN_DEVICE_REF m_device
Definition: TensorEvaluator.h:192
Eigen::StorageMemory
Definition: TensorForwardDeclarations.h:37
Eigen::TensorBase
The tensor base class.
Definition: TensorBase.h:973
Eigen::TensorForcedEvalOp::RealScalar
Eigen::NumTraits< Scalar >::Real RealScalar
Definition: TensorForcedEval.h:63
Eigen::internal::traits< TensorForcedEvalOp< XprType > >::Scalar
XprType::Scalar Scalar
Definition: TensorForcedEval.h:27
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::m_device
const Device EIGEN_DEVICE_REF m_device
Definition: TensorForcedEval.h:230
Eigen::internal::array_prod
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_prod(const Sizes< Indices... > &)
Definition: TensorDimensions.h:140
Eigen::TensorEvaluator::BlockAccess
@ BlockAccess
Definition: TensorEvaluator.h:48
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::TensorEvaluator
TensorEvaluator(const XprType &op, const Device &device)
Definition: TensorForcedEval.h:138
Eigen::internal::remove_const::type
T type
Definition: Meta.h:121
Eigen::internal::nested< TensorForcedEvalOp< XprType >, 1, typename eval< TensorForcedEvalOp< XprType > >::type >::type
TensorForcedEvalOp< XprType > type
Definition: TensorForcedEval.h:51
Eigen::internal::TensorExecutor
Definition: TensorExecutor.h:81
Eigen::internal::traits< TensorForcedEvalOp< XprType > >::_Nested
remove_reference< Nested >::type _Nested
Definition: TensorForcedEval.h:32
Eigen::internal::traits< TensorForcedEvalOp< XprType > >::PointerType
XprTraits::PointerType PointerType
Definition: TensorForcedEval.h:35
Eigen::internal::non_integral_type_placement_new< Eigen::SyclDevice, CoeffReturnType >::operator()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void operator()(Index, StorageType)
Definition: TensorForcedEval.h:98
Eigen::internal::traits
Definition: ForwardDeclarations.h:17
Eigen::TensorForcedEvalOp::Index
Eigen::internal::traits< TensorForcedEvalOp >::Index Index
Definition: TensorForcedEval.h:67
Eigen::TensorEvaluator::EvaluatorPointerType
Storage::Type EvaluatorPointerType
Definition: TensorEvaluator.h:39
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::ArgType
const typedef internal::remove_all< ArgType_ >::type ArgType
Definition: TensorForcedEval.h:106
Eigen::TensorForcedEvalOp::Scalar
Eigen::internal::traits< TensorForcedEvalOp >::Scalar Scalar
Definition: TensorForcedEval.h:62
Eigen::internal::TensorBlockResourceRequirements
Definition: TensorBlock.h:75
EIGEN_DEVICE_REF
#define EIGEN_DEVICE_REF
Definition: TensorMacros.h:50
Eigen::TensorEvaluator
A cost model used to limit the number of threads used for evaluating tensor expression.
Definition: TensorEvaluator.h:28
internal
Definition: BandTriangularSolver.h:13
Eigen::TensorEvaluator::CoeffReturnType
Derived::Scalar CoeffReturnType
Definition: TensorEvaluator.h:32
NULL
#define NULL
Definition: ccolamd.c:609
Eigen::internal::traits< TensorForcedEvalOp< XprType > >::Index
traits< XprType >::Index Index
Definition: TensorForcedEval.h:30
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::Storage
StorageMemory< CoeffReturnType, Device > Storage
Definition: TensorForcedEval.h:115
Eigen::TensorEvaluator::IsAligned
@ IsAligned
Definition: TensorEvaluator.h:46
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::m_op
const ArgType m_op
Definition: TensorForcedEval.h:229
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::data
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EvaluatorPointerType data() const
Definition: TensorForcedEval.h:218
Eigen::internal::eval
Definition: XprHelper.h:332
Eigen::TensorEvaluator::PacketAccess
@ PacketAccess
Definition: TensorEvaluator.h:47
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::Index
XprType::Index Index
Definition: TensorForcedEval.h:110
Eigen::TensorOpCost
Definition: TensorCostModel.h:25
Eigen::internal::IsTileable
Definition: TensorForwardDeclarations.h:164
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::dimensions
const EIGEN_DEVICE_FUNC Dimensions & dimensions() const
Definition: TensorForcedEval.h:143
Eigen::TensorEvalToOp
Definition: TensorEvalTo.h:68
Eigen::internal::TensorBlockResourceRequirements::any
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlockResourceRequirements any()
Definition: TensorBlock.h:155
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::internal::is_arithmetic
Definition: Meta.h:133
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Eigen::Dense
Definition: Constants.h:507
Eigen::TensorEvaluator< const TensorForcedEvalOp< ArgType_ >, Device >::evalSubExprsIfNeeded
EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType)
Definition: TensorForcedEval.h:145


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:06:00