TR-mbed 1.0
Loading...
Searching...
No Matches
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
13namespace Eigen {
14
22namespace internal {
23template<typename XprType, template <class> class 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.
44 typedef typename MakePointerT::Type Type;
45
46
47 };
48};
49
50template<typename XprType, template <class> class MakePointer_>
55
56template<typename XprType, template <class> class MakePointer_>
61
62} // end namespace internal
63
64
65
66
67template<typename XprType, template <class> class MakePointer_>
94
95
96
97template<typename ArgType, typename Device, template <class> class MakePointer_>
98struct TensorEvaluator<const TensorEvalToOp<ArgType, MakePointer_>, Device>
99{
101 typedef typename ArgType::Scalar Scalar;
103 typedef typename XprType::Index Index;
110 enum {
116 CoordAccess = false, // to be implemented
117 RawAccess = true
118 };
119
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
140
141
142 EIGEN_DEVICE_FUNC const Dimensions& dimensions() const { return m_impl.dimensions(); }
143
145 EIGEN_UNUSED_VARIABLE(scalar);
146 eigen_assert(scalar == NULL);
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) {
154 EIGEN_UNUSED_VARIABLE(scalar);
155 eigen_assert(scalar == NULL);
156 m_impl.evalSubExprsIfNeededAsync(m_buffer, std::move(done));
157 }
158#endif
159
161 m_buffer[i] = m_impl.coeff(i);
162 }
166
169 return m_impl.getResourceRequirements();
170 }
171
173 TensorBlockDesc& desc, TensorBlockScratch& scratch) {
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>
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:
228 TensorEvaluator<ArgType, Device> m_impl;
229 EvaluatorPointerType m_buffer;
230 const ArgType m_expression;
231};
232
233
234} // end namespace Eigen
235
236#endif // EIGEN_CXX11_TENSOR_TENSOR_EVAL_TO_H
int i
Definition BiCGSTAB_step_by_step.cpp:9
#define EIGEN_UNUSED_VARIABLE(var)
Definition Macros.h:1076
#define EIGEN_DEVICE_FUNC
Definition Macros.h:976
#define eigen_assert(x)
Definition Macros.h:1037
#define EIGEN_STRONG_INLINE
Definition Macros.h:917
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition CwiseBinaryOp.h:84
The tensor base class.
Definition TensorBase.h:973
Definition TensorEvalTo.h:69
XprType::Nested m_xpr
Definition TensorEvalTo.h:91
EIGEN_DEVICE_FUNC const internal::remove_all< typenameXprType::Nested >::type & expression() const
Definition TensorEvalTo.h:86
internal::remove_const< typenameXprType::CoeffReturnType >::type CoeffReturnType
Definition TensorEvalTo.h:73
Eigen::internal::traits< TensorEvalToOp >::StorageKind StorageKind
Definition TensorEvalTo.h:76
MakePointer_< CoeffReturnType >::Type PointerType
Definition TensorEvalTo.h:74
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvalToOp(PointerType buffer, const XprType &expr)
Definition TensorEvalTo.h:81
Eigen::NumTraits< Scalar >::Real RealScalar
Definition TensorEvalTo.h:72
Eigen::internal::traits< TensorEvalToOp >::Index Index
Definition TensorEvalTo.h:77
static const int NumDims
Definition TensorEvalTo.h:79
PointerType m_buffer
Definition TensorEvalTo.h:92
EIGEN_DEVICE_FUNC PointerType buffer() const
Definition TensorEvalTo.h:88
Eigen::internal::nested< TensorEvalToOp >::type Nested
Definition TensorEvalTo.h:75
Eigen::internal::traits< TensorEvalToOp >::Scalar Scalar
Definition TensorEvalTo.h:71
Definition TensorCostModel.h:25
Definition TensorBlock.h:1381
IndexType offset() const
Definition TensorBlock.h:298
const Dimensions & dimensions() const
Definition TensorBlock.h:299
@ Unaligned
Definition Constants.h:233
@ Aligned
Definition Constants.h:240
@ kMaterializedInOutput
Definition TensorBlock.h:610
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85
Definition BandTriangularSolver.h:13
Container::iterator get(Container &c, Position position)
Definition stdlist_overload.cpp:29
Definition Constants.h:507
Definition TensorForwardDeclarations.h:21
Definition TensorMeta.h:50
Definition TensorForwardDeclarations.h:37
PacketType< CoeffReturnType, Device >::type PacketReturnType
Definition TensorEvalTo.h:105
TensorEvaluator< ArgType, Device >::Dimensions Dimensions
Definition TensorEvalTo.h:102
EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType scalar)
Definition TensorEvalTo.h:144
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalPacket(Index i)
Definition TensorEvalTo.h:163
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE internal::TensorBlockResourceRequirements getResourceRequirements() const
Definition TensorEvalTo.h:168
TensorEvaluator< constArgType, Device >::TensorBlock ArgTensorBlock
Definition TensorEvalTo.h:127
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalScalar(Index i)
Definition TensorEvalTo.h:160
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalBlock(TensorBlockDesc &desc, TensorBlockScratch &scratch)
Definition TensorEvalTo.h:172
EIGEN_DEVICE_FUNC EvaluatorPointerType data() const
Definition TensorEvalTo.h:216
EIGEN_STRONG_INLINE ~TensorEvaluator()
Definition TensorEvalTo.h:138
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
Definition TensorEvalTo.h:198
StorageMemory< CoeffReturnType, Device > Storage
Definition TensorEvalTo.h:108
EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
Definition TensorEvalTo.h:134
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
Definition TensorEvalTo.h:204
EIGEN_DEVICE_FUNC const Dimensions & dimensions() const
Definition TensorEvalTo.h:142
internal::TensorBlockScratchAllocator< Device > TensorBlockScratch
Definition TensorEvalTo.h:124
EIGEN_STRONG_INLINE void cleanup()
Definition TensorEvalTo.h:194
internal::remove_const< typenameXprType::CoeffReturnType >::type CoeffReturnType
Definition TensorEvalTo.h:104
internal::TensorBlockDescriptor< NumDims, Index > TensorBlockDesc
Definition TensorEvalTo.h:123
Eigen::internal::traits< XprType >::PointerType TensorPointerType
Definition TensorEvalTo.h:107
internal::TensorBlockAssignment< CoeffReturnType, NumDims, typename ArgTensorBlock::XprType, Index > TensorBlockAssignment
Definition TensorEvalTo.h:131
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
Definition TensorEvalTo.h:209
TensorEvalToOp< ArgType, MakePointer_ > XprType
Definition TensorEvalTo.h:100
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
Derived::Scalar CoeffReturnType
Definition TensorEvaluator.h:32
@ 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
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
Definition TensorEvaluator.h:105
const TensorEvalToOp< XprType, MakePointer_ > & type
Definition TensorEvalTo.h:53
Definition XprHelper.h:332
Definition TensorTraits.h:175
traits< XprType > XprTraits
Definition TensorEvalTo.h:28
XprTraits::StorageKind StorageKind
Definition TensorEvalTo.h:29
XprType::Nested Nested
Definition TensorEvalTo.h:31
XprTraits::Index Index
Definition TensorEvalTo.h:30
remove_reference< Nested >::type _Nested
Definition TensorEvalTo.h:32
MakePointer_< Scalar >::Type PointerType
Definition TensorEvalTo.h:35
XprType::Scalar Scalar
Definition TensorEvalTo.h:27
Definition ForwardDeclarations.h:17