Warning, file /include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorForcedEval.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_FORCED_EVAL_H
0011 #define EIGEN_CXX11_TENSOR_TENSOR_FORCED_EVAL_H
0012
0013 namespace Eigen {
0014
0015
0016
0017
0018
0019
0020
0021
0022 namespace internal {
0023 template<typename XprType>
0024 struct traits<TensorForcedEvalOp<XprType> >
0025 {
0026
0027 typedef typename XprType::Scalar Scalar;
0028 typedef traits<XprType> XprTraits;
0029 typedef typename traits<XprType>::StorageKind StorageKind;
0030 typedef typename traits<XprType>::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 XprTraits::PointerType PointerType;
0036
0037 enum {
0038 Flags = 0
0039 };
0040 };
0041
0042 template<typename XprType>
0043 struct eval<TensorForcedEvalOp<XprType>, Eigen::Dense>
0044 {
0045 typedef const TensorForcedEvalOp<XprType>& type;
0046 };
0047
0048 template<typename XprType>
0049 struct nested<TensorForcedEvalOp<XprType>, 1, typename eval<TensorForcedEvalOp<XprType> >::type>
0050 {
0051 typedef TensorForcedEvalOp<XprType> type;
0052 };
0053
0054 }
0055
0056
0057
0058 template<typename XprType>
0059 class TensorForcedEvalOp : public TensorBase<TensorForcedEvalOp<XprType>, ReadOnlyAccessors>
0060 {
0061 public:
0062 typedef typename Eigen::internal::traits<TensorForcedEvalOp>::Scalar Scalar;
0063 typedef typename Eigen::NumTraits<Scalar>::Real RealScalar;
0064 typedef typename internal::remove_const<typename XprType::CoeffReturnType>::type CoeffReturnType;
0065 typedef typename Eigen::internal::nested<TensorForcedEvalOp>::type Nested;
0066 typedef typename Eigen::internal::traits<TensorForcedEvalOp>::StorageKind StorageKind;
0067 typedef typename Eigen::internal::traits<TensorForcedEvalOp>::Index Index;
0068
0069 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorForcedEvalOp(const XprType& expr)
0070 : m_xpr(expr) {}
0071
0072 EIGEN_DEVICE_FUNC
0073 const typename internal::remove_all<typename XprType::Nested>::type&
0074 expression() const { return m_xpr; }
0075
0076 protected:
0077 typename XprType::Nested m_xpr;
0078 };
0079
0080 namespace internal {
0081 template <typename Device, typename CoeffReturnType>
0082 struct non_integral_type_placement_new{
0083 template <typename StorageType>
0084 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void operator()(Index numValues, StorageType m_buffer) {
0085
0086 if (!internal::is_arithmetic<CoeffReturnType>::value) {
0087 for (Index i = 0; i < numValues; ++i) new (m_buffer + i) CoeffReturnType();
0088 }
0089 }
0090 };
0091
0092
0093
0094
0095 template <typename CoeffReturnType>
0096 struct non_integral_type_placement_new<Eigen::SyclDevice, CoeffReturnType> {
0097 template <typename StorageType>
0098 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void operator()(Index, StorageType) {
0099 }
0100 };
0101 }
0102
0103 template<typename ArgType_, typename Device>
0104 struct TensorEvaluator<const TensorForcedEvalOp<ArgType_>, Device>
0105 {
0106 typedef const typename internal::remove_all<ArgType_>::type ArgType;
0107 typedef TensorForcedEvalOp<ArgType> XprType;
0108 typedef typename ArgType::Scalar Scalar;
0109 typedef typename TensorEvaluator<ArgType, Device>::Dimensions Dimensions;
0110 typedef typename XprType::Index Index;
0111 typedef typename XprType::CoeffReturnType CoeffReturnType;
0112 typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType;
0113 static const int PacketSize = PacketType<CoeffReturnType, Device>::size;
0114 typedef typename Eigen::internal::traits<XprType>::PointerType TensorPointerType;
0115 typedef StorageMemory<CoeffReturnType, Device> Storage;
0116 typedef typename Storage::Type EvaluatorPointerType;
0117
0118 enum {
0119 IsAligned = true,
0120 PacketAccess = (PacketType<CoeffReturnType, Device>::size > 1),
0121 BlockAccess = internal::is_arithmetic<CoeffReturnType>::value,
0122 PreferBlockAccess = false,
0123 Layout = TensorEvaluator<ArgType, Device>::Layout,
0124 RawAccess = true
0125 };
0126
0127 static const int NumDims = internal::traits<ArgType>::NumDimensions;
0128
0129
0130 typedef internal::TensorBlockDescriptor<NumDims, Index> TensorBlockDesc;
0131 typedef internal::TensorBlockScratchAllocator<Device> TensorBlockScratch;
0132
0133 typedef typename internal::TensorMaterializedBlock<CoeffReturnType, NumDims,
0134 Layout, Index>
0135 TensorBlock;
0136
0137
0138 TensorEvaluator(const XprType& op, const Device& device)
0139 : m_impl(op.expression(), device), m_op(op.expression()),
0140 m_device(device), m_buffer(NULL)
0141 { }
0142
0143 EIGEN_DEVICE_FUNC const Dimensions& dimensions() const { return m_impl.dimensions(); }
0144
0145 EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType) {
0146 const Index numValues = internal::array_prod(m_impl.dimensions());
0147 m_buffer = m_device.get((CoeffReturnType*)m_device.allocate_temp(numValues * sizeof(CoeffReturnType)));
0148
0149 internal::non_integral_type_placement_new<Device, CoeffReturnType>()(numValues, m_buffer);
0150
0151 typedef TensorEvalToOp< const typename internal::remove_const<ArgType>::type > EvalTo;
0152 EvalTo evalToTmp(m_device.get(m_buffer), m_op);
0153
0154 internal::TensorExecutor<
0155 const EvalTo, typename internal::remove_const<Device>::type,
0156 internal::IsVectorizable<Device, const ArgType>::value,
0157 internal::IsTileable<Device, const ArgType>::value>::
0158 run(evalToTmp, m_device);
0159
0160 return true;
0161 }
0162
0163 #ifdef EIGEN_USE_THREADS
0164 template <typename EvalSubExprsCallback>
0165 EIGEN_STRONG_INLINE void evalSubExprsIfNeededAsync(
0166 EvaluatorPointerType, EvalSubExprsCallback done) {
0167 const Index numValues = internal::array_prod(m_impl.dimensions());
0168 m_buffer = m_device.get((CoeffReturnType*)m_device.allocate_temp(
0169 numValues * sizeof(CoeffReturnType)));
0170 typedef TensorEvalToOp<const typename internal::remove_const<ArgType>::type>
0171 EvalTo;
0172 EvalTo evalToTmp(m_device.get(m_buffer), m_op);
0173
0174 auto on_done = std::bind([](EvalSubExprsCallback done_) { done_(true); },
0175 std::move(done));
0176 internal::TensorAsyncExecutor<
0177 const EvalTo, typename internal::remove_const<Device>::type,
0178 decltype(on_done),
0179 internal::IsVectorizable<Device, const ArgType>::value,
0180 internal::IsTileable<Device, const ArgType>::value>::
0181 runAsync(evalToTmp, m_device, std::move(on_done));
0182 }
0183 #endif
0184
0185 EIGEN_STRONG_INLINE void cleanup() {
0186 m_device.deallocate_temp(m_buffer);
0187 m_buffer = NULL;
0188 }
0189
0190 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
0191 {
0192 return m_buffer[index];
0193 }
0194
0195 template<int LoadMode>
0196 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
0197 {
0198 return internal::ploadt<PacketReturnType, LoadMode>(m_buffer + index);
0199 }
0200
0201 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0202 internal::TensorBlockResourceRequirements getResourceRequirements() const {
0203 return internal::TensorBlockResourceRequirements::any();
0204 }
0205
0206 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock
0207 block(TensorBlockDesc& desc, TensorBlockScratch& scratch,
0208 bool = false) const {
0209 assert(m_buffer != NULL);
0210 return TensorBlock::materialize(m_buffer, m_impl.dimensions(), desc, scratch);
0211 }
0212
0213 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const {
0214 return TensorOpCost(sizeof(CoeffReturnType), 0, 0, vectorized, PacketSize);
0215 }
0216
0217 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
0218 EvaluatorPointerType data() const { return m_buffer; }
0219
0220 #ifdef EIGEN_USE_SYCL
0221
0222 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const {
0223 m_buffer.bind(cgh);
0224 m_impl.bind(cgh);
0225 }
0226 #endif
0227 private:
0228 TensorEvaluator<ArgType, Device> m_impl;
0229 const ArgType m_op;
0230 const Device EIGEN_DEVICE_REF m_device;
0231 EvaluatorPointerType m_buffer;
0232 };
0233
0234
0235 }
0236
0237 #endif