ArmNN
 24.05
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 4175 of file WorkloadData.cpp.

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

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