10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_CONVERSION_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_CONVERSION_H 23 template<
typename TargetType,
typename XprType>
30 typedef typename XprType::Nested
Nested;
38 template<
typename TargetType,
typename XprType>
44 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>
62 template<
int LoadMode,
typename Index>
64 return internal::pcast<SrcPacket, TgtPacket>(m_impl.template packet<LoadMode>(index));
72 template <
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);
84 TgtPacket
result = internal::pcast<SrcPacket, TgtPacket>(src1, src2);
92 template <
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);
106 TgtPacket
result = internal::pcast<SrcPacket, TgtPacket>(src1, src2, src3, src4);
114 template <
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);
132 TgtPacket
result = internal::pcast<SrcPacket, TgtPacket>(src1, src2, src3, src4, src5, src6, src7, src8);
140 template <
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)) {
154 return internal::pcast<SrcPacket, TgtPacket>(m_impl.template packet<Unaligned>(index));
162 for (
int i = 0;
i < TgtPacketSize; ++
i) {
163 values[
i] = converter(m_impl.coeff(index+
i));
165 TgtPacket rslt = internal::pload<TgtPacket>(
values);
175 template<
typename TargetType,
typename XprType>
199 impl.evalSubExprsIfNeeded(
NULL);
206 return impl.evalSubExprsIfNeeded(data);
210 #ifdef EIGEN_USE_THREADS 211 template <
bool SameType,
typename Eval,
typename EvalPointerType,
212 typename EvalSubExprsCallback>
213 struct ConversionSubExprEvalAsync {
215 impl.evalSubExprsIfNeededAsync(
nullptr, std::move(done));
219 template <
typename Eval,
typename EvalPointerType,
220 typename EvalSubExprsCallback>
221 struct ConversionSubExprEvalAsync<true, Eval, EvalPointerType,
222 EvalSubExprsCallback> {
224 impl.evalSubExprsIfNeededAsync(data, std::move(done));
231 template <
typename SrcType,
typename TargetType,
bool IsSameT>
233 template <
typename ArgType,
typename Device>
236 return converter(impl.
coeff(index));
240 template <
typename SrcType,
typename TargetType>
242 template <
typename ArgType,
typename Device>
244 return impl.
coeff(index);
248 template <
typename SrcPacket,
typename TargetPacket,
int LoadMode,
bool ActuallyVectorize,
bool IsSameT>
255 template <
typename ArgType,
typename Device>
260 for (
int i = 0;
i < PacketSize; ++
i) {
261 values[
i] = converter(impl.
coeff(index+
i));
263 TargetPacket rslt = internal::pload<TargetPacket>(
values);
268 template <
typename SrcPacket,
typename TargetPacket,
int LoadMode,
bool IsSameT>
269 struct PacketConv<SrcPacket, TargetPacket, LoadMode, true, IsSameT> {
273 template <
typename ArgType,
typename Device>
278 SrcCoeffRatio, TgtCoeffRatio> converter(impl);
279 return converter.template packet<LoadMode>(index);
283 template <
typename SrcPacket,
typename TargetPacket,
int LoadMode>
284 struct PacketConv<SrcPacket, TargetPacket, LoadMode, false, true> {
288 template <
typename ArgType,
typename Device>
291 for (
int i = 0;
i < PacketSize; ++
i) values[
i] = impl.
coeff(index+
i);
292 return internal::pload<TargetPacket>(
values);
296 template <
typename SrcPacket,
typename TargetPacket,
int LoadMode>
297 struct PacketConv<SrcPacket, TargetPacket, LoadMode, true, true> {
298 template <
typename ArgType,
typename Device>
300 return impl.template packet<LoadMode>(index);
307 template<
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>
379 EvaluatorPointerType
data, EvalSubExprsCallback done) {
380 ConversionSubExprEvalAsync<IsSameType, TensorEvaluator<ArgType, Device>,
381 EvaluatorPointerType,
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) +
421 TensorOpCost(0, 0, TgtCoeffRatio * (cast_cost / PacketSize));
423 return m_impl.costPerCoeff(vectorized) +
TensorOpCost(0, 0, cast_cost);
429 return m_impl.getResourceRequirements();
433 block(TensorBlockDesc& desc, TensorBlockScratch& scratch,
434 bool =
false)
const {
436 TensorConversionOpBlockFactory());
443 #ifdef EIGEN_USE_SYCL 456 #endif // EIGEN_CXX11_TENSOR_TENSOR_CONVERSION_H EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
StorageMemory< CoeffReturnType, Device > Storage
#define EIGEN_STRONG_INLINE
const TensorEvaluator< ArgType, Device > & impl() const
required by sycl in order to extract the sycl accessor
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TargetPacket run(const TensorEvaluator< ArgType, Device > &impl, Index index)
PacketType< SrcType, Device >::type PacketSourceType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket packet(Index index) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorConversionOp(const XprType &xpr)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket packet(Index index) const
const TensorEvaluator::Index m_maxIndex
internal::unpacket_traits< TargetPacket >::type TargetType
TargetType CoeffReturnType
TensorConversionOp< TargetType, const ArgXprType > type
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TargetPacket run(const TensorEvaluator< ArgType, Device > &impl, Index index)
const TensorConversionOp< TargetType, XprType > & type
Namespace containing all symbols from the Eigen library.
A cost model used to limit the number of threads used for evaluating tensor expression.
traits< XprType >::StorageKind StorageKind
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TargetType run(const TensorEvaluator< ArgType, Device > &impl, Index index)
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
const TensorEvaluator & m_impl
internal::nested< TensorConversionOp >::type Nested
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock block(TensorBlockDesc &desc, TensorBlockScratch &scratch, bool=false) const
traits< XprType >::Index Index
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TargetType run(const TensorEvaluator< ArgType, Device > &impl, Index index)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketConverter(const TensorEvaluator &impl)
TensorConversionOp< TargetType, XprType > type
internal::remove_all< typename internal::traits< ArgType >::Scalar >::type SrcType
PacketType< CoeffReturnType, Device >::type PacketReturnType
Generic expression where a coefficient-wise binary operator is applied to two expressions.
internal::TensorUnaryExprBlock< TensorConversionOpBlockFactory, ArgTensorBlock > TensorBlock
TensorEvaluator< const ArgType, Device >::TensorBlock ArgTensorBlock
TensorConversionOp< TargetType, ArgType > XprType
NumTraits< Scalar >::Real RealScalar
internal::traits< TensorConversionOp >::StorageKind StorageKind
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketConverter(const TensorEvaluator &impl)
TensorEvaluator< ArgType, Device >::Dimensions Dimensions
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
XprType< ArgXprType >::type expr(const ArgXprType &expr) const
const TensorEvaluator & m_impl
Tensor conversion class. This class makes it possible to vectorize type casting operations when the n...
internal::traits< TensorConversionOp >::Scalar Scalar
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketConverter(const TensorEvaluator &impl)
EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType data)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
const TensorEvaluator & m_impl
TensorEvaluator< ArgType, Device > m_impl
internal::traits< TensorConversionOp >::Index Index
TypeConversion< Scalar, typename traits< XprType >::PointerType >::type PointerType
EIGEN_DEVICE_FUNC EvaluatorPointerType data() const
remove_reference< Nested >::type _Nested
#define EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE bool run(Eval &impl, EvalPointerType data)
static EIGEN_STRONG_INLINE bool run(Eval &impl, EvalPointerType)
internal::TensorBlockDescriptor< NumDims, Index > TensorBlockDesc
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket packet(Index index) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE internal::TensorBlockResourceRequirements getResourceRequirements() const
const TensorEvaluator & m_impl
EIGEN_STRONG_INLINE void cleanup()
internal::unpacket_traits< TargetPacket >::type TargetType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
Storage::Type EvaluatorPointerType
Generic expression where a coefficient-wise unary operator is applied to an expression.
EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketConverter(const TensorEvaluator &impl)
EIGEN_DEVICE_FUNC const internal::remove_all< typename XprType::Nested >::type & expression() const
internal::unpacket_traits< TargetPacket >::type TargetType
const std::vector< size_t > dimensions
const TensorEvaluator & m_impl
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TargetPacket run(const TensorEvaluator< ArgType, Device > &impl, Index index)
internal::TensorBlockScratchAllocator< Device > TensorBlockScratch
internal::unpacket_traits< SrcPacket >::type SrcType
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TargetPacket run(const TensorEvaluator< ArgType, Device > &impl, Index index)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket packet(Index index) const
#define EIGEN_UNROLL_LOOP
internal::unpacket_traits< SrcPacket >::type SrcType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket packet(Index index) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketConverter(const TensorEvaluator &impl)