10#ifndef EIGEN_CXX11_TENSOR_TENSOR_FORCED_EVAL_H
11#define EIGEN_CXX11_TENSOR_TENSOR_FORCED_EVAL_H
13#include "./InternalHeaderCheck.h"
25template<
typename XprType>
26struct traits<TensorForcedEvalOp<XprType> >
29 typedef typename XprType::Scalar Scalar;
30 typedef traits<XprType> XprTraits;
31 typedef typename traits<XprType>::StorageKind StorageKind;
32 typedef typename traits<XprType>::Index
Index;
33 typedef typename XprType::Nested Nested;
34 typedef typename remove_reference<Nested>::type _Nested;
35 static const int NumDimensions = XprTraits::NumDimensions;
36 static const int Layout = XprTraits::Layout;
37 typedef typename XprTraits::PointerType PointerType;
44template<
typename XprType>
45struct eval<TensorForcedEvalOp<XprType>,
Eigen::Dense>
47 typedef const TensorForcedEvalOp<XprType>& type;
50template<
typename XprType>
51struct nested<TensorForcedEvalOp<XprType>, 1, typename eval<TensorForcedEvalOp<XprType> >::type>
53 typedef TensorForcedEvalOp<XprType> type;
60template<
typename XprType>
61class TensorForcedEvalOp :
public TensorBase<TensorForcedEvalOp<XprType>, ReadOnlyAccessors>
64 typedef typename Eigen::internal::traits<TensorForcedEvalOp>::Scalar Scalar;
66 typedef typename internal::remove_const<typename XprType::CoeffReturnType>::type CoeffReturnType;
67 typedef typename Eigen::internal::nested<TensorForcedEvalOp>::type Nested;
68 typedef typename Eigen::internal::traits<TensorForcedEvalOp>::StorageKind StorageKind;
69 typedef typename Eigen::internal::traits<TensorForcedEvalOp>::Index
Index;
71 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorForcedEvalOp(
const XprType& expr)
75 const typename internal::remove_all<typename XprType::Nested>::type&
76 expression()
const {
return m_xpr; }
79 typename XprType::Nested m_xpr;
83template <
typename Device,
typename CoeffReturnType>
84struct non_integral_type_placement_new{
85 template <
typename StorageType>
86EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void operator()(
Index numValues, StorageType m_buffer) {
88 if (!internal::is_arithmetic<CoeffReturnType>::value) {
89 for (
Index i = 0; i < numValues; ++i)
new (m_buffer + i) CoeffReturnType();
97template <
typename CoeffReturnType>
98struct non_integral_type_placement_new<
Eigen::SyclDevice, CoeffReturnType> {
99 template <
typename StorageType>
100EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void operator()(
Index, StorageType) {
105template<
typename ArgType_,
typename Device>
106struct TensorEvaluator<const TensorForcedEvalOp<ArgType_>, Device>
108 typedef const typename internal::remove_all<ArgType_>::type ArgType;
109 typedef TensorForcedEvalOp<ArgType> XprType;
110 typedef typename ArgType::Scalar Scalar;
111 typedef typename TensorEvaluator<ArgType, Device>::Dimensions Dimensions;
112 typedef typename XprType::Index Index;
113 typedef typename XprType::CoeffReturnType CoeffReturnType;
114 typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType;
115 static const int PacketSize = PacketType<CoeffReturnType, Device>::size;
116 typedef typename Eigen::internal::traits<XprType>::PointerType TensorPointerType;
117 typedef StorageMemory<CoeffReturnType, Device> Storage;
118 typedef typename Storage::Type EvaluatorPointerType;
122 PacketAccess = (PacketType<CoeffReturnType, Device>::size > 1),
123 BlockAccess = internal::is_arithmetic<CoeffReturnType>::value,
124 PreferBlockAccess =
false,
125 Layout = TensorEvaluator<ArgType, Device>::Layout,
129 static const int NumDims = internal::traits<ArgType>::NumDimensions;
132 typedef internal::TensorBlockDescriptor<NumDims, Index> TensorBlockDesc;
133 typedef internal::TensorBlockScratchAllocator<Device> TensorBlockScratch;
135 typedef typename internal::TensorMaterializedBlock<CoeffReturnType, NumDims,
140 TensorEvaluator(
const XprType& op,
const Device& device)
141 : m_impl(op.expression(), device), m_op(op.expression()),
142 m_device(device), m_buffer(NULL)
145 EIGEN_DEVICE_FUNC
const Dimensions& dimensions()
const {
return m_impl.dimensions(); }
147 EIGEN_STRONG_INLINE
bool evalSubExprsIfNeeded(EvaluatorPointerType) {
148 const Index numValues = internal::array_prod(m_impl.dimensions());
149 m_buffer = m_device.get((CoeffReturnType*)m_device.allocate_temp(numValues *
sizeof(CoeffReturnType)));
151 internal::non_integral_type_placement_new<Device, CoeffReturnType>()(numValues, m_buffer);
153 typedef TensorEvalToOp< const typename internal::remove_const<ArgType>::type > EvalTo;
154 EvalTo evalToTmp(m_device.get(m_buffer), m_op);
156 internal::TensorExecutor<
157 const EvalTo,
typename internal::remove_const<Device>::type,
158 internal::IsVectorizable<Device, const ArgType>::value,
159 internal::IsTileable<Device, const ArgType>::value>::
160 run(evalToTmp, m_device);
165#ifdef EIGEN_USE_THREADS
166 template <
typename EvalSubExprsCallback>
167 EIGEN_STRONG_INLINE
void evalSubExprsIfNeededAsync(
168 EvaluatorPointerType, EvalSubExprsCallback done) {
169 const Index numValues = internal::array_prod(m_impl.dimensions());
170 m_buffer = m_device.get((CoeffReturnType*)m_device.allocate_temp(
171 numValues *
sizeof(CoeffReturnType)));
172 typedef TensorEvalToOp<const typename internal::remove_const<ArgType>::type>
174 EvalTo evalToTmp(m_device.get(m_buffer), m_op);
176 auto on_done = std::bind([](EvalSubExprsCallback done_) { done_(
true); },
178 internal::TensorAsyncExecutor<
179 const EvalTo,
typename internal::remove_const<Device>::type,
181 internal::IsVectorizable<Device, const ArgType>::value,
182 internal::IsTileable<Device, const ArgType>::value>::
183 runAsync(evalToTmp, m_device, std::move(on_done));
187 EIGEN_STRONG_INLINE
void cleanup() {
188 m_device.deallocate_temp(m_buffer);
192 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index)
const
194 return m_buffer[index];
197 template<
int LoadMode>
198 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index)
const
200 return internal::ploadt<PacketReturnType, LoadMode>(m_buffer + index);
203 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
204 internal::TensorBlockResourceRequirements getResourceRequirements()
const {
205 return internal::TensorBlockResourceRequirements::any();
208 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock
209 block(TensorBlockDesc& desc, TensorBlockScratch& scratch,
210 bool =
false)
const {
211 assert(m_buffer != NULL);
212 return TensorBlock::materialize(m_buffer, m_impl.dimensions(), desc, scratch);
215 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(
bool vectorized)
const {
216 return TensorOpCost(
sizeof(CoeffReturnType), 0, 0, vectorized, PacketSize);
219 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
220 EvaluatorPointerType data()
const {
return m_buffer; }
224 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void bind(cl::sycl::handler &cgh)
const {
230 TensorEvaluator<ArgType, Device> m_impl;
232 const Device EIGEN_DEVICE_REF m_device;
233 EvaluatorPointerType m_buffer;
Namespace containing all symbols from the Eigen library.
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index