ArmNN
 24.02
SpaceToBatchNdQueueDescriptor Struct Reference

#include <WorkloadData.hpp>

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

Public Member Functions

void Validate (const WorkloadInfo &workloadInfo) const
 
- Public Member Functions inherited from QueueDescriptorWithParameters< SpaceToBatchNdDescriptor >
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< SpaceToBatchNdDescriptor >
SpaceToBatchNdDescriptor 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< SpaceToBatchNdDescriptor >
 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 385 of file WorkloadData.hpp.

Member Function Documentation

◆ Validate()

void Validate ( const WorkloadInfo workloadInfo) const

Definition at line 1848 of file WorkloadData.cpp.

1849 {
1850  const std::string descriptorName{"SpaceToBatchNdQueueDescriptor"};
1851 
1852  ValidateNumInputs(workloadInfo, descriptorName, 1);
1853  ValidateNumOutputs(workloadInfo, descriptorName, 1);
1854 
1855  const TensorInfo& inputTensorInfo = workloadInfo.m_InputTensorInfos[0];
1856  const TensorInfo& outputTensorInfo = workloadInfo.m_OutputTensorInfos[0];
1857 
1858  if (m_Parameters.m_BlockShape.size() != m_Parameters.m_PadList.size())
1859  {
1860  throw InvalidArgumentException(descriptorName + ": Pad List must contain the same number of "
1861  "dimensions as Block Shape.");
1862  }
1863 
1864  if (m_Parameters.m_BlockShape.size() == 2)
1865  {
1866  ValidateTensorNumDimensions(inputTensorInfo, descriptorName, 4, "input");
1867  ValidateTensorNumDimensions(outputTensorInfo, descriptorName, 4, "output");
1868  }
1869  else if (m_Parameters.m_BlockShape.size() == 1)
1870  {
1871  ValidateTensorNumDimensions(inputTensorInfo, descriptorName, 3, "input");
1872  ValidateTensorNumDimensions(outputTensorInfo, descriptorName, 3, "output");
1873  }
1874  else
1875  {
1876  throw InvalidArgumentException(descriptorName + ": Invalid Block and Crops size.");
1877  }
1878 
1879  // Check input + padding and output have the same number of elements
1880  DataLayoutIndexed dimensionIndices(m_Parameters.m_DataLayout);
1881  const unsigned int inputHeight = inputTensorInfo.GetShape()[dimensionIndices.GetHeightIndex()] +
1882  m_Parameters.m_PadList[0].first + m_Parameters.m_PadList[0].second;
1883  const unsigned int inputWidth = (inputTensorInfo.GetNumDimensions() == 3) ? 1 :
1884  inputTensorInfo.GetShape()[dimensionIndices.GetWidthIndex()] +
1885  m_Parameters.m_PadList[1].first + m_Parameters.m_PadList[1].second;
1886 
1887  const int channelsIndex_int = (m_Parameters.m_DataLayout == DataLayout::NCHW) ? 1 : -1;
1888  const unsigned int channelsIndex = channelsIndex_int < 0 ?
1889  static_cast<unsigned int>(channelsIndex_int) + inputTensorInfo.GetNumDimensions()
1890  : static_cast<unsigned int>(channelsIndex_int);
1891 
1892  const unsigned int numInputElements = inputTensorInfo.GetShape()[0] *
1893  inputHeight *
1894  inputWidth *
1895  inputTensorInfo.GetShape()[channelsIndex];
1896 
1897  if (outputTensorInfo.GetNumElements() != numInputElements)
1898  {
1899  throw InvalidArgumentException(descriptorName + ": Input tensor has " +
1900  to_string(numInputElements) + " after padding but output tensor has " +
1901  to_string(outputTensorInfo.GetNumElements()) + " elements.");
1902  }
1903 
1904  // In a 4D tensor, there will be 2 spatialDimensions (H and W), and the for loop will run twice.
1905  // In a 3D tensor, there will be 1 spatialDimensions, and the for loop will run once.
1906  unsigned int firstSpatialDimension = m_Parameters.m_DataLayout == DataLayout::NCHW ? 2 : 1;
1907  for (unsigned int i = 0; i < m_Parameters.m_BlockShape.size(); ++i)
1908  {
1909  unsigned int spatialDimension = firstSpatialDimension + i;
1910  auto inputSize = inputTensorInfo.GetShape()[spatialDimension] +
1911  m_Parameters.m_PadList[i].first +
1912  m_Parameters.m_PadList[i].second;
1913  if (inputSize % m_Parameters.m_BlockShape[i] != 0)
1914  {
1915  throw InvalidArgumentException(descriptorName + ": Input dimension size after padding must be "
1916  "divisible by Block Shape in dimension: " + to_string(spatialDimension) + ".");
1917  }
1918  }
1919 
1920  std::vector<DataType> supportedTypes =
1921  {
1928  };
1929 
1930  ValidateDataTypes(inputTensorInfo, supportedTypes, descriptorName);
1931  ValidateTensorDataTypesMatch(inputTensorInfo, outputTensorInfo, descriptorName, "input", "output");
1932 }

