Eigen::TensorContractionEvaluatorBase< Derived > Struct Template Reference

#include <TensorContraction.h>

Public Types

enum  {
  IsAligned = true , PacketAccess = (PacketType<CoeffReturnType, Device>::size > 1) , BlockAccess = false , PreferBlockAccess = false ,
  CoordAccess = false , RawAccess = true
}
 
typedef internal::traits< Derived >::Indices Indices
 
typedef internal::traits< Derived >::LeftArgType LeftArgType
 
typedef internal::traits< Derived >::RightArgType RightArgType
 
typedef internal::traits< Derived >::OutputKernelType OutputKernelType
 
typedef internal::traits< Derived >::Device Device
 
typedef TensorContractionOp< Indices, LeftArgType, RightArgType, OutputKernelTypeXprType
 
typedef std::remove_const_t< typename XprType::ScalarScalar
 
typedef XprType::Index Index
 
typedef XprType::CoeffReturnType CoeffReturnType
 
typedef PacketType< CoeffReturnType, Device >::type PacketReturnType
 
typedef StorageMemory< Scalar, DeviceStorage
 
typedef Storage::Type EvaluatorPointerType
 
typedef internal::TensorBlockNotImplemented TensorBlock
 
typedef std::conditional_t< static_cast< int >Layout)==static_cast< int >ColMajor), LeftArgType, RightArgTypeEvalLeftArgType
 
typedef std::conditional_t< static_cast< int >Layout)==static_cast< int >ColMajor), RightArgType, LeftArgTypeEvalRightArgType
 
typedef TensorEvaluator< EvalLeftArgType, DeviceLeftEvaluatorType
 
typedef TensorEvaluator< EvalRightArgType, DeviceRightEvaluatorType
 
typedef array< Index, ContractDimscontract_t
 
typedef array< Index, LDims - ContractDimsleft_nocontract_t
 
typedef array< Index, RDims - ContractDimsright_nocontract_t
 
typedef DSizes< Index, NumDimsDimensions
 

Public Member Functions

EIGEN_STRONG_INLINE TensorContractionEvaluatorBase (const XprType &op, const Device &device)
 
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensionsdimensions () const
 
EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded (EvaluatorPointerType data)
 
EIGEN_DEVICE_FUNC void evalTo (Scalar *buffer) const
 
template<bool lhs_inner_dim_contiguous, bool rhs_inner_dim_contiguous, bool rhs_inner_dim_reordered, int Alignment>
void evalProductSequential (Scalar *buffer) const
 
template<bool lhs_inner_dim_contiguous, bool rhs_inner_dim_contiguous, bool rhs_inner_dim_reordered, int Alignment>
EIGEN_DEVICE_FUNC void evalGemv (Scalar *buffer) const
 
template<bool lhs_inner_dim_contiguous, bool rhs_inner_dim_contiguous, bool rhs_inner_dim_reordered, int Alignment>
EIGEN_DEVICE_FUNC void evalGemm (Scalar *buffer) const
 
template<bool lhs_inner_dim_contiguous, bool rhs_inner_dim_contiguous, bool rhs_inner_dim_reordered, int Alignment>
EIGEN_DEVICE_FUNC void evalGemmPartialWithoutOutputKernel (Scalar *buffer, Index k_start, Index k_end, int num_threads) const
 
template<bool lhs_inner_dim_contiguous, bool rhs_inner_dim_contiguous, bool rhs_inner_dim_reordered, int Alignment, bool use_output_kernel>
EIGEN_DEVICE_FUNC void evalGemmPartial (Scalar *buffer, Index k_start, Index k_end, int num_threads) const
 
EIGEN_STRONG_INLINE void cleanup ()
 
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff (Index index) const
 
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff (bool) const
 
template<int LoadMode>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet (Index index) const
 
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EvaluatorPointerType data () const
 

Static Public Attributes

static constexpr int Layout = TensorEvaluator<LeftArgType, Device>::Layout
 
static constexpr int LDims
 
static constexpr int RDims
 
static constexpr int ContractDims = internal::array_size<Indices>::value
 
static constexpr int NumDims = LDims + RDims - 2 * ContractDims
 

Protected Attributes

Dimensions m_dimensions
 
contract_t m_k_strides
 
contract_t m_left_contracting_strides
 
contract_t m_right_contracting_strides
 
bool m_lhs_inner_dim_contiguous
 
bool m_rhs_inner_dim_contiguous
 
bool m_rhs_inner_dim_reordered
 
left_nocontract_t m_i_strides
 
right_nocontract_t m_j_strides
 
left_nocontract_t m_left_nocontract_strides
 
right_nocontract_t m_right_nocontract_strides
 
Index m_i_size
 
Index m_j_size
 
Index m_k_size
 
TensorContractionParams m_tensor_contraction_params
 
TensorEvaluator< EvalLeftArgType, Devicem_leftImpl
 
TensorEvaluator< EvalRightArgType, Devicem_rightImpl
 
const Device EIGEN_DEVICE_REF m_device
 
OutputKernelType m_output_kernel
 
EvaluatorPointerType m_result
 

Member Typedef Documentation

◆ CoeffReturnType

template<typename Derived >
typedef XprType::CoeffReturnType Eigen::TensorContractionEvaluatorBase< Derived >::CoeffReturnType

