ArmNN
 22.08
BatchMatMulDescriptor Struct Reference

A BatchMatMulDescriptor for the BatchMatMul operator. More...

#include <Descriptors.hpp>

Inheritance diagram for BatchMatMulDescriptor:
BaseDescriptor

Public Member Functions

 BatchMatMulDescriptor (Optional< DataLayout > dataLayoutX=EmptyOptional(), Optional< DataLayout > dataLayoutY=EmptyOptional(), std::vector< unsigned int > transposeX={}, std::vector< unsigned int > transposeY={}, std::vector< unsigned int > adjointX={}, std::vector< unsigned int > adjointY={})
 
bool operator== (const BatchMatMulDescriptor &rhs) const
 
- Public Member Functions inherited from BaseDescriptor
virtual bool IsNull () const
 
virtual ~BaseDescriptor ()=default
 

Static Public Member Functions

static std::pair< std::pair< unsigned int, unsigned int >, std::pair< unsigned int, unsigned int > > GetAxesToMul (const BatchMatMulDescriptor &desc, const TensorShape &tensorXShape, const TensorShape &tensorYShape)
 Static helper to get the two axes (for each input) for multiplication. More...
 
static std::pair< std::vector< unsigned int >, std::vector< unsigned int > > GetAxesNotMul (const BatchMatMulDescriptor &desc, const TensorShape &inputXShape, const TensorShape &inputYShape)
 Static helper to get the axes (for each input) that will not be multiplied together. More...
 

Public Attributes

Optional< DataLayoutm_DataLayoutX
 Data layout of each input tensor, such as NHWC/NDHWC (or leave as EmptyOptional for arbitrary layout) More...
 
Optional< DataLayoutm_DataLayoutY
 
std::vector< unsigned int > m_TransposeX
 Transpose vector for each input tensor (leave as empty vector for no pre-transposing) Transpose and Adjoint can not both be set to true for the same tensor at the same time. More...
 
std::vector< unsigned int > m_TransposeY
 
std::vector< unsigned int > m_AdjointX
 Adjoint vector for each input tensor (leave as empty vector for no pre-adjoint) Transpose and Adjoint can not both be set to true for the same tensor at the same time. More...
 
std::vector< unsigned int > m_AdjointY
 

Detailed Description

A BatchMatMulDescriptor for the BatchMatMul operator.

Definition at line 1554 of file Descriptors.hpp.

Constructor & Destructor Documentation

◆ BatchMatMulDescriptor()

BatchMatMulDescriptor ( Optional< DataLayout dataLayoutX = EmptyOptional(),
Optional< DataLayout dataLayoutY = EmptyOptional(),
std::vector< unsigned int >  transposeX = {},
std::vector< unsigned int >  transposeY = {},
std::vector< unsigned int >  adjointX = {},
std::vector< unsigned int >  adjointY = {} 
)
inline

Definition at line 1556 of file Descriptors.hpp.

1558  {},
1559  std::vector<unsigned int> transposeY = {},
1560  std::vector<unsigned int> adjointX = {},
1561  std::vector<unsigned int> adjointY = {})
1562  : m_DataLayoutX(dataLayoutX)
1563  , m_DataLayoutY(dataLayoutY)
1564  , m_TransposeX(transposeX)
1565  , m_TransposeY(transposeY)
1566  , m_AdjointX(adjointX)
1567  , m_AdjointY(adjointY)
1568  {}
Optional< DataLayout > m_DataLayoutX
Data layout of each input tensor, such as NHWC/NDHWC (or leave as EmptyOptional for arbitrary layout)...
std::vector< unsigned int > m_TransposeX
Transpose vector for each input tensor (leave as empty vector for no pre-transposing) Transpose and A...
std::vector< unsigned int > m_AdjointX
Adjoint vector for each input tensor (leave as empty vector for no pre-adjoint) Transpose and Adjoint...
std::vector< unsigned int > m_TransposeY
std::vector< unsigned int > m_AdjointY
Optional< DataLayout > m_DataLayoutY

Member Function Documentation

◆ GetAxesNotMul()

std::pair< std::vector< unsigned int >, std::vector< unsigned int > > GetAxesNotMul ( const BatchMatMulDescriptor desc,
const TensorShape inputXShape,
const TensorShape inputYShape 
)
static

Static helper to get the axes (for each input) that will not be multiplied together.

Definition at line 508 of file Descriptors.cpp.

References BatchMatMulDescriptor::GetAxesToMul(), and TensorShape::GetNumDimensions().

Referenced by BatchMatMulQueueDescriptor::Validate().

512 {
513  // May refactor to just work on one input per call - makes it less confusing and also
514  // allows more flexibility (i.e. in Layer output shape inference)
515  auto axesToMul = BatchMatMulDescriptor::GetAxesToMul(desc, inputXShape, inputYShape);
516 
517  std::vector<unsigned int> axesXNotMul;
518  std::vector<unsigned int> axesYNotMul;
519 
520  for(unsigned int i = 0; i < inputXShape.GetNumDimensions(); i++)
521  {
522  if(i == axesToMul.first.first || i == axesToMul.first.second)
523  {
524  continue;
525  }
526  axesXNotMul.push_back(i);
527  }
528  for(unsigned int i = 0; i < inputYShape.GetNumDimensions(); i++)
529  {
530  if(i == axesToMul.second.first || i == axesToMul.second.second)
531  {
532  continue;
533  }
534  axesYNotMul.push_back(i);
535  }
536 
537  return { axesXNotMul, axesYNotMul };
538 }
static std::pair< std::pair< unsigned int, unsigned int >, std::pair< unsigned int, unsigned int > > GetAxesToMul(const BatchMatMulDescriptor &desc, const TensorShape &tensorXShape, const TensorShape &tensorYShape)
Static helper to get the two axes (for each input) for multiplication.