References armnn::BFloat16, armnn::Float16, armnn::Float32, DataLayoutIndexed::GetHeightIndex(), TensorInfo::GetNumDimensions(), TensorInfo::GetNumElements(), TensorInfo::GetShape(), DataLayoutIndexed::GetWidthIndex(), SpaceToBatchNdDescriptor::m_BlockShape, SpaceToBatchNdDescriptor::m_DataLayout, WorkloadInfo::m_InputTensorInfos, WorkloadInfo::m_OutputTensorInfos, SpaceToBatchNdDescriptor::m_PadList, QueueDescriptorWithParameters< SpaceToBatchNdDescriptor >::m_Parameters, armnn::NCHW, armnn::QAsymmS8, armnn::QAsymmU8, armnn::QSymmS16, and QueueDescriptor::ValidateTensorNumDimensions().


The documentation for this struct was generated from the following files:
armnn::TensorInfo::GetNumElements
unsigned int GetNumElements() const
Definition: Tensor.hpp:198
armnn::SpaceToBatchNdDescriptor::m_DataLayout
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
Definition: Descriptors.hpp:1071
armnn::TensorInfo
Definition: Tensor.hpp:152
armnn::TensorInfo::GetNumDimensions
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:197
armnnUtils::DataLayoutIndexed
Provides access to the appropriate indexes for Channels, Height and Width based on DataLayout.
Definition: DataLayoutIndexed.hpp:17
armnn::DataType::Float32
@ Float32
armnn::SpaceToBatchNdDescriptor::m_BlockShape
std::vector< unsigned int > m_BlockShape
Block shape value.
Definition: Descriptors.hpp:1066
armnn::DataType::QAsymmU8
@ QAsymmU8
armnn::DataType::QSymmS16
@ QSymmS16
armnn::DataType::BFloat16
@ BFloat16
armnn::SpaceToBatchNdDescriptor::m_PadList
std::vector< std::pair< unsigned int, unsigned int > > m_PadList
Specifies the padding values for the input dimension: heightPad{top, bottom} widthPad{left,...
Definition: Descriptors.hpp:1069
armnn::DataType::Float16
@ Float16
armnn::WorkloadInfo::m_OutputTensorInfos
std::vector< TensorInfo > m_OutputTensorInfos
Definition: WorkloadInfo.hpp:19
armnn::QueueDescriptorWithParameters< SpaceToBatchNdDescriptor >::m_Parameters
SpaceToBatchNdDescriptor m_Parameters
Definition: WorkloadData.hpp:66
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::QueueDescriptor::ValidateTensorNumDimensions
void ValidateTensorNumDimensions(const TensorInfo &tensor, std::string const &descName, unsigned int numDimensions, std::string const &tensorName) const
Definition: WorkloadData.cpp:397
armnn::DataLayout::NCHW
@ NCHW