ArmNN
 23.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 748 of file WorkloadData.hpp.

Member Function Documentation

◆ Validate()

void Validate ( const WorkloadInfo workloadInfo) const

Definition at line 4167 of file WorkloadData.cpp.

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

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:1591
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:1596
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:476
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:1600
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:514
armnn::BatchMatMulDescriptor::m_AdjointY
bool m_AdjointY
Definition: Descriptors.hpp:1597
armnn::DataType::QAsymmU8
@ QAsymmU8
armnnUtils::Permuted
armnn::TensorShape Permuted(const armnn::TensorShape &srcShape, const armnn::PermutationVector &mappings)
Definition: Permute.cpp:98
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:1592
armnn::BatchMatMulDescriptor::m_DataLayoutY
DataLayout m_DataLayoutY
Definition: Descriptors.hpp:1601
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:497
armnn::DataLayout::NCHW
@ NCHW