Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType > Class Template Reference

#include <TensorBlock.h>

Public Types

typedef DSizes< IndexType, NumDims > Dimensions
 

Public Member Functions

 TensorBlockMapper ()=default
 
 TensorBlockMapper (const DSizes< IndexType, NumDims > &dimensions, const TensorBlockResourceRequirements &requirements)
 
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE IndexType blockCount () const
 
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE IndexType blockTotalSize () const
 
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const DSizes< IndexType, NumDims > & blockDimensions () const
 
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockDescriptor blockDescriptor (IndexType block_index) const
 

Private Types

typedef TensorBlockDescriptor< NumDims, IndexType > BlockDescriptor
 

Private Member Functions

void InitializeBlockDimensions ()
 

Private Attributes

DSizes< IndexType, NumDims > m_tensor_dimensions
 
TensorBlockResourceRequirements m_requirements
 
DSizes< IndexType, NumDims > m_block_dimensions
 
IndexType m_total_block_count
 
DSizes< IndexType, NumDims > m_tensor_strides
 
DSizes< IndexType, NumDims > m_block_strides
 

Member Typedef Documentation

◆ BlockDescriptor

template<int NumDims, int Layout, typename IndexType = Eigen::Index>
typedef TensorBlockDescriptor<NumDims, IndexType> Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::BlockDescriptor
private

◆ Dimensions

template<int NumDims, int Layout, typename IndexType = Eigen::Index>
typedef DSizes<IndexType, NumDims> Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::Dimensions

Constructor & Destructor Documentation

◆ TensorBlockMapper() [1/2]

template<int NumDims, int Layout, typename IndexType = Eigen::Index>
Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::TensorBlockMapper ( )
default

◆ TensorBlockMapper() [2/2]

template<int NumDims, int Layout, typename IndexType = Eigen::Index>
Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::TensorBlockMapper ( const DSizes< IndexType, NumDims > &  dimensions,
const TensorBlockResourceRequirements requirements 
)
inline
322  : m_tensor_dimensions(dimensions), m_requirements(requirements) {
323  // Compute block dimensions and the total number of blocks.
325  }
TensorBlockResourceRequirements m_requirements
Definition: TensorBlock.h:456
DSizes< IndexType, NumDims > m_tensor_dimensions
Definition: TensorBlock.h:455
void InitializeBlockDimensions()
Definition: TensorBlock.h:359

References Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::InitializeBlockDimensions().

Member Function Documentation

◆ blockCount()

template<int NumDims, int Layout, typename IndexType = Eigen::Index>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE IndexType Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::blockCount ( ) const
inline

◆ blockDescriptor()

