ArmNN
 22.05
LstmQueueDescriptor Struct Reference

#include <WorkloadData.hpp>

Inheritance diagram for LstmQueueDescriptor:
QueueDescriptorWithParameters< LstmDescriptor > QueueDescriptor

Public Member Functions

 LstmQueueDescriptor ()
 
void Validate (const WorkloadInfo &workloadInfo) const
 
- Public Member Functions inherited from QueueDescriptorWithParameters< LstmDescriptor >
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
 

Public Attributes

const ConstTensorHandlem_InputToInputWeights
 
const ConstTensorHandlem_InputToForgetWeights
 
const ConstTensorHandlem_InputToCellWeights
 
const ConstTensorHandlem_InputToOutputWeights
 
const ConstTensorHandlem_RecurrentToInputWeights
 
const ConstTensorHandlem_RecurrentToForgetWeights
 
const ConstTensorHandlem_RecurrentToCellWeights
 
const ConstTensorHandlem_RecurrentToOutputWeights
 
const ConstTensorHandlem_CellToInputWeights
 
const ConstTensorHandlem_CellToForgetWeights
 
const ConstTensorHandlem_CellToOutputWeights
 
const ConstTensorHandlem_InputGateBias
 
const ConstTensorHandlem_ForgetGateBias
 
const ConstTensorHandlem_CellBias
 
const ConstTensorHandlem_OutputGateBias
 
const ConstTensorHandlem_ProjectionWeights
 
const ConstTensorHandlem_ProjectionBias
 
const ConstTensorHandlem_InputLayerNormWeights
 
const ConstTensorHandlem_ForgetLayerNormWeights
 
const ConstTensorHandlem_CellLayerNormWeights
 
const ConstTensorHandlem_OutputLayerNormWeights
 
- Public Attributes inherited from QueueDescriptorWithParameters< LstmDescriptor >
LstmDescriptor m_Parameters
 
- Public Attributes inherited from QueueDescriptor
std::vector< ITensorHandle * > m_Inputs
 
std::vector< ITensorHandle * > m_Outputs
 
void * m_AdditionalInfoObject
 
bool m_AllowExpandedDims = false
 

Additional Inherited Members

- Protected Member Functions inherited from QueueDescriptorWithParameters< LstmDescriptor >
 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 432 of file WorkloadData.hpp.

Constructor & Destructor Documentation

◆ LstmQueueDescriptor()

LstmQueueDescriptor ( )
inline

Definition at line 434 of file WorkloadData.hpp.

435  : m_InputToInputWeights(nullptr)
436  , m_InputToForgetWeights(nullptr)
437  , m_InputToCellWeights(nullptr)
438  , m_InputToOutputWeights(nullptr)
439  , m_RecurrentToInputWeights(nullptr)
440  , m_RecurrentToForgetWeights(nullptr)
441  , m_RecurrentToCellWeights(nullptr)
442  , m_RecurrentToOutputWeights(nullptr)
443  , m_CellToInputWeights(nullptr)
444  , m_CellToForgetWeights(nullptr)
445  , m_CellToOutputWeights(nullptr)
446  , m_InputGateBias(nullptr)
447  , m_ForgetGateBias(nullptr)
448  , m_CellBias(nullptr)
449  , m_OutputGateBias(nullptr)
450  , m_ProjectionWeights(nullptr)
451  , m_ProjectionBias(nullptr)
452  , m_InputLayerNormWeights(nullptr)
453  , m_ForgetLayerNormWeights(nullptr)
454  , m_CellLayerNormWeights(nullptr)
455  , m_OutputLayerNormWeights(nullptr)
456  {
457  }
const ConstTensorHandle * m_ProjectionWeights
const ConstTensorHandle * m_RecurrentToForgetWeights
const ConstTensorHandle * m_InputGateBias
const ConstTensorHandle * m_RecurrentToCellWeights
const ConstTensorHandle * m_CellBias
const ConstTensorHandle * m_InputToOutputWeights
const ConstTensorHandle * m_OutputLayerNormWeights
const ConstTensorHandle * m_OutputGateBias
const ConstTensorHandle * m_CellLayerNormWeights
const ConstTensorHandle * m_CellToOutputWeights
const ConstTensorHandle * m_InputToCellWeights
const ConstTensorHandle * m_InputToForgetWeights
const ConstTensorHandle * m_RecurrentToInputWeights
const ConstTensorHandle * m_ForgetGateBias
const ConstTensorHandle * m_CellToForgetWeights
const ConstTensorHandle * m_ProjectionBias
const ConstTensorHandle * m_ForgetLayerNormWeights
const ConstTensorHandle * m_InputLayerNormWeights
const ConstTensorHandle * m_CellToInputWeights
const ConstTensorHandle * m_InputToInputWeights
const ConstTensorHandle * m_RecurrentToOutputWeights

