ArmNN
 24.02
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 4173 of file WorkloadData.cpp.

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

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: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: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: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:505
armnn::DataLayout::NCHW
@ NCHW