Warning, file /include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorEvalTo.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef EIGEN_CXX11_TENSOR_TENSOR_EVAL_TO_H
0011 #define EIGEN_CXX11_TENSOR_TENSOR_EVAL_TO_H
0012
0013 namespace Eigen {
0014
0015
0016
0017
0018
0019
0020
0021
0022 namespace internal {
0023 template<typename XprType, template <class> class MakePointer_>
0024 struct traits<TensorEvalToOp<XprType, MakePointer_> >
0025 {
0026
0027 typedef typename XprType::Scalar Scalar;
0028 typedef traits<XprType> XprTraits;
0029 typedef typename XprTraits::StorageKind StorageKind;
0030 typedef typename XprTraits::Index Index;
0031 typedef typename XprType::Nested Nested;
0032 typedef typename remove_reference<Nested>::type _Nested;
0033 static const int NumDimensions = XprTraits::NumDimensions;
0034 static const int Layout = XprTraits::Layout;
0035 typedef typename MakePointer_<Scalar>::Type PointerType;
0036
0037 enum {
0038 Flags = 0
0039 };
0040 template <class T>
0041 struct MakePointer {
0042
0043 typedef MakePointer_<T> MakePointerT;
0044 typedef typename MakePointerT::Type Type;
0045
0046
0047 };
0048 };
0049
0050 template<typename XprType, template <class> class MakePointer_>
0051 struct eval<TensorEvalToOp<XprType, MakePointer_>, Eigen::Dense>
0052 {
0053 typedef const TensorEvalToOp<XprType, MakePointer_>& type;
0054 };
0055
0056 template<typename XprType, template <class> class MakePointer_>
0057 struct nested<TensorEvalToOp<XprType, MakePointer_>, 1, typename eval<TensorEvalToOp<XprType, MakePointer_> >::type>
0058 {
0059 typedef TensorEvalToOp<XprType, MakePointer_> type;
0060 };
0061
0062 }
0063
0064
0065
0066
0067 template<typename XprType, template <class> class MakePointer_>
0068 class TensorEvalToOp : public TensorBase<TensorEvalToOp<XprType, MakePointer_>, ReadOnlyAccessors>
0069 {
0070 public:
0071 typedef typename Eigen::internal::traits<TensorEvalToOp>::Scalar Scalar;
0072 typedef typename Eigen::NumTraits<Scalar>::Real RealScalar;
0073 typedef typename internal::remove_const<typename XprType::CoeffReturnType>::type CoeffReturnType;
0074 typedef typename MakePointer_<CoeffReturnType>::Type PointerType;
0075 typedef typename Eigen::internal::nested<TensorEvalToOp>::type Nested;
0076 typedef typename Eigen::internal::traits<TensorEvalToOp>::StorageKind StorageKind;
0077 typedef typename Eigen::internal::traits<TensorEvalToOp>::Index Index;
0078
0079 static const int NumDims = Eigen::internal::traits<TensorEvalToOp>::NumDimensions;
0080
0081 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvalToOp(PointerType buffer, const XprType& expr)
0082 : m_xpr(expr), m_buffer(buffer) {}
0083
0084 EIGEN_DEVICE_FUNC
0085 const typename internal::remove_all<typename XprType::Nested>::type&
0086 expression() const { return m_xpr; }
0087
0088 EIGEN_DEVICE_FUNC PointerType buffer() const { return m_buffer; }
0089
0090 protected:
0091 typename XprType::Nested m_xpr;
0092 PointerType m_buffer;
0093 };
0094
0095
0096
0097 template<typename ArgType, typename Device, template <class> class MakePointer_>
0098 struct TensorEvaluator<const TensorEvalToOp<ArgType, MakePointer_>, Device>
0099 {
0100 typedef TensorEvalToOp<ArgType, MakePointer_> XprType;
0101 typedef typename ArgType::Scalar Scalar;
0102 typedef typename TensorEvaluator<ArgType, Device>::Dimensions Dimensions;
0103 typedef typename XprType::Index Index;
0104 typedef typename internal::remove_const<typename XprType::CoeffReturnType>::type CoeffReturnType;
0105 typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType;
0106 static const int PacketSize = PacketType<CoeffReturnType, Device>::size;
0107 typedef typename Eigen::internal::traits<XprType>::PointerType TensorPointerType;
0108 typedef StorageMemory<CoeffReturnType, Device> Storage;
0109 typedef typename Storage::Type EvaluatorPointerType;
0110 enum {
0111 IsAligned = TensorEvaluator<ArgType, Device>::IsAligned,
0112 PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess,
0113 BlockAccess = true,
0114 PreferBlockAccess = false,
0115 Layout = TensorEvaluator<ArgType, Device>::Layout,
0116 CoordAccess = false,
0117 RawAccess = true
0118 };
0119
0120 static const int NumDims = internal::traits<ArgType>::NumDimensions;
0121
0122
0123 typedef internal::TensorBlockDescriptor<NumDims, Index> TensorBlockDesc;
0124 typedef internal::TensorBlockScratchAllocator<Device> TensorBlockScratch;
0125
0126 typedef typename TensorEvaluator<const ArgType, Device>::TensorBlock
0127 ArgTensorBlock;
0128
0129 typedef internal::TensorBlockAssignment<
0130 CoeffReturnType, NumDims, typename ArgTensorBlock::XprType, Index>
0131 TensorBlockAssignment;
0132
0133
0134 EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device)
0135 : m_impl(op.expression(), device), m_buffer(device.get(op.buffer())), m_expression(op.expression()){}
0136
0137
0138 EIGEN_STRONG_INLINE ~TensorEvaluator() {
0139 }
0140
0141
0142 EIGEN_DEVICE_FUNC const Dimensions& dimensions() const { return m_impl.dimensions(); }
0143
0144 EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType scalar) {
0145 EIGEN_UNUSED_VARIABLE(scalar);
0146 eigen_assert(scalar == NULL);
0147 return m_impl.evalSubExprsIfNeeded(m_buffer);
0148 }
0149
0150 #ifdef EIGEN_USE_THREADS
0151 template <typename EvalSubExprsCallback>
0152 EIGEN_STRONG_INLINE void evalSubExprsIfNeededAsync(
0153 EvaluatorPointerType scalar, EvalSubExprsCallback done) {
0154 EIGEN_UNUSED_VARIABLE(scalar);
0155 eigen_assert(scalar == NULL);
0156 m_impl.evalSubExprsIfNeededAsync(m_buffer, std::move(done));
0157 }
0158 #endif
0159
0160 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalScalar(Index i) {
0161 m_buffer[i] = m_impl.coeff(i);
0162 }
0163 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalPacket(Index i) {
0164 internal::pstoret<CoeffReturnType, PacketReturnType, Aligned>(m_buffer + i, m_impl.template packet<TensorEvaluator<ArgType, Device>::IsAligned ? Aligned : Unaligned>(i));
0165 }
0166
0167 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0168 internal::TensorBlockResourceRequirements getResourceRequirements() const {
0169 return m_impl.getResourceRequirements();
0170 }
0171
0172 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalBlock(
0173 TensorBlockDesc& desc, TensorBlockScratch& scratch) {
0174
0175 desc.template AddDestinationBuffer<Layout>(
0176 m_buffer + desc.offset(),
0177 internal::strides<Layout>(m_impl.dimensions()));
0178
0179 ArgTensorBlock block =
0180 m_impl.block(desc, scratch, true);
0181
0182
0183
0184 if (block.kind() != internal::TensorBlockKind::kMaterializedInOutput) {
0185 TensorBlockAssignment::Run(
0186 TensorBlockAssignment::target(
0187 desc.dimensions(), internal::strides<Layout>(m_impl.dimensions()),
0188 m_buffer, desc.offset()),
0189 block.expr());
0190 }
0191 block.cleanup();
0192 }
0193
0194 EIGEN_STRONG_INLINE void cleanup() {
0195 m_impl.cleanup();
0196 }
0197
0198 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
0199 {
0200 return m_buffer[index];
0201 }
0202
0203 template<int LoadMode>
0204 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
0205 {
0206 return internal::ploadt<PacketReturnType, LoadMode>(m_buffer + index);
0207 }
0208
0209 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const {
0210
0211
0212 return m_impl.costPerCoeff(vectorized) +
0213 TensorOpCost(0, sizeof(CoeffReturnType), 0, vectorized, PacketSize);
0214 }
0215
0216 EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return m_buffer; }
0217 ArgType expression() const { return m_expression; }
0218 #ifdef EIGEN_USE_SYCL
0219
0220 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const {
0221 m_impl.bind(cgh);
0222 m_buffer.bind(cgh);
0223 }
0224 #endif
0225
0226
0227 private:
0228 TensorEvaluator<ArgType, Device> m_impl;
0229 EvaluatorPointerType m_buffer;
0230 const ArgType m_expression;
0231 };
0232
0233
0234 }
0235
0236 #endif