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>
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>
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>
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());
443 #ifdef EIGEN_USE_SYCL
456 #endif // EIGEN_CXX11_TENSOR_TENSOR_CONVERSION_H