ArmNN
 24.08
BatchMatMulQueueDescriptor Struct Reference

#include <WorkloadData.hpp>

Inheritance diagram for BatchMatMulQueueDescriptor:
[legend]
Collaboration diagram for BatchMatMulQueueDescriptor:
[legend]

Public Member Functions

void Validate (const WorkloadInfo &workloadInfo) const
 
- Public Member Functions inherited from QueueDescriptorWithParameters< BatchMatMulDescriptor >
virtual ~QueueDescriptorWithParameters ()=default
 
- Public Member Functions inherited from QueueDescriptor
virtual ~QueueDescriptor ()=default
 
void ValidateTensorNumDimensions (const TensorInfo &tensor, std::string const &descName, unsigned int numDimensions, std::string const &tensorName) const
 
void ValidateTensorNumDimNumElem (const TensorInfo &tensorInfo, unsigned int numDimension, unsigned int numElements, std::string const &tensorName) const
 
void ValidateInputsOutputs (const std::string &descName, unsigned int numExpectedIn, unsigned int numExpectedOut) const
 
template<typename T >
const T * GetAdditionalInformation () const
 

Additional Inherited Members

- Public Attributes inherited from QueueDescriptorWithParameters< BatchMatMulDescriptor >
BatchMatMulDescriptor m_Parameters
 
- Public Attributes inherited from QueueDescriptor
std::vector< ITensorHandle * > m_Inputs
 
std::vector< ITensorHandle * > m_Outputs
 
void * m_AdditionalInfoObject
 
bool m_AllowExpandedDims = false
 
- Protected Member Functions inherited from QueueDescriptorWithParameters< BatchMatMulDescriptor >
 QueueDescriptorWithParameters ()=default
 
 QueueDescriptorWithParameters (QueueDescriptorWithParameters const &)=default
 
QueueDescriptorWithParametersoperator= (QueueDescriptorWithParameters const &)=default
 
- Protected Member Functions inherited from QueueDescriptor
 QueueDescriptor ()
 
 QueueDescriptor (QueueDescriptor const &)=default
 
QueueDescriptoroperator= (QueueDescriptor const &)=default
 

Detailed Description

Definition at line 753 of file WorkloadData.hpp.

Member Function Documentation

◆ Validate()

void Validate ( const WorkloadInfo workloadInfo) const

Definition at line 4177 of file WorkloadData.cpp.

