ArmNN
 22.11
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 422 of file WorkloadData.hpp.

Constructor & Destructor Documentation

◆ LstmQueueDescriptor()

LstmQueueDescriptor ( )
inline

Definition at line 424 of file WorkloadData.hpp.

425  : m_InputToInputWeights(nullptr)
426  , m_InputToForgetWeights(nullptr)
427  , m_InputToCellWeights(nullptr)
428  , m_InputToOutputWeights(nullptr)
429  , m_RecurrentToInputWeights(nullptr)
430  , m_RecurrentToForgetWeights(nullptr)
431  , m_RecurrentToCellWeights(nullptr)
432  , m_RecurrentToOutputWeights(nullptr)
433  , m_CellToInputWeights(nullptr)
434  , m_CellToForgetWeights(nullptr)
435  , m_CellToOutputWeights(nullptr)
436  , m_InputGateBias(nullptr)
437  , m_ForgetGateBias(nullptr)
438  , m_CellBias(nullptr)
439  , m_OutputGateBias(nullptr)
440  , m_ProjectionWeights(nullptr)
441  , m_ProjectionBias(nullptr)
442  , m_InputLayerNormWeights(nullptr)
443  , m_ForgetLayerNormWeights(nullptr)
444  , m_CellLayerNormWeights(nullptr)
445  , m_OutputLayerNormWeights(nullptr)
446  {
447  }
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 1955 of file WorkloadData.cpp.

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

