ArmNN
 23.11
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 4172 of file WorkloadData.cpp.

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

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:484
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:195
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:522
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:191
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:505
armnn::DataLayout::NCHW
@ NCHW