ArmNN
 24.08
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 1851 of file WorkloadData.cpp.

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

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