1956 {
1957  // ported from android/ml/nn/common/operations/LSTM.cpp CheckInputTensorDimensions()
1958 
1959  const std::string descriptorName{"LstmQueueDescriptor"};
1960 
1961  // check dimensions of all inputs and outputs
1962  if (workloadInfo.m_InputTensorInfos.size() != 3)
1963  {
1964  throw InvalidArgumentException(descriptorName + ": Invalid number of inputs.");
1965  }
1966  if (workloadInfo.m_OutputTensorInfos.size() != 4)
1967  {
1968  throw InvalidArgumentException(descriptorName + ": Invalid number of outputs.");
1969  }
1970 
1971  std::vector<DataType> supportedTypes =
1972  {
1977  };
1978 
1979  // check for supported type of one input and match them with all the other input and output
1980  ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], supportedTypes, descriptorName);
1981 
1982  // type matches all other inputs
1983  for (uint32_t i = 1u; i < workloadInfo.m_InputTensorInfos.size(); ++i)
1984  {
1985  ValidateTensorDataTypesMatch(workloadInfo.m_InputTensorInfos[0],
1986  workloadInfo.m_InputTensorInfos[i],
1987  descriptorName,
1988  "input_0",
1989  "input_" + std::to_string(i));
1990  }
1991  // type matches all other outputs
1992  for (uint32_t i = 0u; i < workloadInfo.m_OutputTensorInfos.size(); ++i)
1993  {
1994  ValidateTensorDataTypesMatch(workloadInfo.m_InputTensorInfos[0],
1995  workloadInfo.m_OutputTensorInfos[i],
1996  "LstmQueueDescriptor",
1997  "input_0",
1998  "output_" + std::to_string(i));
1999  }
2000 
2001  // Making sure clipping parameters have valid values.
2002  // == 0 means no clipping
2003  // > 0 means clipping
2004  if (m_Parameters.m_ClippingThresCell < 0.0f)
2005  {
2006  throw InvalidArgumentException(descriptorName + ": negative cell clipping threshold is invalid");
2007  }
2008  if (m_Parameters.m_ClippingThresProj < 0.0f)
2009  {
2010  throw InvalidArgumentException(descriptorName + ": negative projection clipping threshold is invalid");
2011  }
2012 
2013  // Inferring batch size, number of outputs and number of cells from the inputs.
2014  const uint32_t n_input = workloadInfo.m_InputTensorInfos[0].GetShape()[1];
2015  const uint32_t n_batch = workloadInfo.m_InputTensorInfos[0].GetShape()[0];
2016  ValidatePointer(m_InputToOutputWeights, "Null pointer check", "InputToOutputWeights");
2017  const uint32_t n_cell = m_InputToOutputWeights->GetShape()[0];
2018  ValidatePointer(m_RecurrentToOutputWeights, "Null pointer check", "RecurrentToOutputWeights");
2019  const uint32_t n_output = m_RecurrentToOutputWeights->GetShape()[1];
2020 
2021  // input tensor
2022  ValidateTensorNumDimNumElem(workloadInfo.m_InputTensorInfos[0], 2, (n_batch * n_input),
2023  descriptorName + " input_0");
2024  // outputStateInTensor
2025  ValidateTensorNumDimNumElem(workloadInfo.m_InputTensorInfos[1], 2, (n_batch * n_output),
2026  descriptorName + " input_1");
2027  // outputStateInTensor
2028  ValidateTensorNumDimNumElem(workloadInfo.m_InputTensorInfos[2], 2, (n_batch * n_cell),
2029  descriptorName + " input_2");
2030  // scratchBufferTensor
2031  unsigned int scratchBufferSize = m_Parameters.m_CifgEnabled ? n_cell * 3 : n_cell * 4;
2032  ValidateTensorNumDimNumElem(workloadInfo.m_OutputTensorInfos[0], 2, (n_batch * scratchBufferSize),
2033  descriptorName + " output_0");
2034  // outputStateOutTensor
2035  ValidateTensorNumDimNumElem(workloadInfo.m_OutputTensorInfos[1], 2, (n_batch * n_output),
2036  descriptorName + " output_1");
2037  // cellStateOutTensor
2038  ValidateTensorNumDimNumElem(workloadInfo.m_OutputTensorInfos[2], 2, (n_batch * n_cell),
2039  descriptorName + " output_2");
2040  // outputTensor
2041  ValidateTensorNumDimNumElem(workloadInfo.m_OutputTensorInfos[3], 2, (n_batch * n_output),
2042  descriptorName + " output_3");
2043 
2044  // check that dimensions of inputs/outputs and QueueDescriptor data match with each other
2045  if ( m_InputToInputWeights )
2046  {
2048  (n_cell * n_input), "InputLayerNormWeights");
2049  }
2050 
2051  ValidatePointer(m_InputToForgetWeights, "Null pointer check", "InputToForgetWeights");
2053  (n_cell * n_input), "InputToForgetWeights");
2054 
2055  ValidatePointer(m_InputToCellWeights, "Null pointer check", "InputToCellWeights");
2057  (n_cell * n_input), "InputToCellWeights");
2058 
2060  {
2062  (n_cell * n_output), "RecurrentToInputWeights");
2063  }
2064 
2065  ValidatePointer(m_RecurrentToForgetWeights, "Null pointer check", "RecurrentToForgetWeights");
2067  (n_cell * n_output), "RecurrentToForgetWeights");
2068 
2069  ValidatePointer(m_RecurrentToCellWeights, "Null pointer check", "RecurrentToCellWeights");
2071  (n_cell * n_output), "RecurrentToCellWeights");
2072 
2073  // Make sure the input-gate's parameters are either both present (regular
2074  // LSTM) or not at all (CIFG-LSTM). And CifgEnable is set accordingly.
2075  bool cifg_weights_all_or_none = ((m_InputToInputWeights && m_RecurrentToInputWeights &&
2079  if (!cifg_weights_all_or_none)
2080  {
2081  throw InvalidArgumentException(descriptorName + ": Input-Gate's parameters InputToInputWeights and "
2082  "RecurrentToInputWeights must either both be present (regular LSTM) "
2083  "or both not present (CIFG-LSTM). In addition CifgEnable must be set "
2084  "accordingly.");
2085  }
2086 
2087  if ( m_CellToInputWeights )
2088  {
2090  n_cell, "CellToInputWeights");
2091  }
2092  if ( m_CellToForgetWeights )
2093  {
2095  n_cell, "CellToForgetWeights");
2096  }
2097  if ( m_CellToOutputWeights )
2098  {
2100  n_cell, "CellToOutputWeights");
2101  }
2102 
2103  // Making sure the peephole weights are there all or none. And PeepholeEnable is set accordingly.
2104  bool peephole_weights_all_or_none =
2109  if (!peephole_weights_all_or_none)
2110  {
2111  throw InvalidArgumentException(descriptorName + ": Invalid combination of peephole parameters.");
2112  }
2113 
2114  // Make sure the input gate bias is present only when not a CIFG-LSTM.
2116  {
2117  if (m_InputGateBias)
2118  {
2119  throw InvalidArgumentException(descriptorName + ": InputGateBias is present and CIFG-LSTM is enabled.");
2120  }
2121  }
2122  else
2123  {
2124  if (!m_InputGateBias)
2125  {
2126  throw InvalidArgumentException(descriptorName + ": If CIFG-LSTM is disabled InputGateBias "
2127  "must be present.");
2128  }
2130  n_cell, "InputGateBias");
2131  }
2132 
2133  ValidatePointer(m_ForgetGateBias, "Null pointer check", "ForgetGateBias");
2134  ValidateTensorNumDimNumElem(m_ForgetGateBias->GetTensorInfo(), 1, n_cell, "ForgetGateBias");
2135 
2136  ValidatePointer(m_CellBias, "Null pointer check", "CellBias");
2137  ValidateTensorNumDimNumElem(m_CellBias->GetTensorInfo(), 1, n_cell, "CellBias");
2138 
2139  ValidatePointer(m_OutputGateBias, "Null pointer check", "OutputGateBias");
2140  ValidateTensorNumDimNumElem(m_OutputGateBias->GetTensorInfo(), 1, n_cell, "OutputGateBias");
2141 
2142  if (m_ProjectionWeights)
2143  {
2145  (n_cell * n_output), "ProjectionWeights");
2146  }
2147  if (m_ProjectionBias)
2148  {
2149  ValidateTensorNumDimNumElem(m_ProjectionBias->GetTensorInfo(), 1, n_output, "ProjectionBias");
2150  }
2151 
2152  // Making sure the projection tensors are consistent:
2153  // 1) If projection weight is not present, then projection bias should not be
2154  // present.
2155  // 2) If projection weight is present, then projection bias is optional.
2156  bool projecton_tensors_consistent = ((!m_ProjectionWeights && !m_ProjectionBias &&
2162  if (!projecton_tensors_consistent)
2163  {
2164  throw InvalidArgumentException(descriptorName + ": Projection tensors are inconsistent.");
2165  }
2166 
2167  // The four layer normalization weights either all have values or none of them have values. Additionally, if
2168  // CIFG is used, input layer normalization weights tensor is omitted and the other layer normalization weights
2169  // either all have values or none of them have values. Layer normalization is used when the values of all the
2170  // layer normalization weights are present
2172  {
2173  ValidateTensorNumDimNumElem(m_InputLayerNormWeights->GetTensorInfo(), 1, n_cell, "InputLayerNormWeights");
2174  }
2176  {
2177  ValidateTensorNumDimNumElem(m_ForgetLayerNormWeights->GetTensorInfo(), 1, n_cell, "ForgetLayerNormWeights");
2178  }
2180  {
2181  ValidateTensorNumDimNumElem(m_CellLayerNormWeights->GetTensorInfo(), 1, n_cell, "CellLayerNormWeights");
2182  }
2184  {
2185  ValidateTensorNumDimNumElem(m_OutputLayerNormWeights->GetTensorInfo(), 1, n_cell, "OutputLayerNormWeights");
2186  }
2187 
2189  {
2191  {
2193  {
2194  throw InvalidArgumentException(descriptorName + ": Layer normalisation is enabled and CIFG-LSTM is "
2195  "disabled but InputLayerNormWeights are not present");
2196  }
2198  1, n_cell, "InputLayerNormWeights");
2199  }
2200  else if (m_InputLayerNormWeights)
2201  {
2202  throw InvalidArgumentException(descriptorName + ":InputLayerNormWeights are present while CIFG is "
2203  "enabled");
2204  }
2205 
2206  ValidatePointer(m_ForgetLayerNormWeights, "Null pointer check layer normalisation enabled",
2207  "ForgetLayerNormWeights");
2208  ValidateTensorNumDimNumElem(m_ForgetLayerNormWeights->GetTensorInfo(), 1, n_cell, "ForgetLayerNormWeights");
2209 
2210  ValidatePointer(m_OutputLayerNormWeights, "Null pointer check layer normalisation enabled",
2211  "OutputLayerNormWeights");
2212  ValidateTensorNumDimNumElem(m_OutputLayerNormWeights->GetTensorInfo(), 1, n_cell, "OutputLayerNormWeights");
2213 
2214  ValidatePointer(m_CellLayerNormWeights, "Null pointer check layer normalisation enabled",
2215  "CellLayerNormWeights");
2216  ValidateTensorNumDimNumElem(m_CellLayerNormWeights->GetTensorInfo(), 1, n_cell, "CellLayerNormWeights");
2217  }
2219  {
2220  throw InvalidArgumentException(descriptorName + ": Layer normalisation is disabled but one or more layer "
2221  "normalisation weights are present.");
2222  }
2223 }
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 462 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_CellLayerNormWeights