4178 {
4179  const std::string descriptorName{"BatchMatMulDescriptor"};
4180 
4181  ValidateNumInputs(workloadInfo, descriptorName, 2);
4182  ValidateNumOutputs(workloadInfo, descriptorName, 1);
4183 
4184  // Inputs must be: both 2D+
4185  // For inputs X and Y whose dimensions to be multiplied are (M,N) and (I,J) respectively,
4186  // axes N and I must be the same size
4187 
4188  const auto& inputXInfoBeforeParams = workloadInfo.m_InputTensorInfos[0];
4189  const auto& inputYInfoBeforeParams = workloadInfo.m_InputTensorInfos[1];
4190  const auto& outputInfo = workloadInfo.m_OutputTensorInfos[0];
4191  // Output info has already been inferred
4192 
4193  std::vector<DataType> supportedTypes =
4194  {
4201  };
4202 
4203  ValidateDataTypes(inputXInfoBeforeParams, supportedTypes, descriptorName);
4204  ValidateDataTypes(inputYInfoBeforeParams, supportedTypes, descriptorName);
4205  ValidateDataTypes(outputInfo, supportedTypes, descriptorName);
4206 
4207  if ((inputXInfoBeforeParams.GetNumDimensions() < 2) ||
4208  (inputYInfoBeforeParams.GetNumDimensions() < 2))
4209  {
4210  throw InvalidArgumentException(descriptorName + ": Input tensors are not 2D or greater.");
4211  }
4212 
4213  TensorInfo inputXInfoAfterParams;
4214  TensorInfo inputYInfoAfterParams;
4215 
4218  {
4219  throw InvalidArgumentException(descriptorName +
4220  ": Invalid descriptor parameters - Transpose and Adjoint "
4221  "cannot both be true for a given input tensor.");
4222  }
4224  {
4225  inputXInfoAfterParams = armnnUtils::Permuted(inputXInfoBeforeParams,
4228  inputXInfoBeforeParams.GetShape()));
4229  }
4230  else if(m_Parameters.m_AdjointX)
4231  {
4233  inputXInfoBeforeParams.GetShape());
4234  if(inputXInfoBeforeParams.GetShape()[axesToMul.first] !=
4235  inputXInfoBeforeParams.GetShape()[axesToMul.second])
4236  {
4237  throw InvalidArgumentException(descriptorName +
4238  ": Adjoint is set to true for input tensor X, but the axes to be adjointed are not square." );
4239  }
4240  // Shape remains the same as it's square
4241  inputXInfoAfterParams = inputXInfoBeforeParams;
4242  }
4243  else
4244  {
4245  inputXInfoAfterParams = inputXInfoBeforeParams;
4246  }
4247 
4249  {
4250  inputYInfoAfterParams = armnnUtils::Permuted(inputYInfoBeforeParams,
4253  inputYInfoBeforeParams.GetShape()));
4254  }
4255  else if(m_Parameters.m_AdjointY)
4256  {
4258  inputYInfoBeforeParams.GetShape());
4259  if(inputYInfoBeforeParams.GetShape()[axesToMul.first] !=
4260  inputYInfoBeforeParams.GetShape()[axesToMul.second])
4261  {
4262  throw InvalidArgumentException(descriptorName +
4263  ": Adjoint is set to true for input tensor Y, but the axes to be adjointed are not square." );
4264  }
4265  // Shape remains the same as it's square
4266  inputYInfoAfterParams = inputYInfoBeforeParams;
4267  }
4268  else
4269  {
4270  inputYInfoAfterParams = inputYInfoBeforeParams;
4271  }
4272 
4273  switch(m_Parameters.m_DataLayoutX)
4274  {
4275  case DataLayout::NCDHW:
4276  case DataLayout::NDHWC:
4277  if(inputXInfoAfterParams.GetNumDimensions() < 3)
4278  {
4279  throw InvalidArgumentException(descriptorName +
4280  ": Input tensor X does not have the correct "
4281  "number of dimensions for the Data Layout that it has been assigned.");
4282  }
4283  break;
4284  case DataLayout::NCHW:
4285  case DataLayout::NHWC:
4286  default:
4287  break;
4288  }
4289 
4290  switch(m_Parameters.m_DataLayoutY)
4291  {
4292  case DataLayout::NCDHW:
4293  case DataLayout::NDHWC:
4294  if(inputYInfoAfterParams.GetNumDimensions() < 3)
4295  {
4296  throw InvalidArgumentException(descriptorName +
4297  ": Input tensor Y does not have the correct "
4298  "number of dimensions for the Data Layout that it has been assigned.");
4299  }
4300  break;
4301  case DataLayout::NCHW:
4302  case DataLayout::NHWC:
4303  default:
4304  break;
4305  }
4306 
4308  inputXInfoAfterParams.GetShape());
4310  inputYInfoBeforeParams.GetShape());
4311 
4312  if(inputXInfoAfterParams.GetShape()[axesXToMul.second]
4313  != inputYInfoAfterParams.GetShape()[axesYToMul.first])
4314  {
4315  throw InvalidArgumentException(descriptorName +
4316  ": The final axis of input tensor X must be the same size as "
4317  "the second last axis of input tensor Y.");
4318  }
4319 
4320  { // Separate scope so we don't pollute the rest of the scope with our temp variables
4321  // e.g. NHWC isnt compatible with NCHW as of now
4324 
4325  if(xLayout == DataLayout::NCHW || xLayout == DataLayout::NCDHW)
4326  {
4327  if(yLayout == DataLayout::NHWC || yLayout == DataLayout::NDHWC)
4328  {
4329  throw InvalidArgumentException(descriptorName +
4330  ": Invalid input tensor data layout combination.");
4331  }
4332  }
4333  if(yLayout == DataLayout::NCHW || yLayout == DataLayout::NCDHW)
4334  {
4335  if(xLayout == DataLayout::NHWC || xLayout == DataLayout::NDHWC)
4336  {
4337  throw InvalidArgumentException(descriptorName +
4338  ": Invalid input tensor data layout combination.");
4339  }
4340  }
4341  }
4342 
4343  // Simulate aligning the ends of the matrix dims and prepending 1's to the beginning of the shorter one
4344  unsigned int outputTensorDimSize = std::max(inputXInfoAfterParams.GetNumDimensions(),
4345  inputYInfoAfterParams.GetNumDimensions());
4346  if(outputTensorDimSize-2 > 0)
4347  {
4348  TensorInfo tiXNotMul = TensorInfo(TensorShape(outputTensorDimSize-2),
4350  TensorInfo tiYNotMul = TensorInfo(TensorShape(outputTensorDimSize-2),
4352  TensorInfo tiOutNotMul = TensorInfo(TensorShape(outputTensorDimSize-2),
4354 
4355  auto doAxisExtension = [&](std::vector<unsigned int> axisIndices, TensorInfo& ti)
4356  {
4357  auto sizeDiff = (outputTensorDimSize-2) - axisIndices.size();
4358 
4359  for(unsigned int i = 0; i < sizeDiff; i++)
4360  {
4361  axisIndices.insert(axisIndices.begin(), 1);
4362  }
4363 
4364  for(unsigned int i = 0; i < ti.GetNumDimensions(); i++)
4365  {
4366  ti.GetShape()[i] = inputXInfoAfterParams.GetShape()[i];
4367  }
4368  };
4369 
4371  inputXInfoAfterParams.GetShape());
4373  inputYInfoAfterParams.GetShape());
4374 
4375  doAxisExtension(axesXNotMul, tiXNotMul);
4376  doAxisExtension(axesYNotMul, tiYNotMul);
4377 
4378  for(unsigned int i = 0; i < tiOutNotMul.GetNumDimensions(); i++)
4379  {
4380  tiOutNotMul.GetShape()[i] = std::max(tiXNotMul.GetShape()[i],
4381  tiYNotMul.GetShape()[i]);
4382  }
4383 
4384  ValidateBroadcastTensorShapesMatch(tiXNotMul,
4385  tiYNotMul,
4386  tiOutNotMul,
4387  descriptorName,
4388  "input_X",
4389  "input_Y");
4390  }
4391 }