◆ contract_t

template<typename Derived >
typedef array<Index, ContractDims> Eigen::TensorContractionEvaluatorBase< Derived >::contract_t

◆ Device

template<typename Derived >
typedef internal::traits<Derived>::Device Eigen::TensorContractionEvaluatorBase< Derived >::Device

◆ Dimensions

template<typename Derived >
typedef DSizes<Index, NumDims> Eigen::TensorContractionEvaluatorBase< Derived >::Dimensions

◆ EvalLeftArgType

template<typename Derived >
typedef std::conditional_t<static_cast<int>Layout) == static_cast<int>ColMajor), LeftArgType, RightArgType> Eigen::TensorContractionEvaluatorBase< Derived >::EvalLeftArgType

◆ EvalRightArgType

template<typename Derived >
typedef std::conditional_t<static_cast<int>Layout) == static_cast<int>ColMajor), RightArgType, LeftArgType> Eigen::TensorContractionEvaluatorBase< Derived >::EvalRightArgType

◆ EvaluatorPointerType

template<typename Derived >
typedef Storage::Type Eigen::TensorContractionEvaluatorBase< Derived >::EvaluatorPointerType

◆ Index

template<typename Derived >
typedef XprType::Index Eigen::TensorContractionEvaluatorBase< Derived >::Index

◆ Indices

template<typename Derived >
typedef internal::traits<Derived>::Indices Eigen::TensorContractionEvaluatorBase< Derived >::Indices

◆ left_nocontract_t

template<typename Derived >
typedef array<Index, LDims - ContractDims> Eigen::TensorContractionEvaluatorBase< Derived >::left_nocontract_t

◆ LeftArgType

template<typename Derived >
typedef internal::traits<Derived>::LeftArgType Eigen::TensorContractionEvaluatorBase< Derived >::LeftArgType

◆ LeftEvaluatorType

◆ OutputKernelType

template<typename Derived >
typedef internal::traits<Derived>::OutputKernelType Eigen::TensorContractionEvaluatorBase< Derived >::OutputKernelType

◆ PacketReturnType

template<typename Derived >
typedef PacketType<CoeffReturnType, Device>::type Eigen::TensorContractionEvaluatorBase< Derived >::PacketReturnType

◆ right_nocontract_t

template<typename Derived >
typedef array<Index, RDims - ContractDims> Eigen::TensorContractionEvaluatorBase< Derived >::right_nocontract_t

◆ RightArgType

template<typename Derived >
typedef internal::traits<Derived>::RightArgType Eigen::TensorContractionEvaluatorBase< Derived >::RightArgType

◆ RightEvaluatorType

◆ Scalar

template<typename Derived >
typedef std::remove_const_t<typename XprType::Scalar> Eigen::TensorContractionEvaluatorBase< Derived >::Scalar

◆ Storage

template<typename Derived >
typedef StorageMemory<Scalar, Device> Eigen::TensorContractionEvaluatorBase< Derived >::Storage

◆ TensorBlock

◆ XprType

Member Enumeration Documentation

◆ anonymous enum

template<typename Derived >
anonymous enum
Enumerator
IsAligned 
PacketAccess 
BlockAccess 
PreferBlockAccess 
CoordAccess 
RawAccess 
358  {
359  IsAligned = true,
361  BlockAccess = false,
362  PreferBlockAccess = false,
363  CoordAccess = false, // to be implemented
364  RawAccess = true
365  };
@ PreferBlockAccess
Definition: TensorContraction.h:362
@ PacketAccess
Definition: TensorContraction.h:360
@ RawAccess
Definition: TensorContraction.h:364
@ CoordAccess
Definition: TensorContraction.h:363
@ IsAligned
Definition: TensorContraction.h:359
@ BlockAccess
Definition: TensorContraction.h:361
@ size
Definition: GenericPacketMath.h:113

Constructor & Destructor Documentation

◆ TensorContractionEvaluatorBase()

