10#ifndef EIGEN_CXX11_TENSOR_TENSOR_GENERATOR_H
11#define EIGEN_CXX11_TENSOR_TENSOR_GENERATOR_H
23template<
typename Generator,
typename XprType>
26 typedef typename XprType::Scalar
Scalar;
29 typedef typename XprTraits::Index
Index;
30 typedef typename XprType::Nested
Nested;
32 static const int NumDimensions = XprTraits::NumDimensions;
33 static const int Layout = XprTraits::Layout;
37template<
typename Generator,
typename XprType>
43template<
typename Generator,
typename XprType>
53template<
typename Generator,
typename XprType>
81template<
typename Generator,
typename ArgType,
typename Device>
115 :
m_device(device), m_generator(op.generator())
123 for (
int i = 1;
i < NumDims; ++
i) {
124 m_strides[
i] = m_strides[
i - 1] * m_dimensions[
i - 1];
128 m_strides[NumDims - 1] = 1;
130 for (
int i = NumDims - 2;
i >= 0; --
i) {
131 m_strides[
i] = m_strides[
i + 1] * m_dimensions[
i + 1];
148 extract_coordinates(index, coords);
149 return m_generator(coords);
152 template<
int LoadMode>
160 for (
int i = 0;
i < packetSize; ++
i) {
169 const size_t target_size =
m_device.firstLevelCacheSize();
171 return internal::TensorBlockResourceRequirements::skewed<Scalar>(
175 struct BlockIteratorState {
184 bool =
false)
const {
185 static const bool is_col_major =
190 extract_coordinates(desc.
offset(), coords);
199 for (
int i = 0;
i < NumDims; ++
i) {
200 const int dim = is_col_major ?
i : NumDims - 1 -
i;
202 it[
i].stride =
i == 0 ? 1 : (it[
i - 1].
size * it[
i - 1].stride);
203 it[
i].span = it[
i].stride * (it[
i].
size - 1);
209 const typename TensorBlock::Storage block_storage =
210 TensorBlock::prepareStorage(desc, scratch);
216 static const int inner_dim = is_col_major ? 0 : NumDims - 1;
218 const Index inner_dim_vectorized = inner_dim_size - packet_size;
220 while (it[NumDims - 1].
count < it[NumDims - 1].
size) {
223 for (;
i <= inner_dim_vectorized;
i += packet_size) {
224 for (
Index j = 0;
j < packet_size; ++
j) {
226 j_coords[inner_dim] +=
j;
227 *(block_buffer +
offset +
i +
j) = m_generator(j_coords);
229 coords[inner_dim] += packet_size;
232 for (;
i < inner_dim_size; ++
i) {
233 *(block_buffer +
offset +
i) = m_generator(coords);
236 coords[inner_dim] = initial_coords[inner_dim];
239 if (NumDims == 1)
break;
242 for (
i = 1;
i < NumDims; ++
i) {
245 coords[is_col_major ?
i : NumDims - 1 -
i]++;
248 if (
i != NumDims - 1) it[
i].count = 0;
249 coords[is_col_major ?
i : NumDims - 1 -
i] =
250 initial_coords[is_col_major ?
i : NumDims - 1 -
i];
255 return block_storage.AsTensorMaterializedBlock();
262 return TensorOpCost(0, 0, TensorOpCost::AddCost<Scalar>() +
263 TensorOpCost::MulCost<Scalar>());
277 for (
int i = NumDims - 1;
i > 0; --
i) {
278 const Index idx = index / m_fast_strides[
i];
279 index -= idx * m_strides[
i];
284 for (
int i = 0;
i < NumDims - 1; ++
i) {
285 const Index idx = index / m_fast_strides[
i];
286 index -= idx * m_strides[
i];
289 coords[NumDims-1] = index;
int i
Definition BiCGSTAB_step_by_step.cpp:9
#define EIGEN_UNROLL_LOOP
Definition Macros.h:1461
#define EIGEN_DEVICE_FUNC
Definition Macros.h:976
#define eigen_assert(x)
Definition Macros.h:1037
#define EIGEN_STRONG_INLINE
Definition Macros.h:917
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition StaticAssert.h:127
#define EIGEN_DEVICE_REF
Definition TensorMacros.h:50
Scalar Scalar int size
Definition benchVecAdd.cpp:17
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition CwiseBinaryOp.h:84
The tensor base class.
Definition TensorBase.h:973
Tensor generator class.
Definition TensorGenerator.h:55
Eigen::internal::traits< TensorGeneratorOp >::StorageKind StorageKind
Definition TensorGenerator.h:61
Eigen::internal::traits< TensorGeneratorOp >::Scalar Scalar
Definition TensorGenerator.h:57
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorGeneratorOp(const XprType &expr, const Generator &generator)
Definition TensorGenerator.h:64
EIGEN_DEVICE_FUNC const internal::remove_all< typenameXprType::Nested >::type & expression() const
Definition TensorGenerator.h:72
Eigen::internal::nested< TensorGeneratorOp >::type Nested
Definition TensorGenerator.h:60
Eigen::NumTraits< Scalar >::Real RealScalar
Definition TensorGenerator.h:58
XprType::CoeffReturnType CoeffReturnType
Definition TensorGenerator.h:59
Eigen::internal::traits< TensorGeneratorOp >::Index Index
Definition TensorGenerator.h:62
const Generator m_generator
Definition TensorGenerator.h:76
EIGEN_DEVICE_FUNC const Generator & generator() const
Definition TensorGenerator.h:68
XprType::Nested m_xpr
Definition TensorGenerator.h:75
Definition TensorCostModel.h:25
Definition EmulateArray.h:21
EIGEN_DEVICE_FUNC static EIGEN_ALWAYS_INLINE std::size_t size()
Definition EmulateArray.h:44
IndexType offset() const
Definition TensorBlock.h:298
IndexType dimension(int index) const
Definition TensorBlock.h:300
Definition TensorRef.h:81
Definition TensorBlock.h:656
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics set mxtics default set mytics default set mx2tics default set my2tics default set xtics border mirror norotate autofreq set ytics border mirror norotate autofreq set ztics border nomirror norotate autofreq set nox2tics set noy2tics set timestamp bottom norotate offset
Definition gnuplot_common_settings.hh:64
@ ColMajor
Definition Constants.h:319
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85
Definition BandTriangularSolver.h:13
uint8_t count
Definition ref_serial.h:256
Definition Constants.h:507
Definition TensorMeta.h:50
Definition TensorForwardDeclarations.h:37
EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
Definition TensorGenerator.h:114
XprType::CoeffReturnType CoeffReturnType
Definition TensorGenerator.h:89
EIGEN_DEVICE_FUNC EvaluatorPointerType data() const
Definition TensorGenerator.h:266
EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType)
Definition TensorGenerator.h:139
TensorEvaluator< ArgType, Device >::Dimensions Dimensions
Definition TensorGenerator.h:86
Dimensions m_dimensions
Definition TensorGenerator.h:294
const Device EIGEN_DEVICE_REF m_device
Definition TensorGenerator.h:293
internal::TensorBlockScratchAllocator< Device > TensorBlockScratch
Definition TensorGenerator.h:107
Storage::Type EvaluatorPointerType
Definition TensorGenerator.h:92
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void extract_coordinates(Index index, array< Index, NumDims > &coords) const
Definition TensorGenerator.h:275
array< Index, NumDims > m_strides
Definition TensorGenerator.h:295
internal::TensorMaterializedBlock< CoeffReturnType, NumDims, Layout, Index > TensorBlock
Definition TensorGenerator.h:111
Generator m_generator
Definition TensorGenerator.h:297
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
Definition TensorGenerator.h:153
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
Definition TensorGenerator.h:137
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE internal::TensorBlockResourceRequirements getResourceRequirements() const
Definition TensorGenerator.h:168
XprType::Index Index
Definition TensorGenerator.h:85
TensorGeneratorOp< Generator, ArgType > XprType
Definition TensorGenerator.h:84
StorageMemory< CoeffReturnType, Device > Storage
Definition TensorGenerator.h:91
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool) const
Definition TensorGenerator.h:259
internal::TensorIntDivisor< Index > IndexDivisor
Definition TensorGenerator.h:103
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock block(TensorBlockDesc &desc, TensorBlockScratch &scratch, bool=false) const
Definition TensorGenerator.h:183
XprType::Scalar Scalar
Definition TensorGenerator.h:88
internal::TensorBlockDescriptor< NumDims, Index > TensorBlockDesc
Definition TensorGenerator.h:106
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
Definition TensorGenerator.h:145
EIGEN_STRONG_INLINE void cleanup()
Definition TensorGenerator.h:142
array< IndexDivisor, NumDims > m_fast_strides
Definition TensorGenerator.h:296
PacketType< CoeffReturnType, Device >::type PacketReturnType
Definition TensorGenerator.h:90
Index count
Definition TensorGenerator.h:179
Index size
Definition TensorGenerator.h:178
Index span
Definition TensorGenerator.h:177
Index stride
Definition TensorGenerator.h:176
A cost model used to limit the number of threads used for evaluating tensor expression.
Definition TensorEvaluator.h:29
const Device EIGEN_DEVICE_REF m_device
Definition TensorEvaluator.h:192
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
Definition TensorEvaluator.h:73
Derived::Scalar CoeffReturnType
Definition TensorEvaluator.h:32
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
Definition TensorEvaluator.h:94
@ BlockAccess
Definition TensorEvaluator.h:48
@ PreferBlockAccess
Definition TensorEvaluator.h:49
@ PacketAccess
Definition TensorEvaluator.h:47
@ Layout
Definition TensorEvaluator.h:50
@ IsAligned
Definition TensorEvaluator.h:46
Derived::Dimensions Dimensions
Definition TensorEvaluator.h:34
Definition TensorBlock.h:75
const TensorGeneratorOp< Generator, XprType > & type
Definition TensorGenerator.h:40
Definition XprHelper.h:332
TensorGeneratorOp< Generator, XprType > type
Definition TensorGenerator.h:46
Definition TensorTraits.h:175
XprType::Nested Nested
Definition TensorGenerator.h:30
XprTraits::StorageKind StorageKind
Definition TensorGenerator.h:28
XprTraits::Index Index
Definition TensorGenerator.h:29
XprType::Scalar Scalar
Definition TensorGenerator.h:26
XprTraits::PointerType PointerType
Definition TensorGenerator.h:34
remove_reference< Nested >::type _Nested
Definition TensorGenerator.h:31
traits< XprType > XprTraits
Definition TensorGenerator.h:27
Definition ForwardDeclarations.h:17
std::ptrdiff_t j
Definition tut_arithmetic_redux_minmax.cpp:2