10#ifndef EIGEN_CXX11_TENSOR_TENSOR_FORCED_EVAL_H
11#define EIGEN_CXX11_TENSOR_TENSOR_FORCED_EVAL_H
16template<
typename XprType>
17struct traits<TensorForcedEvalOp<XprType> >
20 typedef typename XprType::Scalar Scalar;
21 typedef traits<XprType> XprTraits;
22 typedef typename traits<XprType>::StorageKind StorageKind;
23 typedef typename traits<XprType>::Index
Index;
24 typedef typename XprType::Nested Nested;
25 typedef typename remove_reference<Nested>::type _Nested;
26 static const int NumDimensions = XprTraits::NumDimensions;
27 static const int Layout = XprTraits::Layout;
28 typedef typename XprTraits::PointerType PointerType;
35template<
typename XprType>
36struct eval<TensorForcedEvalOp<XprType>, Eigen::Dense>
38 typedef const TensorForcedEvalOp<XprType>& type;
41template<
typename XprType>
42struct nested<TensorForcedEvalOp<XprType>, 1, typename eval<TensorForcedEvalOp<XprType> >::type>
44 typedef TensorForcedEvalOp<XprType> type;
54template <
typename XprType>
55class TensorForcedEvalOp :
public TensorBase<TensorForcedEvalOp<XprType>, ReadOnlyAccessors> {
57 typedef typename Eigen::internal::traits<TensorForcedEvalOp>::Scalar Scalar;
59 typedef typename internal::remove_const<typename XprType::CoeffReturnType>::type CoeffReturnType;
60 typedef typename Eigen::internal::nested<TensorForcedEvalOp>::type Nested;
61 typedef typename Eigen::internal::traits<TensorForcedEvalOp>::StorageKind StorageKind;
62 typedef typename Eigen::internal::traits<TensorForcedEvalOp>::Index Index;
64 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorForcedEvalOp(
const XprType& expr)
68 const typename internal::remove_all<typename XprType::Nested>::type&
69 expression()
const {
return m_xpr; }
72 typename XprType::Nested m_xpr;
76template <
typename Device,
typename CoeffReturnType>
77struct non_integral_type_placement_new{
78 template <
typename StorageType>
79EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void operator()(
Index numValues, StorageType m_buffer) {
81 if (!internal::is_arithmetic<CoeffReturnType>::value) {
90template <
typename CoeffReturnType>
91struct non_integral_type_placement_new<Eigen::SyclDevice, CoeffReturnType> {
92 template <
typename StorageType>
93EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void operator()(
Index, StorageType) {
98template<
typename ArgType_,
typename Device>
101 typedef const typename internal::remove_all<ArgType_>::type ArgType;
102 typedef TensorForcedEvalOp<ArgType> XprType;
103 typedef typename ArgType::Scalar Scalar;
104 typedef typename TensorEvaluator<ArgType, Device>::Dimensions Dimensions;
105 typedef typename XprType::Index Index;
106 typedef typename XprType::CoeffReturnType CoeffReturnType;
107 typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType;
108 static const int PacketSize = PacketType<CoeffReturnType, Device>::size;
109 typedef typename Eigen::internal::traits<XprType>::PointerType TensorPointerType;
110 typedef StorageMemory<CoeffReturnType, Device> Storage;
111 typedef typename Storage::Type EvaluatorPointerType;
115 PacketAccess = (PacketType<CoeffReturnType, Device>::size > 1),
116 BlockAccess = internal::is_arithmetic<CoeffReturnType>::value,
117 PreferBlockAccess =
false,
118 Layout = TensorEvaluator<ArgType, Device>::Layout,
122 static const int NumDims = internal::traits<ArgType>::NumDimensions;
125 typedef internal::TensorBlockDescriptor<NumDims, Index> TensorBlockDesc;
126 typedef internal::TensorBlockScratchAllocator<Device> TensorBlockScratch;
128 typedef typename internal::TensorMaterializedBlock<CoeffReturnType, NumDims,
133 TensorEvaluator(
const XprType& op,
const Device& device)
134 : m_impl(op.expression(), device), m_op(op.expression()),
135 m_device(device), m_buffer(NULL)
138 EIGEN_DEVICE_FUNC
const Dimensions& dimensions()
const {
return m_impl.dimensions(); }
140 EIGEN_STRONG_INLINE
bool evalSubExprsIfNeeded(EvaluatorPointerType) {
141 const Index numValues = internal::array_prod(m_impl.dimensions());
142 m_buffer = m_device.get((CoeffReturnType*)m_device.allocate_temp(numValues *
sizeof(CoeffReturnType)));
144 internal::non_integral_type_placement_new<Device, CoeffReturnType>()(numValues, m_buffer);
146 typedef TensorEvalToOp< const typename internal::remove_const<ArgType>::type > EvalTo;
147 EvalTo evalToTmp(m_device.get(m_buffer), m_op);
149 internal::TensorExecutor<
150 const EvalTo,
typename internal::remove_const<Device>::type,
151 internal::IsVectorizable<Device, const ArgType>::value,
152 internal::IsTileable<Device, const ArgType>::value>::
153 run(evalToTmp, m_device);
158#ifdef EIGEN_USE_THREADS
159 template <
typename EvalSubExprsCallback>
160 EIGEN_STRONG_INLINE
void evalSubExprsIfNeededAsync(
161 EvaluatorPointerType, EvalSubExprsCallback done) {
162 const Index numValues = internal::array_prod(m_impl.dimensions());
163 m_buffer = m_device.get((CoeffReturnType*)m_device.allocate_temp(
164 numValues *
sizeof(CoeffReturnType)));
165 typedef TensorEvalToOp<const typename internal::remove_const<ArgType>::type>
167 EvalTo evalToTmp(m_device.get(m_buffer), m_op);
169 auto on_done = std::bind([](EvalSubExprsCallback done_) { done_(
true); },
171 internal::TensorAsyncExecutor<
172 const EvalTo,
typename internal::remove_const<Device>::type,
174 internal::IsVectorizable<Device, const ArgType>::value,
175 internal::IsTileable<Device, const ArgType>::value>::
176 runAsync(evalToTmp, m_device, std::move(on_done));
180 EIGEN_STRONG_INLINE
void cleanup() {
181 m_device.deallocate_temp(m_buffer);
185 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index)
const
187 return m_buffer[index];
190 template<
int LoadMode>
191 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index)
const
193 return internal::ploadt<PacketReturnType, LoadMode>(m_buffer + index);
196 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
197 internal::TensorBlockResourceRequirements getResourceRequirements()
const {
198 return internal::TensorBlockResourceRequirements::any();
201 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock
202 block(TensorBlockDesc& desc, TensorBlockScratch& scratch,
203 bool =
false)
const {
204 assert(m_buffer != NULL);
205 return TensorBlock::materialize(m_buffer, m_impl.dimensions(), desc, scratch);
208 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(
bool vectorized)
const {
209 return TensorOpCost(
sizeof(CoeffReturnType), 0, 0, vectorized, PacketSize);
212 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
213 EvaluatorPointerType data()
const {
return m_buffer; }
217 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void bind(cl::sycl::handler &cgh)
const {
223 TensorEvaluator<ArgType, Device> m_impl;
225 const Device EIGEN_DEVICE_REF m_device;
226 EvaluatorPointerType m_buffer;
The tensor base class.
Definition TensorForwardDeclarations.h:56
Tensor reshaping class.
Definition TensorForcedEval.h:55
Namespace containing all symbols from the Eigen library.
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The tensor evaluator class.
Definition TensorEvaluator.h:27