TR-mbed 1.0
Loading...
Searching...
No Matches
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
13namespace Eigen {
14
22namespace internal {
23template<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
42template<typename XprType>
47
48template<typename XprType>
53
54} // end namespace internal
55
56
57
58template<typename XprType>
79
80namespace internal {
81template <typename Device, typename CoeffReturnType>
83 template <typename StorageType>
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'
95template <typename CoeffReturnType>
96struct non_integral_type_placement_new<Eigen::SyclDevice, CoeffReturnType> {
97 template <typename StorageType>
100};
101} // end namespace internal
102
103template<typename ArgType_, typename Device>
104struct 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
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>
200
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:
228 TensorEvaluator<ArgType, Device> m_impl;
229 const ArgType m_op;
230 const Device EIGEN_DEVICE_REF m_device;
231 EvaluatorPointerType m_buffer;
232};
233
234
235} // end namespace Eigen
236
237#endif // EIGEN_CXX11_TENSOR_TENSOR_FORCED_EVAL_H
int i
Definition BiCGSTAB_step_by_step.cpp:9
#define EIGEN_DEVICE_FUNC
Definition Macros.h:976
#define EIGEN_STRONG_INLINE
Definition Macros.h:917
#define EIGEN_DEVICE_REF
Definition TensorMacros.h:50
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
Definition TensorForcedEval.h:60
Eigen::internal::traits< TensorForcedEvalOp >::Scalar Scalar
Definition TensorForcedEval.h:62
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorForcedEvalOp(const XprType &expr)
Definition TensorForcedEval.h:69
Eigen::internal::traits< TensorForcedEvalOp >::Index Index
Definition TensorForcedEval.h:67
XprType::Nested m_xpr
Definition TensorForcedEval.h:77
Eigen::internal::traits< TensorForcedEvalOp >::StorageKind StorageKind
Definition TensorForcedEval.h:66
Eigen::internal::nested< TensorForcedEvalOp >::type Nested
Definition TensorForcedEval.h:65
Eigen::NumTraits< Scalar >::Real RealScalar
Definition TensorForcedEval.h:63
internal::remove_const< typenameXprType::CoeffReturnType >::type CoeffReturnType
Definition TensorForcedEval.h:64
EIGEN_DEVICE_FUNC const internal::remove_all< typenameXprType::Nested >::type & expression() const
Definition TensorForcedEval.h:74
Definition TensorCostModel.h:25
Definition TensorExecutor.h:81
Definition TensorBlock.h:656
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_prod(const Sizes< Indices... > &)
Definition TensorDimensions.h:140
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
Definition BandTriangularSolver.h:13
Definition BFloat16.h:88
Definition Constants.h:507
Definition TensorMeta.h:50
Definition TensorForwardDeclarations.h:37
internal::TensorBlockScratchAllocator< Device > TensorBlockScratch
Definition TensorForcedEval.h:131
EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType)
Definition TensorForcedEval.h:145
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
Definition TensorForcedEval.h:196
TensorEvaluator< ArgType, Device >::Dimensions Dimensions
Definition TensorForcedEval.h:109
XprType::Index Index
Definition TensorForcedEval.h:110
TensorEvaluator(const XprType &op, const Device &device)
Definition TensorForcedEval.h:138
ArgType::Scalar Scalar
Definition TensorForcedEval.h:108
EIGEN_STRONG_INLINE void cleanup()
Definition TensorForcedEval.h:185
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock block(TensorBlockDesc &desc, TensorBlockScratch &scratch, bool=false) const
Definition TensorForcedEval.h:207
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
Definition TensorForcedEval.h:190
Eigen::internal::traits< XprType >::PointerType TensorPointerType
Definition TensorForcedEval.h:114
Storage::Type EvaluatorPointerType
Definition TensorForcedEval.h:116
TensorForcedEvalOp< ArgType > XprType
Definition TensorForcedEval.h:107
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
Definition TensorForcedEval.h:213
EIGEN_DEVICE_FUNC const Dimensions & dimensions() const
Definition TensorForcedEval.h:143
PacketType< CoeffReturnType, Device >::type PacketReturnType
Definition TensorForcedEval.h:112
internal::TensorMaterializedBlock< CoeffReturnType, NumDims, Layout, Index > TensorBlock
Definition TensorForcedEval.h:135
const internal::remove_all< ArgType_ >::type ArgType
Definition TensorForcedEval.h:106
internal::TensorBlockDescriptor< NumDims, Index > TensorBlockDesc
Definition TensorForcedEval.h:130
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EvaluatorPointerType data() const
Definition TensorForcedEval.h:218
StorageMemory< CoeffReturnType, Device > Storage
Definition TensorForcedEval.h:115
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE internal::TensorBlockResourceRequirements getResourceRequirements() const
Definition TensorForcedEval.h:202
XprType::CoeffReturnType CoeffReturnType
Definition TensorForcedEval.h:111
A cost model used to limit the number of threads used for evaluating tensor expression.
Definition TensorEvaluator.h:29
const Device EIGEN_DEVICE_REF m_device
Definition TensorEvaluator.h:192
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
internal::TensorMaterializedBlock< ScalarNoConst, NumCoords, Layout, Index > TensorBlock
Definition TensorEvaluator.h:63
Derived::Dimensions Dimensions
Definition TensorEvaluator.h:34
static const int PacketSize
Definition TensorEvaluator.h:36
Definition TensorForwardDeclarations.h:164
static const TiledEvaluation value
Definition TensorForwardDeclarations.h:172
Definition TensorForwardDeclarations.h:147
static const bool value
Definition TensorForwardDeclarations.h:148
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlockResourceRequirements any()
Definition TensorBlock.h:155
const TensorForcedEvalOp< XprType > & type
Definition TensorForcedEval.h:45
Definition XprHelper.h:332
Definition Meta.h:133
Definition TensorTraits.h:175
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void operator()(Index, StorageType)
Definition TensorForcedEval.h:98
Definition TensorForcedEval.h:82
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void operator()(Index numValues, StorageType m_buffer)
Definition TensorForcedEval.h:84
T type
Definition Meta.h:121
XprType::Nested Nested
Definition TensorForcedEval.h:31
traits< XprType > XprTraits
Definition TensorForcedEval.h:28
remove_reference< Nested >::type _Nested
Definition TensorForcedEval.h:32
traits< XprType >::Index Index
Definition TensorForcedEval.h:30
XprType::Scalar Scalar
Definition TensorForcedEval.h:27
XprTraits::PointerType PointerType
Definition TensorForcedEval.h:35
traits< XprType >::StorageKind StorageKind
Definition TensorForcedEval.h:29
Definition ForwardDeclarations.h:17