References armnn::BFloat16, armnn::Float16, armnn::Float32, BatchMatMulDescriptor::GetAxesNotMul(), BatchMatMulDescriptor::GetAxesToMul(), TensorInfo::GetNumDimensions(), BatchMatMulDescriptor::GetPermuteVec(), TensorInfo::GetShape(), BatchMatMulDescriptor::m_AdjointX, BatchMatMulDescriptor::m_AdjointY, BatchMatMulDescriptor::m_DataLayoutX, BatchMatMulDescriptor::m_DataLayoutY, WorkloadInfo::m_InputTensorInfos, WorkloadInfo::m_OutputTensorInfos, QueueDescriptorWithParameters< BatchMatMulDescriptor >::m_Parameters, BatchMatMulDescriptor::m_TransposeX, BatchMatMulDescriptor::m_TransposeY, armnn::NCDHW, armnn::NCHW, armnn::NDHWC, armnn::NHWC, armnnUtils::Permuted(), armnn::QAsymmS8, armnn::QAsymmU8, and armnn::QSymmS16.


The documentation for this struct was generated from the following files:
armnn::BatchMatMulDescriptor::m_TransposeX
bool m_TransposeX
Transpose the slices of each input tensor Transpose and Adjoint can not both be set to true for the s...
Definition: Descriptors.hpp:1612
armnn::DataLayout::NCDHW
@ NCDHW
armnn::DataLayout
DataLayout
Definition: Types.hpp:62
armnn::BatchMatMulDescriptor::m_AdjointX
bool m_AdjointX
Adjoint the slices of each input tensor Transpose and Adjoint can not both be set to true for the sam...
Definition: Descriptors.hpp:1617
armnn::DataLayout::NHWC
@ NHWC
armnn::BatchMatMulDescriptor::GetAxesToMul
static std::pair< unsigned int, unsigned int > GetAxesToMul(DataLayout dataLayout, const TensorShape &tensorShape)
Static helper to get the two axes (for each input) for multiplication.
Definition: Descriptors.cpp:485
armnn::BatchMatMulDescriptor::m_DataLayoutX
DataLayout m_DataLayoutX
Data layout of each input tensor, such as NHWC/NDHWC (leave as default for arbitrary layout)
Definition: Descriptors.hpp:1621
armnn::TensorInfo
Definition: Tensor.hpp:152
armnn::TensorInfo::GetNumDimensions
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:197
armnn::DataType::Float32
@ Float32
armnn::BatchMatMulDescriptor::GetPermuteVec
static PermutationVector GetPermuteVec(DataLayout dataLayout, const TensorShape &tensorShape)
Static helper to get the axes which will be transposed.
Definition: Descriptors.cpp:523
armnn::BatchMatMulDescriptor::m_AdjointY
bool m_AdjointY
Definition: Descriptors.hpp:1618
armnn::DataType::QAsymmU8
@ QAsymmU8
armnnUtils::Permuted
armnn::TensorShape Permuted(const armnn::TensorShape &srcShape, const armnn::PermutationVector &mappings)
Definition: Permute.cpp:125
armnn::DataType::QSymmS16
@ QSymmS16
armnn::DataType::BFloat16
@ BFloat16
armnn::DataLayout::NDHWC
@ NDHWC
armnn::TensorShape
Definition: Tensor.hpp:20
armnn::DataType::Float16
@ Float16
armnn::WorkloadInfo::m_OutputTensorInfos
std::vector< TensorInfo > m_OutputTensorInfos
Definition: WorkloadInfo.hpp:19
armnn::QueueDescriptorWithParameters< BatchMatMulDescriptor >::m_Parameters
BatchMatMulDescriptor m_Parameters
Definition: WorkloadData.hpp:66
armnn::BatchMatMulDescriptor::m_TransposeY
bool m_TransposeY
Definition: Descriptors.hpp:1613
armnn::BatchMatMulDescriptor::m_DataLayoutY
DataLayout m_DataLayoutY
Definition: Descriptors.hpp:1622
armnn::InvalidArgumentException
Definition: Exceptions.hpp:80
armnn::DataType::QAsymmS8
@ QAsymmS8
armnn::TensorInfo::GetShape
const TensorShape & GetShape() const
Definition: Tensor.hpp:193
armnn::WorkloadInfo::m_InputTensorInfos
std::vector< TensorInfo > m_InputTensorInfos
Definition: WorkloadInfo.hpp:18
armnn::BatchMatMulDescriptor::GetAxesNotMul
static std::vector< unsigned int > GetAxesNotMul(DataLayout dataLayout, const TensorShape &tensorShape)
Static helper to get the axes (for each input) that will not be multiplied together.
Definition: Descriptors.cpp:506
armnn::DataLayout::NCHW
@ NCHW