Member Function Documentation

◆ Validate()

void Validate ( const WorkloadInfo workloadInfo) const

Definition at line 2002 of file WorkloadData.cpp.

References armnn::BFloat16, armnn::Float16, armnn::Float32, WorkloadInfo::m_InputTensorInfos, WorkloadInfo::m_OutputTensorInfos, armnn::QSymmS16, and QueueDescriptor::ValidateTensorNumDimNumElem().

2003 {
2004  // ported from android/ml/nn/common/operations/LSTM.cpp CheckInputTensorDimensions()
2005 
2006  const std::string descriptorName{"LstmQueueDescriptor"};
2007 
2008  // check dimensions of all inputs and outputs
2009  if (workloadInfo.m_InputTensorInfos.size() != 3)
2010  {
2011  throw InvalidArgumentException(descriptorName + ": Invalid number of inputs.");
2012  }
2013  if (workloadInfo.m_OutputTensorInfos.size() != 4)
2014  {
2015  throw InvalidArgumentException(descriptorName + ": Invalid number of outputs.");
2016  }
2017 
2018  std::vector<DataType> supportedTypes =
2019  {
2024  };
2025 
2026  // check for supported type of one input and match them with all the other input and output
2027  ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], supportedTypes, descriptorName);
2028 
2029  // type matches all other inputs
2030  for (uint32_t i = 1u; i < workloadInfo.m_InputTensorInfos.size(); ++i)
2031  {
2032  ValidateTensorDataTypesMatch(workloadInfo.m_InputTensorInfos[0],
2033  workloadInfo.m_InputTensorInfos[i],
2034  descriptorName,
2035  "input_0",
2036  "input_" + std::to_string(i));
2037  }
2038  // type matches all other outputs
2039  for (uint32_t i = 0u; i < workloadInfo.m_OutputTensorInfos.size(); ++i)
2040  {
2041  ValidateTensorDataTypesMatch(workloadInfo.m_InputTensorInfos[0],
2042  workloadInfo.m_OutputTensorInfos[i],
2043  "LstmQueueDescriptor",
2044  "input_0",
2045  "output_" + std::to_string(i));
2046  }
2047 
2048  // Making sure clipping parameters have valid values.
2049  // == 0 means no clipping
2050  // > 0 means clipping
2051  if (m_Parameters.m_ClippingThresCell < 0.0f)
2052  {
2053  throw InvalidArgumentException(descriptorName + ": negative cell clipping threshold is invalid");
2054  }
2055  if (m_Parameters.m_ClippingThresProj < 0.0f)
2056  {
2057  throw InvalidArgumentException(descriptorName + ": negative projection clipping threshold is invalid");
2058  }
2059 
2060  // Inferring batch size, number of outputs and number of cells from the inputs.
2061  const uint32_t n_input = workloadInfo.m_InputTensorInfos[0].GetShape()[1];
2062  const uint32_t n_batch = workloadInfo.m_InputTensorInfos[0].GetShape()[0];
2063  ValidatePointer(m_InputToOutputWeights, "Null pointer check", "InputToOutputWeights");
2064  const uint32_t n_cell = m_InputToOutputWeights->GetShape()[0];
2065  ValidatePointer(m_RecurrentToOutputWeights, "Null pointer check", "RecurrentToOutputWeights");
2066  const uint32_t n_output = m_RecurrentToOutputWeights->GetShape()[1];
2067 
2068  // input tensor
2069  ValidateTensorNumDimNumElem(workloadInfo.m_InputTensorInfos[0], 2, (n_batch * n_input),
2070  descriptorName + " input_0");
2071  // outputStateInTensor
2072  ValidateTensorNumDimNumElem(workloadInfo.m_InputTensorInfos[1], 2, (n_batch * n_output),
2073  descriptorName + " input_1");
2074  // outputStateInTensor
2075  ValidateTensorNumDimNumElem(workloadInfo.m_InputTensorInfos[2], 2, (n_batch * n_cell),
2076  descriptorName + " input_2");
2077  // scratchBufferTensor
2078  unsigned int scratchBufferSize = m_Parameters.m_CifgEnabled ? n_cell * 3 : n_cell * 4;
2079  ValidateTensorNumDimNumElem(workloadInfo.m_OutputTensorInfos[0], 2, (n_batch * scratchBufferSize),
2080  descriptorName + " output_0");
2081  // outputStateOutTensor
2082  ValidateTensorNumDimNumElem(workloadInfo.m_OutputTensorInfos[1], 2, (n_batch * n_output),
2083  descriptorName + " output_1");
2084  // cellStateOutTensor
2085  ValidateTensorNumDimNumElem(workloadInfo.m_OutputTensorInfos[2], 2, (n_batch * n_cell),
2086  descriptorName + " output_2");
2087  // outputTensor
2088  ValidateTensorNumDimNumElem(workloadInfo.m_OutputTensorInfos[3], 2, (n_batch * n_output),
2089  descriptorName + " output_3");
2090 
2091  // check that dimensions of inputs/outputs and QueueDescriptor data match with each other
2092  if ( m_InputToInputWeights )
2093  {
2095  (n_cell * n_input), "InputLayerNormWeights");
2096  }
2097 
2098  ValidatePointer(m_InputToForgetWeights, "Null pointer check", "InputToForgetWeights");
2100  (n_cell * n_input), "InputToForgetWeights");
2101 
2102  ValidatePointer(m_InputToCellWeights, "Null pointer check", "InputToCellWeights");
2104  (n_cell * n_input), "InputToCellWeights");
2105 
2107  {
2109  (n_cell * n_output), "RecurrentToInputWeights");
2110  }
2111 
2112  ValidatePointer(m_RecurrentToForgetWeights, "Null pointer check", "RecurrentToForgetWeights");
2114  (n_cell * n_output), "RecurrentToForgetWeights");
2115 
2116  ValidatePointer(m_RecurrentToCellWeights, "Null pointer check", "RecurrentToCellWeights");
2118  (n_cell * n_output), "RecurrentToCellWeights");
2119 
2120  // Make sure the input-gate's parameters are either both present (regular
2121  // LSTM) or not at all (CIFG-LSTM). And CifgEnable is set accordingly.
2122  bool cifg_weights_all_or_none = ((m_InputToInputWeights && m_RecurrentToInputWeights &&
2126  if (!cifg_weights_all_or_none)
2127  {
2128  throw InvalidArgumentException(descriptorName + ": Input-Gate's parameters InputToInputWeights and "
2129  "RecurrentToInputWeights must either both be present (regular LSTM) "
2130  "or both not present (CIFG-LSTM). In addition CifgEnable must be set "
2131  "accordingly.");
2132  }
2133 
2134  if ( m_CellToInputWeights )
2135  {
2137  n_cell, "CellToInputWeights");
2138  }
2139  if ( m_CellToForgetWeights )
2140  {
2142  n_cell, "CellToForgetWeights");
2143  }
2144  if ( m_CellToOutputWeights )
2145  {
2147  n_cell, "CellToOutputWeights");
2148  }
2149 
2150  // Making sure the peephole weights are there all or none. And PeepholeEnable is set accordingly.
2151  bool peephole_weights_all_or_none =
2156  if (!peephole_weights_all_or_none)
2157  {
2158  throw InvalidArgumentException(descriptorName + ": Invalid combination of peephole parameters.");
2159  }
2160 
2161  // Make sure the input gate bias is present only when not a CIFG-LSTM.
2163  {
2164  if (m_InputGateBias)
2165  {
2166  throw InvalidArgumentException(descriptorName + ": InputGateBias is present and CIFG-LSTM is enabled.");
2167  }
2168  }
2169  else
2170  {
2171  if (!m_InputGateBias)
2172  {
2173  throw InvalidArgumentException(descriptorName + ": If CIFG-LSTM is disabled InputGateBias "
2174  "must be present.");
2175  }
2177  n_cell, "InputGateBias");
2178  }
2179 
2180  ValidatePointer(m_ForgetGateBias, "Null pointer check", "ForgetGateBias");
2181  ValidateTensorNumDimNumElem(m_ForgetGateBias->GetTensorInfo(), 1, n_cell, "ForgetGateBias");
2182 
2183  ValidatePointer(m_CellBias, "Null pointer check", "CellBias");
2184  ValidateTensorNumDimNumElem(m_CellBias->GetTensorInfo(), 1, n_cell, "CellBias");
2185 
2186  ValidatePointer(m_OutputGateBias, "Null pointer check", "OutputGateBias");
2187  ValidateTensorNumDimNumElem(m_OutputGateBias->GetTensorInfo(), 1, n_cell, "OutputGateBias");
2188 
2189  if (m_ProjectionWeights)
2190  {
2192  (n_cell * n_output), "ProjectionWeights");
2193  }
2194  if (m_ProjectionBias)
2195  {
2196  ValidateTensorNumDimNumElem(m_ProjectionBias->GetTensorInfo(), 1, n_output, "ProjectionBias");
2197  }
2198 
2199  // Making sure the projection tensors are consistent:
2200  // 1) If projection weight is not present, then projection bias should not be
2201  // present.
2202  // 2) If projection weight is present, then projection bias is optional.
2203  bool projecton_tensors_consistent = ((!m_ProjectionWeights && !m_ProjectionBias &&
2209  if (!projecton_tensors_consistent)
2210  {
2211  throw InvalidArgumentException(descriptorName + ": Projection tensors are inconsistent.");
2212  }
2213 
2214  // The four layer normalization weights either all have values or none of them have values. Additionally, if
2215  // CIFG is used, input layer normalization weights tensor is omitted and the other layer normalization weights
2216  // either all have values or none of them have values. Layer normalization is used when the values of all the
2217  // layer normalization weights are present
2219  {
2220  ValidateTensorNumDimNumElem(m_InputLayerNormWeights->GetTensorInfo(), 1, n_cell, "InputLayerNormWeights");
2221  }
2223  {
2224  ValidateTensorNumDimNumElem(m_ForgetLayerNormWeights->GetTensorInfo(), 1, n_cell, "ForgetLayerNormWeights");
2225  }
2227  {
2228  ValidateTensorNumDimNumElem(m_CellLayerNormWeights->GetTensorInfo(), 1, n_cell, "CellLayerNormWeights");
2229  }
2231  {
2232  ValidateTensorNumDimNumElem(m_OutputLayerNormWeights->GetTensorInfo(), 1, n_cell, "OutputLayerNormWeights");
2233  }
2234 
2236  {
2238  {
2240  {
2241  throw InvalidArgumentException(descriptorName + ": Layer normalisation is enabled and CIFG-LSTM is "
2242  "disabled but InputLayerNormWeights are not present");
2243  }
2245  1, n_cell, "InputLayerNormWeights");
2246  }
2247  else if (m_InputLayerNormWeights)
2248  {
2249  throw InvalidArgumentException(descriptorName + ":InputLayerNormWeights are present while CIFG is "
2250  "enabled");
2251  }
2252 
2253  ValidatePointer(m_ForgetLayerNormWeights, "Null pointer check layer normalisation enabled",
2254  "ForgetLayerNormWeights");
2255  ValidateTensorNumDimNumElem(m_ForgetLayerNormWeights->GetTensorInfo(), 1, n_cell, "ForgetLayerNormWeights");
2256 
2257  ValidatePointer(m_OutputLayerNormWeights, "Null pointer check layer normalisation enabled",
2258  "OutputLayerNormWeights");
2259  ValidateTensorNumDimNumElem(m_OutputLayerNormWeights->GetTensorInfo(), 1, n_cell, "OutputLayerNormWeights");
2260 
2261  ValidatePointer(m_CellLayerNormWeights, "Null pointer check layer normalisation enabled",
2262  "CellLayerNormWeights");
2263  ValidateTensorNumDimNumElem(m_CellLayerNormWeights->GetTensorInfo(), 1, n_cell, "CellLayerNormWeights");
2264  }
2266  {
2267  throw InvalidArgumentException(descriptorName + ": Layer normalisation is disabled but one or more layer "
2268  "normalisation weights are present.");
2269  }
2270 }
bool m_ProjectionEnabled
Enable/disable the projection layer.
const ConstTensorHandle * m_ProjectionWeights
const ConstTensorHandle * m_RecurrentToForgetWeights
float m_ClippingThresProj
Clipping threshold value for the projection.
const ConstTensorHandle * m_InputGateBias
const ConstTensorHandle * m_RecurrentToCellWeights
const ConstTensorHandle * m_CellBias
void ValidateTensorNumDimNumElem(const TensorInfo &tensorInfo, unsigned int numDimension, unsigned int numElements, std::string const &tensorName) const
const ConstTensorHandle * m_InputToOutputWeights
const ConstTensorHandle * m_OutputLayerNormWeights
TensorShape GetShape() const override
Get the number of elements for each dimension ordered from slowest iterating dimension to fastest ite...
const ConstTensorHandle * m_OutputGateBias
const TensorInfo & GetTensorInfo() const
std::vector< TensorInfo > m_InputTensorInfos
const ConstTensorHandle * m_CellLayerNormWeights
bool m_PeepholeEnabled
Enable/disable peephole.
const ConstTensorHandle * m_CellToOutputWeights
std::vector< TensorInfo > m_OutputTensorInfos
const ConstTensorHandle * m_InputToCellWeights
const ConstTensorHandle * m_InputToForgetWeights
float m_ClippingThresCell
Clipping threshold value for the cell state.
const ConstTensorHandle * m_RecurrentToInputWeights
const ConstTensorHandle * m_ForgetGateBias
bool m_CifgEnabled
Enable/disable cifg (coupled input & forget gate).
const ConstTensorHandle * m_CellToForgetWeights
const ConstTensorHandle * m_ProjectionBias
bool m_LayerNormEnabled
Enable/disable layer normalization.
const ConstTensorHandle * m_ForgetLayerNormWeights
const ConstTensorHandle * m_InputLayerNormWeights
const ConstTensorHandle * m_CellToInputWeights
const ConstTensorHandle * m_InputToInputWeights
const ConstTensorHandle * m_RecurrentToOutputWeights

