11#ifndef EIGEN_TENSOR_TENSOR_EVAL_TO_H
12#define EIGEN_TENSOR_TENSOR_EVAL_TO_H
15#include "./InternalHeaderCheck.h"
20template <
typename XprType,
template <
class>
class MakePointer_>
21struct traits<TensorEvalToOp<XprType, MakePointer_> > {
22 using Scalar =
typename XprType::Scalar;
23 using XprTraits = traits<XprType>;
24 using StorageKind =
typename XprTraits::StorageKind;
25 using Index =
typename XprTraits::Index;
26 static constexpr int NumDimensions = XprTraits::NumDimensions;
27 static constexpr int Layout = XprTraits::Layout;
28 using PointerType =
typename MakePointer_<Scalar>::Type;
33 using Type =
typename MakePointer_<T>::Type;
37template <
typename XprType,
template <
class>
class MakePointer_>
38struct eval<TensorEvalToOp<XprType, MakePointer_>, Eigen::Dense> {
39 using type =
const TensorEvalToOp<XprType, MakePointer_>&;
44template <
typename XprType,
template <
class>
class MakePointer_>
45class TensorEvalToOp :
public TensorBase<TensorEvalToOp<XprType, MakePointer_>, ReadOnlyAccessors> {
47 using Scalar =
typename Eigen::internal::traits<TensorEvalToOp>::Scalar;
48 using RealScalar =
typename Eigen::NumTraits<Scalar>::Real;
49 using CoeffReturnType = std::remove_const_t<typename XprType::CoeffReturnType>;
50 using PointerType =
typename MakePointer_<CoeffReturnType>::Type;
51 using Nested =
typename Eigen::internal::ref_selector<TensorEvalToOp>::type;
52 using StorageKind =
typename Eigen::internal::traits<TensorEvalToOp>::StorageKind;
53 using Index =
typename Eigen::internal::traits<TensorEvalToOp>::Index;
55 static constexpr int NumDims = Eigen::internal::traits<TensorEvalToOp>::NumDimensions;
57 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvalToOp(PointerType buffer,
const XprType& expr)
58 : m_xpr(expr), m_buffer(buffer) {}
60 EIGEN_DEVICE_FUNC
const internal::remove_all_t<typename XprType::Nested>& expression()
const {
return m_xpr; }
62 EIGEN_DEVICE_FUNC PointerType buffer()
const {
return m_buffer; }
65 typename XprType::Nested m_xpr;
69template <
typename ArgType,
typename Device,
template <
class>
class MakePointer_>
70struct TensorEvaluator<const TensorEvalToOp<ArgType, MakePointer_>, Device> {
71 using XprType = TensorEvalToOp<ArgType, MakePointer_>;
72 using Scalar =
typename ArgType::Scalar;
73 using Dimensions =
typename TensorEvaluator<ArgType, Device>::Dimensions;
74 using Index =
typename XprType::Index;
75 using CoeffReturnType = std::remove_const_t<typename XprType::CoeffReturnType>;
76 using PacketReturnType =
typename PacketType<CoeffReturnType, Device>::type;
77 static constexpr int PacketSize = PacketType<CoeffReturnType, Device>::size;
78 using TensorPointerType =
typename Eigen::internal::traits<XprType>::PointerType;
79 using Storage = StorageMemory<CoeffReturnType, Device>;
80 using EvaluatorPointerType =
typename Storage::Type;
82 IsAligned = TensorEvaluator<ArgType, Device>::IsAligned,
83 PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess,
85 PreferBlockAccess =
false,
90 static constexpr int Layout = TensorEvaluator<ArgType, Device>::Layout;
91 static constexpr int NumDims = internal::traits<ArgType>::NumDimensions;
94 using TensorBlockDesc = internal::TensorBlockDescriptor<NumDims, Index>;
95 using TensorBlockScratch = internal::TensorBlockScratchAllocator<Device>;
97 using ArgTensorBlock =
typename TensorEvaluator<const ArgType, Device>::TensorBlock;
99 using TensorBlockAssignment =
100 internal::TensorBlockAssignment<CoeffReturnType, NumDims, typename ArgTensorBlock::XprType, Index>;
103 EIGEN_STRONG_INLINE TensorEvaluator(
const XprType& op,
const Device& device)
104 : m_impl(op.expression(), device), m_buffer(device.get(op.buffer())), m_expression(op.expression()) {}
106 EIGEN_DEVICE_FUNC
const Dimensions& dimensions()
const {
return m_impl.dimensions(); }
108 EIGEN_STRONG_INLINE
bool evalSubExprsIfNeeded(EvaluatorPointerType scalar) {
109 EIGEN_UNUSED_VARIABLE(scalar);
110 eigen_assert(scalar ==
nullptr);
111 return m_impl.evalSubExprsIfNeeded(m_buffer);
114#ifdef EIGEN_USE_THREADS
115 template <
typename EvalSubExprsCallback>
116 EIGEN_STRONG_INLINE
void evalSubExprsIfNeededAsync(EvaluatorPointerType scalar, EvalSubExprsCallback done) {
117 EIGEN_UNUSED_VARIABLE(scalar);
118 eigen_assert(scalar ==
nullptr);
119 m_impl.evalSubExprsIfNeededAsync(m_buffer, std::move(done));
123 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void evalScalar(Index i)
const { m_buffer[i] = m_impl.coeff(i); }
124 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void evalPacket(Index i)
const {
125 internal::pstoret<CoeffReturnType, PacketReturnType, Aligned>(
126 m_buffer + i, m_impl.template packet < TensorEvaluator<ArgType, Device>::IsAligned ?
Aligned :
Unaligned > (i));
129 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE internal::TensorBlockResourceRequirements getResourceRequirements()
const {
130 return m_impl.getResourceRequirements();
133 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void evalBlock(TensorBlockDesc& desc, TensorBlockScratch& scratch) {
135 desc.template AddDestinationBuffer<Layout>(
136 m_buffer + desc.offset(),
137 internal::strides<Layout>(m_impl.dimensions()));
139 ArgTensorBlock block = m_impl.block(desc, scratch,
true);
143 if (block.kind() != internal::TensorBlockKind::kMaterializedInOutput) {
144 TensorBlockAssignment::Run(
145 TensorBlockAssignment::target(desc.dimensions(), internal::strides<Layout>(m_impl.dimensions()), m_buffer,
152 EIGEN_STRONG_INLINE
void cleanup() { m_impl.cleanup(); }
154 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index)
const {
return m_buffer[index]; }
156 template <
int LoadMode>
157 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index)
const {
158 return internal::ploadt<PacketReturnType, LoadMode>(m_buffer + index);
161 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(
bool vectorized)
const {
164 return m_impl.costPerCoeff(vectorized) + TensorOpCost(0,
sizeof(CoeffReturnType), 0, vectorized, PacketSize);
167 EIGEN_DEVICE_FUNC EvaluatorPointerType data()
const {
return m_buffer; }
168 ArgType expression()
const {
return m_expression; }
171 TensorEvaluator<ArgType, Device> m_impl;
172 EvaluatorPointerType m_buffer;
173 const ArgType m_expression;
The tensor base class.
Definition TensorForwardDeclarations.h:69
Namespace containing all symbols from the Eigen library.
The tensor evaluator class.
Definition TensorEvaluator.h:47