template<int NumDims, int Layout, typename IndexType = Eigen::Index>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockDescriptor Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::blockDescriptor ( IndexType  block_index) const
inline
335  {
336  static const bool isColMajor = Layout == static_cast<int>(ColMajor);
337 
338  IndexType offset = 0;
339  DSizes<IndexType, NumDims> dimensions;
340 
341  if (NumDims == 0) return BlockDescriptor(offset, dimensions);
342 
343  // Iterate outer -> inner dimensions.
344  for (int i = NumDims - 1; i >= 0; --i) {
345  const int dim = isColMajor ? i : NumDims - i - 1;
346 
347  const IndexType idx = block_index / m_block_strides[dim];
348  block_index -= idx * m_block_strides[dim];
349 
350  const IndexType coord = idx * m_block_dimensions[dim];
351  dimensions[dim] = numext::mini(m_tensor_dimensions[dim] - coord, m_block_dimensions[dim]);
352  offset += coord * m_tensor_strides[dim];
353  }
354 
355  return {offset, dimensions};
356  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
DSizes< IndexType, NumDims > m_block_dimensions
Definition: TensorBlock.h:458
TensorBlockDescriptor< NumDims, IndexType > BlockDescriptor
Definition: TensorBlock.h:315
DSizes< IndexType, NumDims > m_tensor_strides
Definition: TensorBlock.h:461
DSizes< IndexType, NumDims > m_block_strides
Definition: TensorBlock.h:462
@ ColMajor
Definition: Constants.h:318
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T mini(const T &x, const T &y)
Definition: MathFunctions.h:920

References Eigen::ColMajor, i, Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::m_block_dimensions, Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::m_block_strides, Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::m_tensor_dimensions, Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::m_tensor_strides, and Eigen::numext::mini().

Referenced by Eigen::internal::TensorExecutor< Expression, DefaultDevice, Vectorizable, TiledEvaluation::On >::run().

◆ blockDimensions()

template<int NumDims, int Layout, typename IndexType = Eigen::Index>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const DSizes<IndexType, NumDims>& Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::blockDimensions ( ) const
inline

◆ blockTotalSize()

template<int NumDims, int Layout, typename IndexType = Eigen::Index>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE IndexType Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::blockTotalSize ( ) const
inline
329 { return m_block_dimensions.TotalSize(); }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex TotalSize() const
Definition: TensorDimensions.h:167

References Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::m_block_dimensions, and Eigen::DSizes< DenseIndex, NumDims >::TotalSize().

◆ InitializeBlockDimensions()

template<int NumDims, int Layout, typename IndexType = Eigen::Index>
void Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::InitializeBlockDimensions ( )
inlineprivate
359  {
360  // Requested block shape and size.
362  IndexType target_block_size = numext::maxi<IndexType>(1, static_cast<IndexType>(m_requirements.size));
363 
364  IndexType tensor_size = m_tensor_dimensions.TotalSize();
365 
366  // Corner case: one of the dimensions is zero. Logic below is too complex
367  // to handle this case on a general basis, just use unit block size.
368  // Note: we must not yield blocks with zero dimensions (recipe for
369  // overflows/underflows, divisions by zero and NaNs later).
370  if (tensor_size == 0) {
371  for (int i = 0; i < NumDims; ++i) {
372  m_block_dimensions[i] = 1;
373  }
375  return;
376  }
377 
378  // If tensor fits into a target block size, evaluate it as a single block.
379  if (tensor_size <= target_block_size) {
382  // The only valid block index is `0`, and in this case we do not need
383  // to compute real strides for tensor or blocks (see blockDescriptor).
384  for (int i = 0; i < NumDims; ++i) {
385  m_tensor_strides[i] = 0;
386  m_block_strides[i] = 1;
387  }
388  return;
389  }
390 
391  static const bool isColMajor = Layout == static_cast<int>(ColMajor);
392 
393  // Block shape skewed towards inner dimension.
394  if (shape_type == TensorBlockShapeType::kSkewedInnerDims) {
395  IndexType coeff_to_allocate = target_block_size;
396 
397  for (int i = 0; i < NumDims; ++i) {
398  const int dim = isColMajor ? i : NumDims - i - 1;
399  m_block_dimensions[dim] = numext::mini(coeff_to_allocate, m_tensor_dimensions[dim]);
400  coeff_to_allocate =
401  numext::div_ceil(coeff_to_allocate, numext::maxi(static_cast<IndexType>(1), m_block_dimensions[dim]));
402  }
403  eigen_assert(coeff_to_allocate == 1);
404 
405  } else if (shape_type == TensorBlockShapeType::kUniformAllDims) {
406  // Tensor will not fit within 'target_block_size' budget: calculate tensor
407  // block dimension sizes based on "square" dimension size target.
408  const IndexType dim_size_target = convert_index<IndexType>(
409  std::pow(static_cast<float>(target_block_size), 1.0f / static_cast<float>(m_block_dimensions.rank())));
410 
411  for (int i = 0; i < NumDims; ++i) {
412  // TODO(andydavis) Adjust the inner most 'block_dim_size' to make it
413  // a multiple of the packet size. Note that reducing
414  // 'block_dim_size' in this manner can increase the number of
415  // blocks, and so will amplify any per-block overhead.
416  m_block_dimensions[i] = numext::mini(dim_size_target, m_tensor_dimensions[i]);
417  }
418 
419  // Add any un-allocated coefficients to inner dimension(s).
420  IndexType total_size = m_block_dimensions.TotalSize();
421  for (int i = 0; i < NumDims; ++i) {
422  const int dim = isColMajor ? i : NumDims - i - 1;
423 
424  if (m_block_dimensions[dim] < m_tensor_dimensions[dim]) {
425  const IndexType total_size_other_dims = total_size / m_block_dimensions[dim];
426  const IndexType alloc_avail = numext::div_ceil<IndexType>(target_block_size, total_size_other_dims);
427  if (alloc_avail == m_block_dimensions[dim]) {
428  // Insufficient excess coefficients to allocate.
429  break;
430  }
431  m_block_dimensions[dim] = numext::mini(m_tensor_dimensions[dim], alloc_avail);
432  total_size = total_size_other_dims * m_block_dimensions[dim];
433  }
434  }
435 
436  } else {
437  eigen_assert(false); // unknown block shape
438  }
439 
441  numext::mini<IndexType>(target_block_size, m_tensor_dimensions.TotalSize()));
442 
443  // Calculate block counts by dimension and total block count.
444  DSizes<IndexType, NumDims> block_count;
445  for (int i = 0; i < NumDims; ++i) {
447  }
448  m_total_block_count = array_prod(block_count);
449 
450  // Calculate block strides (used for enumerating blocks).
451  m_tensor_strides = strides<Layout>(m_tensor_dimensions);
452  m_block_strides = strides<Layout>(block_count);
453  }
#define eigen_assert(x)
Definition: Macros.h:910
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 pow(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:625
constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE auto array_prod(const array< T, N > &arr) -> decltype(array_reduce< product_op, T, N >(arr, static_cast< T >(1)))
Definition: MoreMeta.h:497
TensorBlockShapeType
Definition: TensorBlock.h:73
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T maxi(const T &x, const T &y)
Definition: MathFunctions.h:926
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE EIGEN_CONSTEXPR T div_ceil(T a, T b)
Definition: MathFunctions.h:1251
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank() const
Definition: TensorDimensions.h:165
size_t size
Definition: TensorBlock.h:77
TensorBlockShapeType shape_type
Definition: TensorBlock.h:76

References Eigen::internal::array_prod(), Eigen::ColMajor, Eigen::numext::div_ceil(), eigen_assert, i, Eigen::internal::kSkewedInnerDims, Eigen::internal::kUniformAllDims, Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::m_block_dimensions, Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::m_block_strides, Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::m_requirements, Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::m_tensor_dimensions, Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::m_tensor_strides, Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::m_total_block_count, Eigen::numext::maxi(), Eigen::numext::mini(), Eigen::bfloat16_impl::pow(), Eigen::DSizes< DenseIndex, NumDims >::rank(), Eigen::internal::TensorBlockResourceRequirements::shape_type, Eigen::internal::TensorBlockResourceRequirements::size, and Eigen::DSizes< DenseIndex, NumDims >::TotalSize().

Referenced by Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::TensorBlockMapper().

Member Data Documentation

◆ m_block_dimensions

◆ m_block_strides

template<int NumDims, int Layout, typename IndexType = Eigen::Index>
DSizes<IndexType, NumDims> Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::m_block_strides
private

◆ m_requirements

template<int NumDims, int Layout, typename IndexType = Eigen::Index>
TensorBlockResourceRequirements Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::m_requirements
private

◆ m_tensor_dimensions

template<int NumDims, int Layout, typename IndexType = Eigen::Index>
DSizes<IndexType, NumDims> Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::m_tensor_dimensions
private

◆ m_tensor_strides

template<int NumDims, int Layout, typename IndexType = Eigen::Index>
DSizes<IndexType, NumDims> Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::m_tensor_strides
private

◆ m_total_block_count

template<int NumDims, int Layout, typename IndexType = Eigen::Index>
IndexType Eigen::internal::TensorBlockMapper< NumDims, Layout, IndexType >::m_total_block_count
private

The documentation for this class was generated from the following file: