10#ifndef EIGEN_CXX11_TENSOR_TENSOR_CONVERSION_H
11#define EIGEN_CXX11_TENSOR_TENSOR_CONVERSION_H
23template<
typename TargetType,
typename XprType>
30 typedef typename XprType::Nested
Nested;
38template<
typename TargetType,
typename XprType>
44template<
typename TargetType,
typename XprType>
53template <
typename TensorEvaluator,
typename SrcPacket,
typename TgtPacket,
int SrcCoeffRatio,
int TgtCoeffRatio>
56template <
typename TensorEvaluator,
typename SrcPacket,
typename TgtPacket>
62 template<
int LoadMode,
typename Index>
72template <
typename TensorEvaluator,
typename SrcPacket,
typename TgtPacket>
78 template<
int LoadMode,
typename Index>
82 SrcPacket src1 = m_impl.template packet<LoadMode>(index);
83 SrcPacket src2 = m_impl.template packet<LoadMode>(index + SrcPacketSize);
92template <
typename TensorEvaluator,
typename SrcPacket,
typename TgtPacket>
98 template<
int LoadMode,
typename Index>
102 SrcPacket src1 = m_impl.template packet<LoadMode>(index);
103 SrcPacket src2 = m_impl.template packet<LoadMode>(index + SrcPacketSize);
104 SrcPacket src3 = m_impl.template packet<LoadMode>(index + 2 * SrcPacketSize);
105 SrcPacket src4 = m_impl.template packet<LoadMode>(index + 3 * SrcPacketSize);
114template <
typename TensorEvaluator,
typename SrcPacket,
typename TgtPacket>
120 template<
int LoadMode,
typename Index>
124 SrcPacket src1 = m_impl.template packet<LoadMode>(index);
125 SrcPacket src2 = m_impl.template packet<LoadMode>(index + 1 * SrcPacketSize);
126 SrcPacket src3 = m_impl.template packet<LoadMode>(index + 2 * SrcPacketSize);
127 SrcPacket src4 = m_impl.template packet<LoadMode>(index + 3 * SrcPacketSize);
128 SrcPacket src5 = m_impl.template packet<LoadMode>(index + 4 * SrcPacketSize);
129 SrcPacket src6 = m_impl.template packet<LoadMode>(index + 5 * SrcPacketSize);
130 SrcPacket src7 = m_impl.template packet<LoadMode>(index + 6 * SrcPacketSize);
131 SrcPacket src8 = m_impl.template packet<LoadMode>(index + 7 * SrcPacketSize);
140template <
typename TensorEvaluator,
typename SrcPacket,
typename TgtPacket,
int TgtCoeffRatio>
144 : m_impl(impl), m_maxIndex(impl.dimensions().TotalSize()) {}
146 template<
int LoadMode,
typename Index>
152 if (m_impl.data() && (index + SrcPacketSize < m_maxIndex)) {
162 for (
int i = 0;
i < TgtPacketSize; ++
i) {
163 values[
i] = converter(m_impl.coeff(index+
i));
175template<
typename TargetType,
typename XprType>
199 impl.evalSubExprsIfNeeded(NULL);
206 return impl.evalSubExprsIfNeeded(
data);
210#ifdef EIGEN_USE_THREADS
211template <
bool SameType,
typename Eval,
typename EvalPointerType,
212 typename EvalSubExprsCallback>
213struct ConversionSubExprEvalAsync {
214 static EIGEN_STRONG_INLINE void run(Eval& impl, EvalPointerType, EvalSubExprsCallback done) {
215 impl.evalSubExprsIfNeededAsync(
nullptr, std::move(done));
219template <
typename Eval,
typename EvalPointerType,
220 typename EvalSubExprsCallback>
221struct ConversionSubExprEvalAsync<true, Eval, EvalPointerType,
222 EvalSubExprsCallback> {
224 impl.evalSubExprsIfNeededAsync(
data, std::move(done));
231template <
typename SrcType,
typename TargetType,
bool IsSameT>
233 template <
typename ArgType,
typename Device>
240template <
typename SrcType,
typename TargetType>
242 template <
typename ArgType,
typename Device>
244 return impl.coeff(index);
248template <
typename SrcPacket,
typename TargetPacket,
int LoadMode,
bool ActuallyVectorize,
bool IsSameT>
255 template <
typename ArgType,
typename Device>
268template <
typename SrcPacket,
typename TargetPacket,
int LoadMode,
bool IsSameT>
273 template <
typename ArgType,
typename Device>
278 SrcCoeffRatio, TgtCoeffRatio>
converter(impl);
283template <
typename SrcPacket,
typename TargetPacket,
int LoadMode>
288 template <
typename ArgType,
typename Device>
296template <
typename SrcPacket,
typename TargetPacket,
int LoadMode>
298 template <
typename ArgType,
typename Device>
307template<
typename TargetType,
typename ArgType,
typename Device>
326 #ifndef EIGEN_USE_SYCL
347 struct TensorConversionOpBlockFactory {
348 template <
typename ArgXprType>
353 template <
typename ArgXprType>
365 : m_impl(op.expression(), device)
376#ifdef EIGEN_USE_THREADS
377 template <
typename EvalSubExprsCallback>
380 ConversionSubExprEvalAsync<IsSameType, TensorEvaluator<ArgType, Device>,
382 EvalSubExprsCallback>::run(m_impl,
data, std::move(done));
396 template<
int LoadMode>
402 const bool Vectorizable =
409 Vectorizable, IsSameType>::run(m_impl, index);
414 const double cast_cost = TensorOpCost::CastCost<SrcType, TargetType>();
416 const double SrcCoeffRatio =
418 const double TgtCoeffRatio =
420 return m_impl.costPerCoeff(vectorized) * (SrcCoeffRatio /
PacketSize) +
423 return m_impl.costPerCoeff(vectorized) +
TensorOpCost(0, 0, cast_cost);
429 return m_impl.getResourceRequirements();
434 bool =
false)
const {
436 TensorConversionOpBlockFactory());
int i
Definition BiCGSTAB_step_by_step.cpp:9
#define EIGEN_UNROLL_LOOP
Definition Macros.h:1461
#define EIGEN_DEVICE_FUNC
Definition Macros.h:976
#define EIGEN_STRONG_INLINE
Definition Macros.h:917
int data[]
Definition Map_placement_new.cpp:1
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
Tensor conversion class. This class makes it possible to vectorize type casting operations when the n...
Definition TensorConversion.h:177
internal::traits< TensorConversionOp >::StorageKind StorageKind
Definition TensorConversion.h:180
NumTraits< Scalar >::Real RealScalar
Definition TensorConversion.h:184
Scalar CoeffReturnType
Definition TensorConversion.h:183
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorConversionOp(const XprType &xpr)
Definition TensorConversion.h:186
EIGEN_DEVICE_FUNC const internal::remove_all< typenameXprType::Nested >::type & expression() const
Definition TensorConversion.h:191
XprType::Nested m_xpr
Definition TensorConversion.h:194
internal::traits< TensorConversionOp >::Index Index
Definition TensorConversion.h:181
internal::traits< TensorConversionOp >::Scalar Scalar
Definition TensorConversion.h:179
internal::nested< TensorConversionOp >::type Nested
Definition TensorConversion.h:182
Definition TensorCostModel.h:25
Definition TensorRef.h:81
Definition TensorBlock.h:912
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
static EIGEN_STRONG_INLINE bool run(Eval &impl, EvalPointerType data)
Definition TensorConversion.h:205
Definition TensorConversion.h:197
static EIGEN_STRONG_INLINE bool run(Eval &impl, EvalPointerType)
Definition TensorConversion.h:198
Definition Constants.h:507
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketConverter(const TensorEvaluator &impl)
Definition TensorConversion.h:59
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket packet(Index index) const
Definition TensorConversion.h:63
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketConverter(const TensorEvaluator &impl)
Definition TensorConversion.h:143
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket packet(Index index) const
Definition TensorConversion.h:147
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketConverter(const TensorEvaluator &impl)
Definition TensorConversion.h:75
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket packet(Index index) const
Definition TensorConversion.h:79
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket packet(Index index) const
Definition TensorConversion.h:99
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketConverter(const TensorEvaluator &impl)
Definition TensorConversion.h:95
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketConverter(const TensorEvaluator &impl)
Definition TensorConversion.h:117
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket packet(Index index) const
Definition TensorConversion.h:121
Definition TensorConversion.h:54
Definition TensorMeta.h:50
Definition TensorForwardDeclarations.h:37
TensorEvaluator< ArgType, Device >::Dimensions Dimensions
Definition TensorConversion.h:312
TensorEvaluator< constArgType, Device >::TensorBlock ArgTensorBlock
Definition TensorConversion.h:345
StorageMemory< CoeffReturnType, Device > Storage
Definition TensorConversion.h:320
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
Definition TensorConversion.h:413
PacketType< SrcType, Device >::type PacketSourceType
Definition TensorConversion.h:317
internal::remove_all< typenameinternal::traits< ArgType >::Scalar >::type SrcType
Definition TensorConversion.h:315
XprType::Index Index
Definition TensorConversion.h:311
EIGEN_STRONG_INLINE void cleanup()
Definition TensorConversion.h:386
TargetType CoeffReturnType
Definition TensorConversion.h:314
internal::TensorBlockDescriptor< NumDims, Index > TensorBlockDesc
Definition TensorConversion.h:341
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
Definition TensorConversion.h:391
internal::TensorBlockScratchAllocator< Device > TensorBlockScratch
Definition TensorConversion.h:342
EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType data)
Definition TensorConversion.h:371
EIGEN_DEVICE_FUNC EvaluatorPointerType data() const
Definition TensorConversion.h:439
TensorEvaluator< ArgType, Device > m_impl
Definition TensorConversion.h:451
TensorConversionOp< TargetType, ArgType > XprType
Definition TensorConversion.h:310
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
Definition TensorConversion.h:369
internal::TensorUnaryExprBlock< TensorConversionOpBlockFactory, ArgTensorBlock > TensorBlock
Definition TensorConversion.h:361
TargetType Scalar
Definition TensorConversion.h:313
const TensorEvaluator< ArgType, Device > & impl() const
required by sycl in order to extract the sycl accessor
Definition TensorConversion.h:442
EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
Definition TensorConversion.h:364
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE internal::TensorBlockResourceRequirements getResourceRequirements() const
Definition TensorConversion.h:428
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
Definition TensorConversion.h:398
Storage::Type EvaluatorPointerType
Definition TensorConversion.h:321
PacketType< CoeffReturnType, Device >::type PacketReturnType
Definition TensorConversion.h:316
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock block(TensorBlockDesc &desc, TensorBlockScratch &scratch, bool=false) const
Definition TensorConversion.h:433
TensorConversionOp< TargetType, const ArgXprType > type
Definition TensorConversion.h:350
XprType< ArgXprType >::type expr(const ArgXprType &expr) const
Definition TensorConversion.h:354
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
PacketType< CoeffReturnType, Device >::type PacketReturnType
Definition TensorEvaluator.h:33
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::Index Index
Definition TensorEvaluator.h:30
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
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TargetType run(const TensorEvaluator< ArgType, Device > &impl, Index index)
Definition TensorConversion.h:243
Definition TensorConversion.h:232
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TargetType run(const TensorEvaluator< ArgType, Device > &impl, Index index)
Definition TensorConversion.h:234
internal::unpacket_traits< TargetPacket >::type TargetType
Definition TensorConversion.h:285
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TargetPacket run(const TensorEvaluator< ArgType, Device > &impl, Index index)
Definition TensorConversion.h:289
internal::unpacket_traits< TargetPacket >::type TargetType
Definition TensorConversion.h:271
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TargetPacket run(const TensorEvaluator< ArgType, Device > &impl, Index index)
Definition TensorConversion.h:274
internal::unpacket_traits< SrcPacket >::type SrcType
Definition TensorConversion.h:270
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TargetPacket run(const TensorEvaluator< ArgType, Device > &impl, Index index)
Definition TensorConversion.h:299
Definition TensorConversion.h:249
static const int PacketSize
Definition TensorConversion.h:253
internal::unpacket_traits< TargetPacket >::type TargetType
Definition TensorConversion.h:251
internal::unpacket_traits< SrcPacket >::type SrcType
Definition TensorConversion.h:250
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TargetPacket run(const TensorEvaluator< ArgType, Device > &impl, Index index)
Definition TensorConversion.h:256
Definition TensorBlock.h:75
const TensorConversionOp< TargetType, XprType > & type
Definition TensorConversion.h:41
Definition XprHelper.h:332
TensorConversionOp< TargetType, XprType > type
Definition TensorConversion.h:47
Definition TensorTraits.h:175
TargetType Scalar
Definition TensorConversion.h:27
traits< XprType >::Index Index
Definition TensorConversion.h:29
XprType::Nested Nested
Definition TensorConversion.h:30
remove_reference< Nested >::type _Nested
Definition TensorConversion.h:31
TypeConversion< Scalar, typenametraits< XprType >::PointerType >::type PointerType
Definition TensorConversion.h:35
traits< XprType >::StorageKind StorageKind
Definition TensorConversion.h:28
Definition ForwardDeclarations.h:17
Definition GenericPacketMath.h:148
Definition GenericPacketMath.h:133