template<typename Derived >
EIGEN_STRONG_INLINE Eigen::TensorContractionEvaluatorBase< Derived >::TensorContractionEvaluatorBase ( const XprType op,
const Device device 
)
inline
397  : m_leftImpl(choose(Cond<static_cast<int>(Layout) == static_cast<int>(ColMajor)>(), op.lhsExpression(),
398  op.rhsExpression()),
399  device),
400  m_rightImpl(choose(Cond<static_cast<int>(Layout) == static_cast<int>(ColMajor)>(), op.rhsExpression(),
401  op.lhsExpression()),
402  device),
403  m_device(device),
404  m_output_kernel(op.outputKernel()),
405  m_result(NULL) {
408  YOU_MADE_A_PROGRAMMING_MISTAKE);
409 
410  DSizes<Index, LDims> eval_left_dims;
411  DSizes<Index, RDims> eval_right_dims;
412  array<IndexPair<Index>, ContractDims> eval_op_indices;
413  if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) {
414  // For ColMajor, we keep using the existing dimensions
415  for (int i = 0; i < LDims; i++) {
416  eval_left_dims[i] = m_leftImpl.dimensions()[i];
417  }
418  for (int i = 0; i < RDims; i++) {
419  eval_right_dims[i] = m_rightImpl.dimensions()[i];
420  }
421  // We keep the pairs of contracting indices.
422  for (int i = 0; i < ContractDims; i++) {
423  eval_op_indices[i].first = op.indices()[i].first;
424  eval_op_indices[i].second = op.indices()[i].second;
425  }
426  } else {
427  // For RowMajor, we need to reverse the existing dimensions
428  for (int i = 0; i < LDims; i++) {
429  eval_left_dims[i] = m_leftImpl.dimensions()[LDims - i - 1];
430  }
431  for (int i = 0; i < RDims; i++) {
432  eval_right_dims[i] = m_rightImpl.dimensions()[RDims - i - 1];
433  }
434  // We need to flip all the pairs of contracting indices as well as
435  // reversing the dimensions.
436  for (int i = 0; i < ContractDims; i++) {
437  eval_op_indices[i].first = LDims - 1 - op.indices()[ContractDims - 1 - i].second;
438  eval_op_indices[i].second = RDims - 1 - op.indices()[ContractDims - 1 - i].first;
439  }
440  }
441 
442  // Check for duplicate axes and make sure the first index in eval_op_indices
443  // is increasing. Using O(n^2) sorting is OK since ContractDims is small
444  for (int i = 0; i < ContractDims; i++) {
445  for (int j = i + 1; j < ContractDims; j++) {
446  eigen_assert(eval_op_indices[j].first != eval_op_indices[i].first &&
447  eval_op_indices[j].second != eval_op_indices[i].second && "contraction axes should be unique");
448  if (eval_op_indices[j].first < eval_op_indices[i].first) {
449  numext::swap(eval_op_indices[j], eval_op_indices[i]);
450  }
451  }
452  }
453 
454  array<Index, LDims> lhs_strides;
455  lhs_strides[0] = 1;
456  for (int i = 0; i < LDims - 1; ++i) {
457  lhs_strides[i + 1] = lhs_strides[i] * eval_left_dims[i];
458  }
459 
460  array<Index, RDims> rhs_strides;
461  rhs_strides[0] = 1;
462  for (int i = 0; i < RDims - 1; ++i) {
463  rhs_strides[i + 1] = rhs_strides[i] * eval_right_dims[i];
464  }
465 
466  if (m_i_strides.size() > 0) m_i_strides[0] = 1;
467  if (m_j_strides.size() > 0) m_j_strides[0] = 1;
468  if (m_k_strides.size() > 0) m_k_strides[0] = 1;
469 
470  m_i_size = 1;
471  m_j_size = 1;
472  m_k_size = 1;
473 
474  // To compute the dimension, we simply concatenate the non-contracting
475  // dimensions of the left and then the right tensor. Additionally, we also
476  // compute the strides corresponding to the left non-contracting
477  // dimensions and right non-contracting dimensions.
479  int dim_idx = 0;
480  Index nocontract_idx = 0;
481 
482  for (int i = 0; i < LDims; i++) {
483  // find if we are contracting on index i of left tensor
484  bool contracting = false;
485  for (int j = 0; j < ContractDims; j++) {
486  if (eval_op_indices[j].first == i) {
487  contracting = true;
488  break;
489  }
490  }
491  if (!contracting) {
492  // add dimension size to output dimensions
493  m_dimensions[dim_idx] = eval_left_dims[i];
494  m_left_nocontract_strides[nocontract_idx] = lhs_strides[i];
495  if (dim_idx != i) {
497  }
498  if (nocontract_idx + 1 < internal::array_size<left_nocontract_t>::value) {
499  m_i_strides[nocontract_idx + 1] = m_i_strides[nocontract_idx] * eval_left_dims[i];
500  } else {
501  m_i_size = m_i_strides[nocontract_idx] * eval_left_dims[i];
502  }
503  dim_idx++;
504  nocontract_idx++;
505  }
506  }
507 
508  nocontract_idx = 0;
509  for (int i = 0; i < RDims; i++) {
510  bool contracting = false;
511  // find if we are contracting on index i of right tensor
512  for (int j = 0; j < ContractDims; j++) {
513  if (eval_op_indices[j].second == i) {
514  contracting = true;
515  break;
516  }
517  }
518  if (!contracting) {
519  m_dimensions[dim_idx] = eval_right_dims[i];
520  if (nocontract_idx + 1 < internal::array_size<right_nocontract_t>::value) {
521  m_j_strides[nocontract_idx + 1] = m_j_strides[nocontract_idx] * eval_right_dims[i];
522  } else {
523  m_j_size = m_j_strides[nocontract_idx] * eval_right_dims[i];
524  }
525  m_right_nocontract_strides[nocontract_idx] = rhs_strides[i];
526  dim_idx++;
527  nocontract_idx++;
528  }
529  }
530 
531  // Now compute the strides corresponding to the contracting dimensions. We
532  // assumed above that non-contracting axes are represented in the same order
533  // in the matrix as they are in the tensor. This is not the case for
534  // contracting axes. As the contracting axes must be of the same size in
535  // each tensor, we'll only look at the first tensor here.
538  for (int i = 0; i < ContractDims; i++) {
539  Index left = eval_op_indices[i].first;
540  Index right = eval_op_indices[i].second;
541 
542  Index size = eval_left_dims[left];
543  eigen_assert(size == eval_right_dims[right] && "Contraction axes must be same size");
544 
545  if (i + 1 < static_cast<int>(internal::array_size<contract_t>::value)) {
546  m_k_strides[i + 1] = m_k_strides[i] * size;
547  } else {
548  m_k_size = m_k_strides[i] * size;
549  }
550  m_left_contracting_strides[i] = lhs_strides[left];
551  m_right_contracting_strides[i] = rhs_strides[right];
552 
553  if (i > 0 && right < eval_op_indices[i - 1].second) {
555  }
556  if (right != i) {
558  }
559  }
560 
561  // If the layout is RowMajor, we need to reverse the m_dimensions
562  if (static_cast<int>(Layout) == static_cast<int>(RowMajor)) {
563  for (int i = 0, j = NumDims - 1; i < j; i++, j--) {
565  }
566  }
567 
568  // A set of parameters that will allow output kernel to get from output
569  // tensor dimensions (i, j) into the original tensor dimensions.
570  // TODO(ezhulenev): Add parameters required to infer output tensor index for
571  // more complex contractions than 2x2 on internal dimension.
573  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define eigen_assert(x)
Definition: Macros.h:910
#define EIGEN_STATIC_ASSERT(X, MSG)
Definition: StaticAssert.h:26
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
@ ColMajor
Definition: Constants.h:318
@ RowMajor
Definition: Constants.h:320
char char * op
Definition: level2_impl.h:374
EIGEN_STRONG_INLINE void swap(T &a, T &b)
Definition: Meta.h:536
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const T1 & choose(Cond< true >, const T1 &first, const T2 &)
Definition: TensorMeta.h:22
static constexpr int Layout
Definition: TensorContraction.h:357
Index m_i_size
Definition: TensorContraction.h:901
static constexpr int NumDims
Definition: TensorContraction.h:388
static constexpr int LDims
Definition: TensorContraction.h:383
right_nocontract_t m_j_strides
Definition: TensorContraction.h:897
right_nocontract_t m_right_nocontract_strides
Definition: TensorContraction.h:899
contract_t m_right_contracting_strides
Definition: TensorContraction.h:890
const Device EIGEN_DEVICE_REF m_device
Definition: TensorContraction.h:909
static constexpr int RDims
Definition: TensorContraction.h:385
left_nocontract_t m_left_nocontract_strides
Definition: TensorContraction.h:898
EvaluatorPointerType m_result
Definition: TensorContraction.h:911
XprType::Index Index
Definition: TensorContraction.h:351
bool m_rhs_inner_dim_reordered
Definition: TensorContraction.h:894
bool m_rhs_inner_dim_contiguous
Definition: TensorContraction.h:893
contract_t m_left_contracting_strides
Definition: TensorContraction.h:889
static constexpr int ContractDims
Definition: TensorContraction.h:387
Index m_j_size
Definition: TensorContraction.h:902
TensorEvaluator< EvalRightArgType, Device > m_rightImpl
Definition: TensorContraction.h:908
Index m_k_size
Definition: TensorContraction.h:903
OutputKernelType m_output_kernel
Definition: TensorContraction.h:910
TensorContractionParams m_tensor_contraction_params
Definition: TensorContraction.h:905
bool m_lhs_inner_dim_contiguous
Definition: TensorContraction.h:892
Dimensions m_dimensions
Definition: TensorContraction.h:886
TensorEvaluator< EvalLeftArgType, Device > m_leftImpl
Definition: TensorContraction.h:907
contract_t m_k_strides
Definition: TensorContraction.h:888
left_nocontract_t m_i_strides
Definition: TensorContraction.h:896
bool swapped_arguments
Definition: TensorContraction.h:265
static constexpr int Layout
Definition: TensorEvaluator.h:46
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
Definition: TensorEvaluator.h:69
static constexpr Index value
Definition: Meta.h:306
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References Eigen::ColMajor, Eigen::TensorContractionEvaluatorBase< Derived >::ContractDims, Eigen::TensorEvaluator< Derived, Device >::dimensions(), eigen_assert, EIGEN_STATIC_ASSERT, i, j, Eigen::TensorContractionEvaluatorBase< Derived >::Layout, Eigen::TensorContractionEvaluatorBase< Derived >::LDims, Eigen::TensorContractionEvaluatorBase< Derived >::m_dimensions, Eigen::TensorContractionEvaluatorBase< Derived >::m_i_size, Eigen::TensorContractionEvaluatorBase< Derived >::m_i_strides, Eigen::TensorContractionEvaluatorBase< Derived >::m_j_size, Eigen::TensorContractionEvaluatorBase< Derived >::m_j_strides, Eigen::TensorContractionEvaluatorBase< Derived >::m_k_size, Eigen::TensorContractionEvaluatorBase< Derived >::m_k_strides, Eigen::TensorContractionEvaluatorBase< Derived >::m_left_contracting_strides, Eigen::TensorContractionEvaluatorBase< Derived >::m_left_nocontract_strides, Eigen::TensorContractionEvaluatorBase< Derived >::m_leftImpl, Eigen::TensorContractionEvaluatorBase< Derived >::m_lhs_inner_dim_contiguous, Eigen::TensorContractionEvaluatorBase< Derived >::m_rhs_inner_dim_contiguous, Eigen::TensorContractionEvaluatorBase< Derived >::m_rhs_inner_dim_reordered, Eigen::TensorContractionEvaluatorBase< Derived >::m_right_contracting_strides, Eigen::TensorContractionEvaluatorBase< Derived >::m_right_nocontract_strides, Eigen::TensorContractionEvaluatorBase< Derived >::m_rightImpl, Eigen::TensorContractionEvaluatorBase< Derived >::m_tensor_contraction_params, Eigen::TensorContractionEvaluatorBase< Derived >::NumDims, op, Eigen::TensorContractionEvaluatorBase< Derived >::RDims, Eigen::RowMajor, size, Eigen::numext::swap(), and Eigen::TensorContractionParams::swapped_arguments.