Member Data Documentation

◆ m_CellBias

const ConstTensorHandle* m_CellBias

Definition at line 472 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_CellLayerNormWeights

const ConstTensorHandle* m_CellLayerNormWeights

Definition at line 478 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_CellToForgetWeights

const ConstTensorHandle* m_CellToForgetWeights

Definition at line 468 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_CellToInputWeights

const ConstTensorHandle* m_CellToInputWeights

Definition at line 467 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_CellToOutputWeights

const ConstTensorHandle* m_CellToOutputWeights

Definition at line 469 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_ForgetGateBias

const ConstTensorHandle* m_ForgetGateBias

Definition at line 471 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_ForgetLayerNormWeights

const ConstTensorHandle* m_ForgetLayerNormWeights

Definition at line 477 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputGateBias

const ConstTensorHandle* m_InputGateBias

Definition at line 470 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputLayerNormWeights

const ConstTensorHandle* m_InputLayerNormWeights

Definition at line 476 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputToCellWeights

const ConstTensorHandle* m_InputToCellWeights

Definition at line 461 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputToForgetWeights

const ConstTensorHandle* m_InputToForgetWeights

Definition at line 460 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputToInputWeights

const ConstTensorHandle* m_InputToInputWeights

Definition at line 459 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputToOutputWeights

const ConstTensorHandle* m_InputToOutputWeights

Definition at line 462 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_OutputGateBias

const ConstTensorHandle* m_OutputGateBias

Definition at line 473 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_OutputLayerNormWeights

const ConstTensorHandle* m_OutputLayerNormWeights

Definition at line 479 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_ProjectionBias

const ConstTensorHandle* m_ProjectionBias

Definition at line 475 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_ProjectionWeights

const ConstTensorHandle* m_ProjectionWeights

Definition at line 474 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_RecurrentToCellWeights

const ConstTensorHandle* m_RecurrentToCellWeights

Definition at line 465 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_RecurrentToForgetWeights

const ConstTensorHandle* m_RecurrentToForgetWeights

Definition at line 464 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_RecurrentToInputWeights

const ConstTensorHandle* m_RecurrentToInputWeights

Definition at line 463 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_RecurrentToOutputWeights

const ConstTensorHandle* m_RecurrentToOutputWeights

Definition at line 466 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().


The documentation for this struct was generated from the following files: