TR-mbed 1.0
Loading...
Searching...
No Matches
TensorAssign.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_ASSIGN_H
11#define EIGEN_CXX11_TENSOR_TENSOR_ASSIGN_H
12
13namespace Eigen {
14
23namespace internal {
24template<typename LhsXprType, typename RhsXprType>
26{
27 typedef typename LhsXprType::Scalar Scalar;
31 typedef typename LhsXprType::Nested LhsNested;
32 typedef typename RhsXprType::Nested RhsNested;
35 static const std::size_t NumDimensions = internal::traits<LhsXprType>::NumDimensions;
36 static const int Layout = internal::traits<LhsXprType>::Layout;
38
39 enum {
40 Flags = 0
41 };
42};
43
44template<typename LhsXprType, typename RhsXprType>
49
50template<typename LhsXprType, typename RhsXprType>
55
56} // end namespace internal
57
58
59
60template<typename LhsXprType, typename RhsXprType>
89
90
91template<typename LeftArgType, typename RightArgType, typename Device>
92struct TensorEvaluator<const TensorAssignOp<LeftArgType, RightArgType>, Device>
93{
95 typedef typename XprType::Index Index;
96 typedef typename XprType::Scalar Scalar;
102
104 static const int NumDims = XprType::NumDims;
105
106 enum {
117 };
118
119 //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===//
122
125 //===--------------------------------------------------------------------===//
126
127 TensorEvaluator(const XprType& op, const Device& device) :
128 m_leftImpl(op.lhsExpression(), device),
129 m_rightImpl(op.rhsExpression(), device)
130 {
134 YOU_MADE_A_PROGRAMMING_MISTAKE);
135 }
136
138 {
139 // The dimensions of the lhs and the rhs tensors should be equal to prevent
140 // overflows and ensure the result is fully initialized.
141 // TODO: use left impl instead if right impl dimensions are known at compile time.
142 return m_rightImpl.dimensions();
143 }
144
146 eigen_assert(dimensions_match(m_leftImpl.dimensions(), m_rightImpl.dimensions()));
147 m_leftImpl.evalSubExprsIfNeeded(NULL);
148 // If the lhs provides raw access to its storage area (i.e. if m_leftImpl.data() returns a non
149 // null value), attempt to evaluate the rhs expression in place. Returns true iff in place
150 // evaluation isn't supported and the caller still needs to manually assign the values generated
151 // by the rhs to the lhs.
152 return m_rightImpl.evalSubExprsIfNeeded(m_leftImpl.data());
153 }
154
155#ifdef EIGEN_USE_THREADS
156 template <typename EvalSubExprsCallback>
157 EIGEN_STRONG_INLINE void evalSubExprsIfNeededAsync(
158 EvaluatorPointerType, EvalSubExprsCallback done) {
159 m_leftImpl.evalSubExprsIfNeededAsync(nullptr, [this, done](bool) {
160 m_rightImpl.evalSubExprsIfNeededAsync(
161 m_leftImpl.data(), [done](bool need_assign) { done(need_assign); });
162 });
163 }
164#endif // EIGEN_USE_THREADS
165
167 m_leftImpl.cleanup();
168 m_rightImpl.cleanup();
169 }
170
172 m_leftImpl.coeffRef(i) = m_rightImpl.coeff(i);
173 }
175
178 m_leftImpl.template writePacket<LhsStoreMode>(i, m_rightImpl.template packet<RhsLoadMode>(i));
179 }
181 {
182 return m_leftImpl.coeff(index);
183 }
184 template<int LoadMode>
186 {
187 return m_leftImpl.template packet<LoadMode>(index);
188 }
189
191 costPerCoeff(bool vectorized) const {
192 // We assume that evalPacket or evalScalar is called to perform the
193 // assignment and account for the cost of the write here, but reduce left
194 // cost by one load because we are using m_leftImpl.coeffRef.
195 TensorOpCost left = m_leftImpl.costPerCoeff(vectorized);
196 return m_rightImpl.costPerCoeff(vectorized) +
198 numext::maxi(0.0, left.bytes_loaded() - sizeof(CoeffReturnType)),
199 left.bytes_stored(), left.compute_cycles()) +
200 TensorOpCost(0, sizeof(CoeffReturnType), 0, vectorized, PacketSize);
201 }
202
206 m_leftImpl.getResourceRequirements(),
207 m_rightImpl.getResourceRequirements());
208 }
209
211 TensorBlockDesc& desc, TensorBlockScratch& scratch) {
213 m_leftImpl.data() != NULL) {
214 // If destination has raw data access, we pass it as a potential
215 // destination for a block descriptor evaluation.
216 desc.template AddDestinationBuffer<Layout>(
217 /*dst_base=*/m_leftImpl.data() + desc.offset(),
218 /*dst_strides=*/internal::strides<Layout>(m_leftImpl.dimensions()));
219 }
220
221 RightTensorBlock block = m_rightImpl.block(desc, scratch, /*root_of_expr_ast=*/true);
222 // If block was evaluated into a destination, there is no need to do assignment.
224 m_leftImpl.writeBlock(desc, block);
225 }
226 block.cleanup();
227 }
228
229#ifdef EIGEN_USE_SYCL
230 // binding placeholder accessors to a command group handler for SYCL
231 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const {
232 m_leftImpl.bind(cgh);
233 m_rightImpl.bind(cgh);
234 }
235#endif
236
237 EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return m_leftImpl.data(); }
238
239 private:
242};
243
244}
245
246
247#endif // EIGEN_CXX11_TENSOR_TENSOR_ASSIGN_H
int i
Definition BiCGSTAB_step_by_step.cpp:9
#define EIGEN_DEVICE_FUNC
Definition Macros.h:976
#define eigen_assert(x)
Definition Macros.h:1037
#define EIGEN_STRONG_INLINE
Definition Macros.h:917
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition StaticAssert.h:127
Definition TensorAssign.h:62
EIGEN_DEVICE_FUNC const internal::remove_all< typenameRhsXprType::Nested >::type & rhsExpression() const
Definition TensorAssign.h:83
LhsXprType::CoeffReturnType CoeffReturnType
Definition TensorAssign.h:66
Eigen::internal::traits< TensorAssignOp >::StorageKind StorageKind
Definition TensorAssign.h:68
EIGEN_DEVICE_FUNC internal::remove_all< typenameLhsXprType::Nested >::type & lhsExpression() const
Definition TensorAssign.h:79
Eigen::internal::traits< TensorAssignOp >::Scalar Scalar
Definition TensorAssign.h:64
const internal::remove_all< typenameRhsXprType::Nested >::type & m_rhs_xpr
Definition TensorAssign.h:87
internal::remove_all< typenameLhsXprType::Nested >::type & m_lhs_xpr
Definition TensorAssign.h:86
Eigen::internal::nested< TensorAssignOp >::type Nested
Definition TensorAssign.h:67
static const int NumDims
Definition TensorAssign.h:71
Eigen::NumTraits< Scalar >::Real RealScalar
Definition TensorAssign.h:65
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorAssignOp(LhsXprType &lhs, const RhsXprType &rhs)
Definition TensorAssign.h:73
Eigen::internal::traits< TensorAssignOp >::Index Index
Definition TensorAssign.h:69
The tensor base class.
Definition TensorBase.h:973
Definition TensorCostModel.h:25
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double bytes_stored() const
Definition TensorCostModel.h:77
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double bytes_loaded() const
Definition TensorCostModel.h:74
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double compute_cycles() const
Definition TensorCostModel.h:80
IndexType offset() const
Definition TensorBlock.h:298
@ Unaligned
Definition Constants.h:233
@ Aligned
Definition Constants.h:240
return int(ret)+1
@ kMaterializedInOutput
Definition TensorBlock.h:610
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T maxi(const T &x, const T &y)
Definition MathFunctions.h:1091
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool dimensions_match(Dims1 dims1, Dims2 dims2)
Definition TensorDimensions.h:484
Definition BandTriangularSolver.h:13
Definition Constants.h:507
Definition TensorMeta.h:50
Definition TensorForwardDeclarations.h:37
PacketType< CoeffReturnType, Device >::type PacketReturnType
Definition TensorAssign.h:98
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
Definition TensorAssign.h:191
TensorAssignOp< LeftArgType, RightArgType > XprType
Definition TensorAssign.h:94
EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType)
Definition TensorAssign.h:145
EIGEN_DEVICE_FUNC const Dimensions & dimensions() const
Definition TensorAssign.h:137
TensorEvaluator(const XprType &op, const Device &device)
Definition TensorAssign.h:127
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalPacket(Index i)
Definition TensorAssign.h:174
TensorEvaluator< constRightArgType, Device >::TensorBlock RightTensorBlock
Definition TensorAssign.h:124
internal::TensorBlockDescriptor< NumDims, Index > TensorBlockDesc
Definition TensorAssign.h:120
EIGEN_DEVICE_FUNC PacketReturnType packet(Index index) const
Definition TensorAssign.h:185
EIGEN_STRONG_INLINE void cleanup()
Definition TensorAssign.h:166
XprType::CoeffReturnType CoeffReturnType
Definition TensorAssign.h:97
internal::TensorBlockScratchAllocator< Device > TensorBlockScratch
Definition TensorAssign.h:121
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE internal::TensorBlockResourceRequirements getResourceRequirements() const
Definition TensorAssign.h:204
StorageMemory< CoeffReturnType, Device > Storage
Definition TensorAssign.h:100
TensorEvaluator< RightArgType, Device >::Dimensions Dimensions
Definition TensorAssign.h:99
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalScalar(Index i)
Definition TensorAssign.h:171
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalBlock(TensorBlockDesc &desc, TensorBlockScratch &scratch)
Definition TensorAssign.h:210
EIGEN_DEVICE_FUNC EvaluatorPointerType data() const
Definition TensorAssign.h:237
EIGEN_DEVICE_FUNC CoeffReturnType coeff(Index index) const
Definition TensorAssign.h:180
A cost model used to limit the number of threads used for evaluating tensor expression.
Definition TensorEvaluator.h:29
Storage::Type EvaluatorPointerType
Definition TensorEvaluator.h:39
EIGEN_DEVICE_FUNC EvaluatorPointerType data() const
Definition TensorEvaluator.h:181
@ BlockAccess
Definition TensorEvaluator.h:48
@ PreferBlockAccess
Definition TensorEvaluator.h:49
@ PacketAccess
Definition TensorEvaluator.h:47
@ Layout
Definition TensorEvaluator.h:50
@ IsAligned
Definition TensorEvaluator.h:46
Derived::Dimensions Dimensions
Definition TensorEvaluator.h:34
static const int PacketSize
Definition TensorEvaluator.h:36
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock block(TensorBlockDesc &desc, TensorBlockScratch &scratch, bool=false) const
Definition TensorEvaluator.h:158
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlockResourceRequirements merge(const TensorBlockResourceRequirements &lhs, const TensorBlockResourceRequirements &rhs)
Definition TensorBlock.h:138
const TensorAssignOp< LhsXprType, RhsXprType > & type
Definition TensorAssign.h:47
Definition XprHelper.h:332
Definition TensorTraits.h:175
RhsXprType::Nested RhsNested
Definition TensorAssign.h:32
traits< LhsXprType >::StorageKind StorageKind
Definition TensorAssign.h:28
remove_reference< RhsNested >::type _RhsNested
Definition TensorAssign.h:34
traits< LhsXprType >::PointerType PointerType
Definition TensorAssign.h:37
remove_reference< LhsNested >::type _LhsNested
Definition TensorAssign.h:33
LhsXprType::Nested LhsNested
Definition TensorAssign.h:31
LhsXprType::Scalar Scalar
Definition TensorAssign.h:27
promote_index_type< typenametraits< LhsXprType >::Index, typenametraits< RhsXprType >::Index >::type Index
Definition TensorAssign.h:30
Definition ForwardDeclarations.h:17