Member Function Documentation

◆ cleanup()

◆ coeff()

template<typename Derived >
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType Eigen::TensorContractionEvaluatorBase< Derived >::coeff ( Index  index) const
inline

◆ costPerCoeff()

template<typename Derived >
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost Eigen::TensorContractionEvaluatorBase< Derived >::costPerCoeff ( bool  ) const
inline
874  {
875  return TensorOpCost(sizeof(CoeffReturnType), 0, 0);
876  }
XprType::CoeffReturnType CoeffReturnType
Definition: TensorContraction.h:352

◆ data()

◆ dimensions()

◆ evalGemm()

template<typename Derived >
template<bool lhs_inner_dim_contiguous, bool rhs_inner_dim_contiguous, bool rhs_inner_dim_reordered, int Alignment>
EIGEN_DEVICE_FUNC void Eigen::TensorContractionEvaluatorBase< Derived >::evalGemm ( Scalar buffer) const
inline
743  {
744  // columns in left side, rows in right side
745  const Index k = this->m_k_size;
746  this->template evalGemmPartial<lhs_inner_dim_contiguous, rhs_inner_dim_contiguous, rhs_inner_dim_reordered,
747  Alignment, true>(buffer, 0, k, 1);
748  }
char char char int int * k
Definition: level2_impl.h:374
EIGEN_DEVICE_FUNC void evalGemmPartial(Scalar *buffer, Index k_start, Index k_end, int num_threads) const
Definition: TensorContraction.h:759

