10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_CONVERSION_H
11 #define EIGEN_CXX11_TENSOR_TENSOR_CONVERSION_H
26 template <
typename TargetType,
typename XprType>
32 typedef typename XprType::Nested
Nested;
33 typedef std::remove_reference_t<Nested>
Nested_;
40 template <
typename TargetType,
typename XprType>
45 template <
typename TargetType,
typename XprType>
53 template <
typename TensorEvaluator,
typename SrcPacket,
typename TgtPacket,
int SrcCoeffRatio,
int TgtCoeffRatio>
56 template <
typename TensorEvaluator,
typename SrcPacket,
typename TgtPacket>
60 template <
int LoadMode,
typename Index>
62 return internal::pcast<SrcPacket, TgtPacket>(m_impl.template packet<LoadMode>(index));
69 template <
typename TensorEvaluator,
typename SrcPacket,
typename TgtPacket>
73 template <
int LoadMode,
typename Index>
77 SrcPacket src1 = m_impl.template packet<LoadMode>(index);
78 SrcPacket src2 = m_impl.template packet<LoadMode>(index + SrcPacketSize);
79 TgtPacket result = internal::pcast<SrcPacket, TgtPacket>(src1, src2);
87 template <
typename TensorEvaluator,
typename SrcPacket,
typename TgtPacket>
91 template <
int LoadMode,
typename Index>
95 SrcPacket src1 = m_impl.template packet<LoadMode>(index);
96 SrcPacket src2 = m_impl.template packet<LoadMode>(index + SrcPacketSize);
97 SrcPacket src3 = m_impl.template packet<LoadMode>(index + 2 * SrcPacketSize);
98 SrcPacket src4 = m_impl.template packet<LoadMode>(index + 3 * SrcPacketSize);
99 TgtPacket result = internal::pcast<SrcPacket, TgtPacket>(src1, src2, src3, src4);
107 template <
typename TensorEvaluator,
typename SrcPacket,
typename TgtPacket>
111 template <
int LoadMode,
typename Index>
115 SrcPacket src1 = m_impl.template packet<LoadMode>(index);
116 SrcPacket src2 = m_impl.template packet<LoadMode>(index + 1 * SrcPacketSize);
117 SrcPacket src3 = m_impl.template packet<LoadMode>(index + 2 * SrcPacketSize);
118 SrcPacket src4 = m_impl.template packet<LoadMode>(index + 3 * SrcPacketSize);
119 SrcPacket src5 = m_impl.template packet<LoadMode>(index + 4 * SrcPacketSize);
120 SrcPacket src6 = m_impl.template packet<LoadMode>(index + 5 * SrcPacketSize);
121 SrcPacket src7 = m_impl.template packet<LoadMode>(index + 6 * SrcPacketSize);
122 SrcPacket src8 = m_impl.template packet<LoadMode>(index + 7 * SrcPacketSize);
123 TgtPacket result = internal::pcast<SrcPacket, TgtPacket>(src1, src2, src3, src4, src5, src6, src7, src8);
131 template <
typename TensorEvaluator,
typename SrcPacket,
typename TgtPacket,
int TgtCoeffRatio>
134 : m_impl(impl), m_maxIndex(impl.dimensions().TotalSize()) {}
136 template <
int LoadMode,
typename Index>
142 if (m_impl.data() && (index + SrcPacketSize < m_maxIndex)) {
144 return internal::pcast<SrcPacket, TgtPacket>(m_impl.template packet<Unaligned>(index));
152 for (
int i = 0;
i < TgtPacketSize; ++
i) {
153 values[
i] = converter(m_impl.coeff(index +
i));
155 TgtPacket rslt = internal::pload<TgtPacket>(values);
165 template <
typename TargetType,
typename XprType>
183 template <
bool SameType,
typename Eval,
typename EvalPo
interType>
186 impl.evalSubExprsIfNeeded(NULL);
191 template <
typename Eval,
typename EvalPo
interType>
196 #ifdef EIGEN_USE_THREADS
197 template <
bool SameType,
typename Eval,
typename EvalPo
interType,
typename EvalSubExprsCallback>
198 struct ConversionSubExprEvalAsync {
200 impl.evalSubExprsIfNeededAsync(
nullptr, std::move(done));
204 template <
typename Eval,
typename EvalPo
interType,
typename EvalSubExprsCallback>
205 struct ConversionSubExprEvalAsync<true, Eval, EvalPointerType, EvalSubExprsCallback> {
207 impl.evalSubExprsIfNeededAsync(
data, std::move(done));
214 template <
typename SrcType,
typename TargetType,
bool IsSameT>
216 template <
typename ArgType,
typename Device>
220 return converter(impl.
coeff(index));
224 template <
typename SrcType,
typename TargetType>
226 template <
typename ArgType,
typename Device>
229 return impl.
coeff(index);
233 template <
typename SrcPacket,
typename TargetPacket,
int LoadMode,
bool ActuallyVectorize,
bool IsSameT>
240 template <
typename ArgType,
typename Device>
247 values[
i] = converter(impl.
coeff(index +
i));
249 TargetPacket rslt = internal::pload<TargetPacket>(values);
254 template <
typename SrcPacket,
typename TargetPacket,
int LoadMode,
bool IsSameT>
255 struct PacketConv<SrcPacket, TargetPacket, LoadMode, true, IsSameT> {
259 template <
typename ArgType,
typename Device>
266 return converter.template packet<LoadMode>(index);
270 template <
typename SrcPacket,
typename TargetPacket,
int LoadMode>
271 struct PacketConv<SrcPacket, TargetPacket, LoadMode, false, true> {
275 template <
typename ArgType,
typename Device>
280 return internal::pload<TargetPacket>(values);
284 template <
typename SrcPacket,
typename TargetPacket,
int LoadMode>
285 struct PacketConv<SrcPacket, TargetPacket, LoadMode, true, true> {
286 template <
typename ArgType,
typename Device>
289 return impl.template packet<LoadMode>(index);
296 template <
typename TargetType,
typename ArgType,
typename Device>
314 #ifndef EIGEN_USE_SYCL
334 struct TensorConversionOpBlockFactory {
335 template <
typename ArgXprType>
340 template <
typename ArgXprType>
357 #ifdef EIGEN_USE_THREADS
358 template <
typename EvalSubExprsCallback>
361 EvalSubExprsCallback>
::run(m_impl,
data, std::move(done));
371 template <
int LoadMode>
385 const double cast_cost = TensorOpCost::CastCost<SrcType, TargetType>();
389 return m_impl.costPerCoeff(vectorized) * (SrcCoeffRatio /
PacketSize) +
392 return m_impl.costPerCoeff(vectorized) +
TensorOpCost(0, 0, cast_cost);
397 return m_impl.getResourceRequirements();
401 bool =
false)
const {
402 return TensorBlock(m_impl.block(desc, scratch), TensorConversionOpBlockFactory());
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define EIGEN_UNROLL_LOOP
Definition: Macros.h:1298
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:892
#define EIGEN_STRONG_INLINE
Definition: Macros.h:834
int data[]
Definition: Map_placement_new.cpp:1
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:79
The tensor base class.
Definition: TensorBase.h:1026
Tensor conversion class. This class makes it possible to vectorize type casting operations when the n...
Definition: TensorConversion.h:166
EIGEN_DEVICE_FUNC const internal::remove_all_t< typename XprType::Nested > & expression() const
Definition: TensorConversion.h:177
internal::traits< TensorConversionOp >::StorageKind StorageKind
Definition: TensorConversion.h:169
NumTraits< Scalar >::Real RealScalar
Definition: TensorConversion.h:173
Scalar CoeffReturnType
Definition: TensorConversion.h:172
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorConversionOp(const XprType &xpr)
Definition: TensorConversion.h:175
XprType::Nested m_xpr
Definition: TensorConversion.h:180
internal::traits< TensorConversionOp >::Index Index
Definition: TensorConversion.h:170
internal::traits< TensorConversionOp >::Scalar Scalar
Definition: TensorConversion.h:168
internal::nested< TensorConversionOp >::type Nested
Definition: TensorConversion.h:171
Definition: TensorCostModel.h:28
Definition: TensorBlock.h:475
Definition: TensorBlock.h:604
Definition: TensorBlock.h:834
char char * op
Definition: level2_impl.h:374
typename remove_all< T >::type remove_all_t
Definition: Meta.h:142
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
auto run(Kernel kernel, Args &&... args) -> decltype(kernel(args...))
Definition: gpu_test_helper.h:414
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
Extend namespace for flags.
Definition: fsi_chan_precond_driver.cc:56
type
Definition: compute_granudrum_aor.py:141
Definition: Eigen_Colamd.h:49
static EIGEN_STRONG_INLINE bool run(Eval &impl, EvalPointerType data)
Definition: TensorConversion.h:193
Definition: TensorConversion.h:184
static EIGEN_STRONG_INLINE bool run(Eval &impl, EvalPointerType)
Definition: TensorConversion.h:185
Definition: Constants.h:519
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:217
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketConverter(const TensorEvaluator &impl)
Definition: TensorConversion.h:58
const TensorEvaluator & m_impl
Definition: TensorConversion.h:66
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket packet(Index index) const
Definition: TensorConversion.h:61
const TensorEvaluator & m_impl
Definition: TensorConversion.h:161
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketConverter(const TensorEvaluator &impl)
Definition: TensorConversion.h:133
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket packet(Index index) const
Definition: TensorConversion.h:137
const TensorEvaluator::Index m_maxIndex
Definition: TensorConversion.h:162
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketConverter(const TensorEvaluator &impl)
Definition: TensorConversion.h:71
const TensorEvaluator & m_impl
Definition: TensorConversion.h:84
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket packet(Index index) const
Definition: TensorConversion.h:74
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket packet(Index index) const
Definition: TensorConversion.h:92
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketConverter(const TensorEvaluator &impl)
Definition: TensorConversion.h:89
const TensorEvaluator & m_impl
Definition: TensorConversion.h:104
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketConverter(const TensorEvaluator &impl)
Definition: TensorConversion.h:109
const TensorEvaluator & m_impl
Definition: TensorConversion.h:128
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket packet(Index index) const
Definition: TensorConversion.h:112
Definition: TensorConversion.h:54
Definition: TensorMeta.h:47
Definition: TensorForwardDeclarations.h:42
StorageMemory< CoeffReturnType, Device > Storage
Definition: TensorConversion.h:308
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
Definition: TensorConversion.h:384
XprType::Index Index
Definition: TensorConversion.h:299
EIGEN_STRONG_INLINE void cleanup()
Definition: TensorConversion.h:365
TargetType CoeffReturnType
Definition: TensorConversion.h:302
PacketType< SrcType, Device >::type PacketSourceType
Definition: TensorConversion.h:305
internal::TensorBlockDescriptor< NumDims, Index > TensorBlockDesc
Definition: TensorConversion.h:329
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
Definition: TensorConversion.h:367
const TensorEvaluator< ArgType, Device > & impl() const
required by sycl in order to extract the sycl accessor
Definition: TensorConversion.h:408
PacketType< CoeffReturnType, Device >::type PacketReturnType
Definition: TensorConversion.h:304
internal::TensorBlockScratchAllocator< Device > TensorBlockScratch
Definition: TensorConversion.h:330
EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType data)
Definition: TensorConversion.h:353
EIGEN_DEVICE_FUNC EvaluatorPointerType data() const
Definition: TensorConversion.h:405
TensorEvaluator< ArgType, Device > m_impl
Definition: TensorConversion.h:411
TensorConversionOp< TargetType, ArgType > XprType
Definition: TensorConversion.h:298
internal::TensorUnaryExprBlock< TensorConversionOpBlockFactory, ArgTensorBlock > TensorBlock
Definition: TensorConversion.h:346
internal::remove_all_t< typename internal::traits< ArgType >::Scalar > SrcType
Definition: TensorConversion.h:303
TargetType Scalar
Definition: TensorConversion.h:301
TensorEvaluator< const ArgType, Device >::TensorBlock ArgTensorBlock
Definition: TensorConversion.h:332
EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
Definition: TensorConversion.h:349
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE internal::TensorBlockResourceRequirements getResourceRequirements() const
Definition: TensorConversion.h:396
TensorEvaluator< ArgType, Device >::Dimensions Dimensions
Definition: TensorConversion.h:300
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
Definition: TensorConversion.h:372
Storage::Type EvaluatorPointerType
Definition: TensorConversion.h:309
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
Definition: TensorConversion.h:351
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock block(TensorBlockDesc &desc, TensorBlockScratch &scratch, bool=false) const
Definition: TensorConversion.h:400
TensorConversionOp< TargetType, const ArgXprType > type
Definition: TensorConversion.h:337
XprType< ArgXprType >::type expr(const ArgXprType &expr) const
Definition: TensorConversion.h:341
A cost model used to limit the number of threads used for evaluating tensor expression.
Definition: TensorEvaluator.h:31
static constexpr int Layout
Definition: TensorEvaluator.h:46
Storage::Type EvaluatorPointerType
Definition: TensorEvaluator.h:41
@ PacketAccess
Definition: TensorEvaluator.h:50
@ IsAligned
Definition: TensorEvaluator.h:49
static constexpr int PacketSize
Definition: TensorEvaluator.h:38
EIGEN_DEVICE_FUNC EvaluatorPointerType data() const
Definition: TensorEvaluator.h:165
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
Definition: TensorEvaluator.h:89
Derived::Index Index
Definition: TensorEvaluator.h:32
internal::TensorMaterializedBlock< ScalarNoConst, NumCoords, Layout, Index > TensorBlock
Definition: TensorEvaluator.h:63
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TargetType run(const TensorEvaluator< ArgType, Device > &impl, Index index)
Definition: TensorConversion.h:227
Definition: TensorConversion.h:215
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TargetType run(const TensorEvaluator< ArgType, Device > &impl, Index index)
Definition: TensorConversion.h:217
internal::unpacket_traits< TargetPacket >::type TargetType
Definition: TensorConversion.h:272
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TargetPacket run(const TensorEvaluator< ArgType, Device > &impl, Index index)
Definition: TensorConversion.h:276
internal::unpacket_traits< TargetPacket >::type TargetType
Definition: TensorConversion.h:257
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TargetPacket run(const TensorEvaluator< ArgType, Device > &impl, Index index)
Definition: TensorConversion.h:260
internal::unpacket_traits< SrcPacket >::type SrcType
Definition: TensorConversion.h:256
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TargetPacket run(const TensorEvaluator< ArgType, Device > &impl, Index index)
Definition: TensorConversion.h:287
Definition: TensorConversion.h:234
internal::unpacket_traits< TargetPacket >::type TargetType
Definition: TensorConversion.h:236
internal::unpacket_traits< SrcPacket >::type SrcType
Definition: TensorConversion.h:235
static constexpr int PacketSize
Definition: TensorConversion.h:238
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TargetPacket run(const TensorEvaluator< ArgType, Device > &impl, Index index)
Definition: TensorConversion.h:241
Definition: TensorBlock.h:75
Definition: TensorForwardDeclarations.h:54
const TensorConversionOp< TargetType, XprType > & type
Definition: TensorConversion.h:42
Definition: XprHelper.h:427
TensorConversionOp< TargetType, XprType > type
Definition: TensorConversion.h:48
Definition: TensorTraits.h:152
ref_selector< T >::type type
Definition: TensorTraits.h:153
Template functor to cast a scalar to another type.
Definition: functors/UnaryFunctors.h:205
TargetType Scalar
Definition: TensorConversion.h:29
traits< XprType >::Index Index
Definition: TensorConversion.h:31
XprType::Nested Nested
Definition: TensorConversion.h:32
TypeConversion< Scalar, typename traits< XprType >::PointerType >::type PointerType
Definition: TensorConversion.h:37
std::remove_reference_t< Nested > Nested_
Definition: TensorConversion.h:33
traits< XprType >::StorageKind StorageKind
Definition: TensorConversion.h:30
Definition: ForwardDeclarations.h:21
Definition: GenericPacketMath.h:201
Definition: GenericPacketMath.h:134
Definition: ZVector/PacketMath.h:50