◆ GetAxesToMul()

std::pair< std::pair< unsigned int, unsigned int >, std::pair< unsigned int, unsigned int > > GetAxesToMul ( const BatchMatMulDescriptor desc,
const TensorShape tensorXShape,
const TensorShape tensorYShape 
)
static

Static helper to get the two axes (for each input) for multiplication.

Definition at line 459 of file Descriptors.cpp.

References TensorShape::GetNumDimensions(), OptionalBase::has_value(), BatchMatMulDescriptor::m_DataLayoutX, BatchMatMulDescriptor::m_DataLayoutY, armnn::NCDHW, armnn::NCHW, armnn::NDHWC, armnn::NHWC, and OptionalReferenceSwitch< IsReference, T >::value().

Referenced by BatchMatMulDescriptor::GetAxesNotMul(), BatchMatMulLayer::InferOutputShapes(), BatchMatMul::RecurseBMM(), and BatchMatMulQueueDescriptor::Validate().

463 {
464  // May refactor to just work on one input per call - makes it less confusing and also
465  // allows more flexibility (i.e. in Layer output shape inference)
466 
467  auto xNumDims = tensorXShape.GetNumDimensions();
468  auto yNumDims = tensorYShape.GetNumDimensions();
469 
470  std::pair<unsigned int, unsigned int> xAxes = { xNumDims-2, xNumDims-1 };
471  std::pair<unsigned int, unsigned int> yAxes = { yNumDims-2, yNumDims-1 };
472 
473  if(desc.m_DataLayoutX.has_value())
474  {
475  switch(desc.m_DataLayoutX.value())
476  {
477  case DataLayout::NDHWC:
478  case DataLayout::NHWC:
479  xAxes.first -= 1;
480  xAxes.second -= 1;
481  break;
482  case DataLayout::NCDHW:
483  case DataLayout::NCHW:
484  default:
485  break;
486  }
487  }
488 
489  if(desc.m_DataLayoutY.has_value())
490  {
491  switch(desc.m_DataLayoutY.value())
492  {
493  case DataLayout::NDHWC:
494  case DataLayout::NHWC:
495  yAxes.first -= 1;
496  yAxes.second -= 1;
497  break;
498  case DataLayout::NCDHW:
499  case DataLayout::NCHW:
500  default:
501  break;
502  }
503  }
504 
505  return { xAxes, yAxes};
506 }

◆ operator==()

bool operator== ( const BatchMatMulDescriptor rhs) const
inline

Definition at line 1570 of file Descriptors.hpp.

References BatchMatMulDescriptor::m_AdjointX, BatchMatMulDescriptor::m_AdjointY, BatchMatMulDescriptor::m_DataLayoutX, BatchMatMulDescriptor::m_DataLayoutY, BatchMatMulDescriptor::m_TransposeX, and BatchMatMulDescriptor::m_TransposeY.

1571  {
1572  return m_DataLayoutX == rhs.m_DataLayoutX &&
1573  m_DataLayoutY == rhs.m_DataLayoutY &&
1574  m_TransposeX == rhs.m_TransposeX &&
1575  m_TransposeY == rhs.m_TransposeY &&
1576  m_AdjointX == rhs.m_AdjointX &&
1577  m_AdjointY == rhs.m_AdjointY;
1578  }
Optional< DataLayout > m_DataLayoutX
Data layout of each input tensor, such as NHWC/NDHWC (or leave as EmptyOptional for arbitrary layout)...
std::vector< unsigned int > m_TransposeX
Transpose vector for each input tensor (leave as empty vector for no pre-transposing) Transpose and A...
std::vector< unsigned int > m_AdjointX
Adjoint vector for each input tensor (leave as empty vector for no pre-adjoint) Transpose and Adjoint...
std::vector< unsigned int > m_TransposeY
std::vector< unsigned int > m_AdjointY
Optional< DataLayout > m_DataLayoutY

Member Data Documentation

◆ m_AdjointX

std::vector<unsigned int> m_AdjointX

Adjoint vector for each input tensor (leave as empty vector for no pre-adjoint) Transpose and Adjoint can not both be set to true for the same tensor at the same time.

Definition at line 1591 of file Descriptors.hpp.

Referenced by BatchMatMulDescriptor::operator==().

◆ m_AdjointY

std::vector<unsigned int> m_AdjointY

Definition at line 1592 of file Descriptors.hpp.

Referenced by BatchMatMulDescriptor::operator==().

◆ m_DataLayoutX

Optional<DataLayout> m_DataLayoutX

Data layout of each input tensor, such as NHWC/NDHWC (or leave as EmptyOptional for arbitrary layout)

Definition at line 1581 of file Descriptors.hpp.

Referenced by BatchMatMulDescriptor::GetAxesToMul(), and BatchMatMulDescriptor::operator==().

◆ m_DataLayoutY

◆ m_TransposeX

std::vector<unsigned int> m_TransposeX

Transpose vector for each input tensor (leave as empty vector for no pre-transposing) Transpose and Adjoint can not both be set to true for the same tensor at the same time.

Definition at line 1586 of file Descriptors.hpp.

Referenced by BatchMatMulDescriptor::operator==().

◆ m_TransposeY

std::vector<unsigned int> m_TransposeY

Definition at line 1587 of file Descriptors.hpp.

Referenced by BatchMatMulDescriptor::operator==().


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