References Eigen::TensorContractionEvaluatorBase< Derived >::evalGemmPartial(), k, and Eigen::TensorContractionEvaluatorBase< Derived >::m_k_size.

◆ evalGemmPartial()

template<typename Derived >
template<bool lhs_inner_dim_contiguous, bool rhs_inner_dim_contiguous, bool rhs_inner_dim_reordered, int Alignment, bool use_output_kernel>
EIGEN_DEVICE_FUNC void Eigen::TensorContractionEvaluatorBase< Derived >::evalGemmPartial ( Scalar buffer,
Index  k_start,
Index  k_end,
int  num_threads 
) const
inline
759  {
760  eigen_assert(k_end >= k_start && k_start >= 0 && k_end <= this->m_k_size);
761  // columns in slice on left side, rows on right side
762  const Index k_slice = k_end - k_start;
763 
764  // rows in left side
765  const Index m = this->m_i_size;
766 
767  // columns in right side
768  const Index n = this->m_j_size;
769 
770  // define data mappers for Lhs and Rhs
771  typedef std::remove_const_t<typename EvalLeftArgType::Scalar> LhsScalar;
772  typedef std::remove_const_t<typename EvalRightArgType::Scalar> RhsScalar;
773 
774  typedef TensorEvaluator<EvalLeftArgType, Device> LeftEvaluator;
775  typedef TensorEvaluator<EvalRightArgType, Device> RightEvaluator;
776 
779 
780  typedef internal::TensorContractionInputMapper<LhsScalar, Index, internal::Lhs, LeftEvaluator, left_nocontract_t,
781  contract_t, lhs_packet_size, lhs_inner_dim_contiguous, false,
782  Unaligned>
783  LhsMapper;
784 
785  typedef internal::TensorContractionInputMapper<RhsScalar, Index, internal::Rhs, RightEvaluator, right_nocontract_t,
786  contract_t, rhs_packet_size, rhs_inner_dim_contiguous,
787  rhs_inner_dim_reordered, Unaligned>
788  RhsMapper;
789 
790  typedef internal::blas_data_mapper<Scalar, Index, ColMajor> OutputMapper;
791 
792  typedef internal::TensorContractionKernel<Scalar, LhsScalar, RhsScalar, Index, OutputMapper, LhsMapper, RhsMapper>
793  TensorContractionKernel;
794 
795  // initialize data mappers
796  LhsMapper lhs(this->m_leftImpl, this->m_left_nocontract_strides, this->m_i_strides,
798 
799  RhsMapper rhs(this->m_rightImpl, this->m_right_nocontract_strides, this->m_j_strides,
801 
802  OutputMapper output(buffer, m);
803 
804  // Sizes of the blocks to load in cache. See the Goto paper for details.
805  internal::TensorContractionBlocking<Scalar, LhsScalar, RhsScalar, Index, internal::ShardByCol> blocking(
806  k_slice, m, n, num_threads);
807  const Index kc = blocking.kc();
808  const Index mc = numext::mini(m, blocking.mc());
809  const Index nc = numext::mini(n, blocking.nc());
810 
811  typedef typename TensorContractionKernel::LhsBlock LhsBlock;
812  typedef typename TensorContractionKernel::RhsBlock RhsBlock;
813 
814  LhsBlock blockA;
815  RhsBlock blockB;
816 
817  TensorContractionKernel kernel(m, k_slice, n, mc, kc, nc);
818 
819  typedef typename TensorContractionKernel::BlockMemHandle BlockMemHandle;
820  const BlockMemHandle packed_mem = kernel.allocate(this->m_device, &blockA, &blockB);
821 
822  // If a contraction kernel does not support beta, explicitly initialize
823  // output buffer with zeroes.
824  if (!TensorContractionKernel::HasBeta) {
825  this->m_device.fill(buffer, buffer + m * n, Scalar(0));
826  }
827 
828  for (Index i2 = 0; i2 < m; i2 += mc) {
829  const Index actual_mc = numext::mini(i2 + mc, m) - i2;
830  for (Index k2 = k_start; k2 < k_end; k2 += kc) {
831  // make sure we don't overshoot right edge of left matrix, then pack vertical panel
832  const Index actual_kc = numext::mini(k2 + kc, k_end) - k2;
833  kernel.packLhs(&blockA, lhs.getSubMapper(i2, k2), actual_kc, actual_mc);
834 
835  // If kernel supports beta, there is no need to initialize output
836  // buffer with zeroes.
837  const Scalar alpha = Scalar(1);
838  const Scalar beta = (TensorContractionKernel::HasBeta && k2 == k_start) ? Scalar(0) : Scalar(1);
839 
840  // series of horizontal blocks
841  for (Index j2 = 0; j2 < n; j2 += nc) {
842  // make sure we don't overshoot right edge of right matrix, then pack block
843  const Index actual_nc = numext::mini(j2 + nc, n) - j2;
844  kernel.packRhs(&blockB, rhs.getSubMapper(k2, j2), actual_kc, actual_nc);
845 
846  // call gebp (matrix kernel)
847  // The parameters here are copied from Eigen's GEMM implementation
848  const OutputMapper output_mapper = output.getSubMapper(i2, j2);
849  kernel.invoke(output_mapper, blockA, blockB, actual_mc, actual_kc, actual_nc, alpha, beta);
850 
851  // We are done with this [i2, j2] output block.
852  if (use_output_kernel && k2 + kc >= k_end) {
853  m_output_kernel(output_mapper, m_tensor_contraction_params, i2, j2, actual_mc, actual_nc);
854  }
855  }
856  }
857  }
858 
859  kernel.deallocate(this->m_device, packed_mem);
860  }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
SCALAR Scalar
Definition: bench_gemm.cpp:45
@ Unaligned
Definition: Constants.h:235
RealScalar alpha
Definition: level1_cplx_impl.h:151
int * m
Definition: level2_cplx_impl.h:294
Scalar beta
Definition: level2_cplx_impl.h:36
@ Lhs
Definition: TensorContractionMapper.h:20
@ Rhs
Definition: TensorContractionMapper.h:20
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T mini(const T &x, const T &y)
Definition: MathFunctions.h:920
void output(std::ostream &outfile, const unsigned &nplot)
Overload output function.
Definition: overloaded_element_body.h:490
array< Index, RDims - ContractDims > right_nocontract_t
Definition: TensorContraction.h:392
std::remove_const_t< typename XprType::Scalar > Scalar
Definition: TensorContraction.h:350
array< Index, ContractDims > contract_t
Definition: TensorContraction.h:390
array< Index, LDims - ContractDims > left_nocontract_t
Definition: TensorContraction.h:391
@ size
Definition: GenericPacketMath.h:139

References alpha, beta, eigen_assert, Eigen::internal::TensorContractionBlocking< ResScalar, LhsScalar, RhsScalar, StorageIndex, ShardingType >::kc(), Eigen::internal::Lhs, m, Eigen::TensorContractionEvaluatorBase< Derived >::m_device, Eigen::TensorContractionEvaluatorBase< Derived >::m_i_size, Eigen::TensorContractionEvaluatorBase< Derived >::m_i_strides, Eigen::TensorContractionEvaluatorBase< Derived >::m_j_size, Eigen::TensorContractionEvaluatorBase< Derived >::m_j_strides, Eigen::TensorContractionEvaluatorBase< Derived >::m_k_size, Eigen::TensorContractionEvaluatorBase< Derived >::m_k_strides, Eigen::TensorContractionEvaluatorBase< Derived >::m_left_contracting_strides, Eigen::TensorContractionEvaluatorBase< Derived >::m_left_nocontract_strides, Eigen::TensorContractionEvaluatorBase< Derived >::m_leftImpl, Eigen::TensorContractionEvaluatorBase< Derived >::m_output_kernel, Eigen::TensorContractionEvaluatorBase< Derived >::m_right_contracting_strides, Eigen::TensorContractionEvaluatorBase< Derived >::m_right_nocontract_strides, Eigen::TensorContractionEvaluatorBase< Derived >::m_rightImpl, Eigen::TensorContractionEvaluatorBase< Derived >::m_tensor_contraction_params, Eigen::internal::TensorContractionBlocking< ResScalar, LhsScalar, RhsScalar, StorageIndex, ShardingType >::mc(), Eigen::numext::mini(), n, Eigen::internal::TensorContractionBlocking< ResScalar, LhsScalar, RhsScalar, StorageIndex, ShardingType >::nc(), output(), Eigen::internal::Rhs, and Eigen::Unaligned.

Referenced by Eigen::TensorContractionEvaluatorBase< Derived >::evalGemm(), and Eigen::TensorContractionEvaluatorBase< Derived >::evalGemmPartialWithoutOutputKernel().

◆ evalGemmPartialWithoutOutputKernel()

template<typename Derived >
template<bool lhs_inner_dim_contiguous, bool rhs_inner_dim_contiguous, bool rhs_inner_dim_reordered, int Alignment>
EIGEN_DEVICE_FUNC void Eigen::TensorContractionEvaluatorBase< Derived >::evalGemmPartialWithoutOutputKernel ( Scalar buffer,
Index  k_start,
Index  k_end,
int  num_threads 
) const
inline
752  {
753  evalGemmPartial<lhs_inner_dim_contiguous, rhs_inner_dim_contiguous, rhs_inner_dim_reordered, Alignment,
754  /*use_output_kernel*/ false>(buffer, k_start, k_end, num_threads);
755  }

References Eigen::TensorContractionEvaluatorBase< Derived >::evalGemmPartial().

◆ evalGemv()

template<typename Derived >
template<bool lhs_inner_dim_contiguous, bool rhs_inner_dim_contiguous, bool rhs_inner_dim_reordered, int Alignment>
EIGEN_DEVICE_FUNC void Eigen::TensorContractionEvaluatorBase< Derived >::evalGemv ( Scalar buffer) const
inline
699  {
700  const Index rows = m_i_size;
701  const Index cols = m_k_size;
702 
703  typedef std::remove_const_t<typename EvalLeftArgType::Scalar> LhsScalar;
704  typedef std::remove_const_t<typename EvalRightArgType::Scalar> RhsScalar;
705  typedef TensorEvaluator<EvalLeftArgType, Device> LeftEvaluator;
706  typedef TensorEvaluator<EvalRightArgType, Device> RightEvaluator;
709  const int lhs_alignment = LeftEvaluator::IsAligned ? Aligned : Unaligned;
710  const int rhs_alignment = RightEvaluator::IsAligned ? Aligned : Unaligned;
711  typedef internal::TensorContractionInputMapper<LhsScalar, Index, internal::Lhs, LeftEvaluator, left_nocontract_t,
712  contract_t, lhs_packet_size, lhs_inner_dim_contiguous, false,
713  lhs_alignment>
714  LhsMapper;
715 
716  typedef internal::TensorContractionInputMapper<RhsScalar, Index, internal::Rhs, RightEvaluator, right_nocontract_t,
717  contract_t, rhs_packet_size, rhs_inner_dim_contiguous,
718  rhs_inner_dim_reordered, rhs_alignment>
719  RhsMapper;
720 
723 
724  const Scalar alpha(1);
725  const Index resIncr(1);
726 
727  // zero out the result buffer (which must be of size at least rows * sizeof(Scalar)
728  m_device.fill(buffer, buffer + rows, Scalar(0));
729 
730  internal::general_matrix_vector_product<Index, LhsScalar, LhsMapper, ColMajor, false, RhsScalar, RhsMapper,
731  false>::run(rows, cols, lhs, rhs, buffer, resIncr, alpha);
732 
733  typedef internal::blas_data_mapper<Scalar, Index, ColMajor> OutputMapper;
734  m_output_kernel(OutputMapper(buffer, rows), m_tensor_contraction_params, static_cast<Index>(0),
735  static_cast<Index>(0), rows, static_cast<Index>(1));
736  }
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
@ Aligned
Definition: Constants.h:242
auto run(Kernel kernel, Args &&... args) -> decltype(kernel(args...))
Definition: gpu_test_helper.h:414

References Eigen::Aligned, alpha, Eigen::ColMajor, cols, Eigen::internal::Lhs, Eigen::TensorContractionEvaluatorBase< Derived >::m_device, Eigen::TensorContractionEvaluatorBase< Derived >::m_i_size, Eigen::TensorContractionEvaluatorBase< Derived >::m_i_strides, Eigen::TensorContractionEvaluatorBase< Derived >::m_j_strides, Eigen::TensorContractionEvaluatorBase< Derived >::m_k_size, Eigen::TensorContractionEvaluatorBase< Derived >::m_k_strides, Eigen::TensorContractionEvaluatorBase< Derived >::m_left_contracting_strides, Eigen::TensorContractionEvaluatorBase< Derived >::m_left_nocontract_strides, Eigen::TensorContractionEvaluatorBase< Derived >::m_leftImpl, Eigen::TensorContractionEvaluatorBase< Derived >::m_output_kernel, Eigen::TensorContractionEvaluatorBase< Derived >::m_right_contracting_strides, Eigen::TensorContractionEvaluatorBase< Derived >::m_right_nocontract_strides, Eigen::TensorContractionEvaluatorBase< Derived >::m_rightImpl, Eigen::TensorContractionEvaluatorBase< Derived >::m_tensor_contraction_params, Eigen::internal::Rhs, rows, Eigen::run(), and Eigen::Unaligned.

◆ evalProductSequential()

template<typename Derived >
template<bool lhs_inner_dim_contiguous, bool rhs_inner_dim_contiguous, bool rhs_inner_dim_reordered, int Alignment>
void Eigen::TensorContractionEvaluatorBase< Derived >::evalProductSequential ( Scalar buffer) const
inline
684  {
685  if (this->m_j_size == 1) {
686  this->template evalGemv<lhs_inner_dim_contiguous, rhs_inner_dim_contiguous, rhs_inner_dim_reordered, Alignment>(
687  buffer);
688  } else {
689  this->template evalGemm<lhs_inner_dim_contiguous, rhs_inner_dim_contiguous, rhs_inner_dim_reordered, Alignment>(
690  buffer);
691  }
692  }

References Eigen::TensorContractionEvaluatorBase< Derived >::m_j_size.

◆ evalSubExprsIfNeeded()

template<typename Derived >
EIGEN_STRONG_INLINE bool Eigen::TensorContractionEvaluatorBase< Derived >::evalSubExprsIfNeeded ( EvaluatorPointerType  data)
inline
577  {
580  if (data) {
581  evalTo(data);
582  return false;
583  } else {
584  m_result = static_cast<EvaluatorPointerType>(m_device.allocate(dimensions().TotalSize() * sizeof(Scalar)));
585  evalTo(m_result);
586  return true;
587  }
588  }
Storage::Type EvaluatorPointerType
Definition: TensorContraction.h:355
EIGEN_DEVICE_FUNC void evalTo(Scalar *buffer) const
Definition: TensorContraction.h:672
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
Definition: TensorContraction.h:575
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EvaluatorPointerType data() const
Definition: TensorContraction.h:883
EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType dest)
Definition: TensorEvaluator.h:71

References Eigen::TensorContractionEvaluatorBase< Derived >::data(), Eigen::TensorContractionEvaluatorBase< Derived >::dimensions(), Eigen::TensorEvaluator< Derived, Device >::evalSubExprsIfNeeded(), Eigen::TensorContractionEvaluatorBase< Derived >::evalTo(), Eigen::TensorContractionEvaluatorBase< Derived >::m_device, Eigen::TensorContractionEvaluatorBase< Derived >::m_leftImpl, Eigen::TensorContractionEvaluatorBase< Derived >::m_result, and Eigen::TensorContractionEvaluatorBase< Derived >::m_rightImpl.

◆ evalTo()

template<typename Derived >
EIGEN_DEVICE_FUNC void Eigen::TensorContractionEvaluatorBase< Derived >::evalTo ( Scalar buffer) const
inline
672  {
673  static_cast<const Derived*>(this)->template evalProduct<Unaligned>(buffer);
674  }

Referenced by Eigen::TensorContractionEvaluatorBase< Derived >::evalSubExprsIfNeeded().

◆ packet()

template<typename Derived >
template<int LoadMode>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType Eigen::TensorContractionEvaluatorBase< Derived >::packet ( Index  index) const
inline
879  {
880  return internal::ploadt<PacketReturnType, LoadMode>(m_result + index);
881  }

References Eigen::TensorContractionEvaluatorBase< Derived >::m_result.

Member Data Documentation

◆ ContractDims

template<typename Derived >
constexpr int Eigen::TensorContractionEvaluatorBase< Derived >::ContractDims = internal::array_size<Indices>::value
staticconstexpr

◆ Layout

template<typename Derived >
constexpr int Eigen::TensorContractionEvaluatorBase< Derived >::Layout = TensorEvaluator<LeftArgType, Device>::Layout
staticconstexpr

◆ LDims

template<typename Derived >
constexpr int Eigen::TensorContractionEvaluatorBase< Derived >::LDims
staticconstexpr
Initial value:
=
internal::array_size<typename TensorEvaluator<EvalLeftArgType, Device>::Dimensions>::value
squared absolute value
Definition: GlobalFunctions.h:87

Referenced by Eigen::TensorContractionEvaluatorBase< Derived >::TensorContractionEvaluatorBase().

◆ m_device

◆ m_dimensions

◆ m_i_size

◆ m_i_strides

◆ m_j_size

◆ m_j_strides

◆ m_k_size

◆ m_k_strides

◆ m_left_contracting_strides

◆ m_left_nocontract_strides

◆ m_leftImpl

◆ m_lhs_inner_dim_contiguous

template<typename Derived >
bool Eigen::TensorContractionEvaluatorBase< Derived >::m_lhs_inner_dim_contiguous
protected

◆ m_output_kernel

◆ m_result

◆ m_rhs_inner_dim_contiguous

template<typename Derived >
bool Eigen::TensorContractionEvaluatorBase< Derived >::m_rhs_inner_dim_contiguous
protected

◆ m_rhs_inner_dim_reordered

template<typename Derived >
bool Eigen::TensorContractionEvaluatorBase< Derived >::m_rhs_inner_dim_reordered
protected

◆ m_right_contracting_strides

◆ m_right_nocontract_strides

◆ m_rightImpl

◆ m_tensor_contraction_params

◆ NumDims

template<typename Derived >
constexpr int Eigen::TensorContractionEvaluatorBase< Derived >::NumDims = LDims + RDims - 2 * ContractDims
staticconstexpr

◆ RDims

template<typename Derived >
constexpr int Eigen::TensorContractionEvaluatorBase< Derived >::RDims
staticconstexpr
Initial value:
=
internal::array_size<typename TensorEvaluator<EvalRightArgType, Device>::Dimensions>::value

Referenced by Eigen::TensorContractionEvaluatorBase< Derived >::TensorContractionEvaluatorBase().


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