const ConstTensorHandle* m_CellLayerNormWeights

Definition at line 468 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_CellToForgetWeights

const ConstTensorHandle* m_CellToForgetWeights

Definition at line 458 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_CellToInputWeights

const ConstTensorHandle* m_CellToInputWeights

Definition at line 457 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_CellToOutputWeights

const ConstTensorHandle* m_CellToOutputWeights

Definition at line 459 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_ForgetGateBias

const ConstTensorHandle* m_ForgetGateBias

Definition at line 461 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_ForgetLayerNormWeights

const ConstTensorHandle* m_ForgetLayerNormWeights

Definition at line 467 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputGateBias

const ConstTensorHandle* m_InputGateBias

Definition at line 460 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputLayerNormWeights

const ConstTensorHandle* m_InputLayerNormWeights

Definition at line 466 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputToCellWeights

const ConstTensorHandle* m_InputToCellWeights

Definition at line 451 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputToForgetWeights

const ConstTensorHandle* m_InputToForgetWeights

Definition at line 450 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputToInputWeights

const ConstTensorHandle* m_InputToInputWeights

Definition at line 449 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputToOutputWeights

const ConstTensorHandle* m_InputToOutputWeights

Definition at line 452 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_OutputGateBias

const ConstTensorHandle* m_OutputGateBias

Definition at line 463 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_OutputLayerNormWeights

const ConstTensorHandle* m_OutputLayerNormWeights

Definition at line 469 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_ProjectionBias

const ConstTensorHandle* m_ProjectionBias

Definition at line 465 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_ProjectionWeights

const ConstTensorHandle* m_ProjectionWeights

Definition at line 464 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_RecurrentToCellWeights

const ConstTensorHandle* m_RecurrentToCellWeights

Definition at line 455 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_RecurrentToForgetWeights

const ConstTensorHandle* m_RecurrentToForgetWeights

Definition at line 454 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_RecurrentToInputWeights

const ConstTensorHandle* m_RecurrentToInputWeights

Definition at line 453 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_RecurrentToOutputWeights

const ConstTensorHandle* m_RecurrentToOutputWeights

Definition at line 456 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().


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