ArmNN
 21.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 QueueDescriptor
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
 

Additional Inherited Members

- Protected Member Functions inherited from QueueDescriptorWithParameters< LstmDescriptor >
 ~QueueDescriptorWithParameters ()=default
 
 QueueDescriptorWithParameters ()=default
 
 QueueDescriptorWithParameters (QueueDescriptorWithParameters const &)=default
 
QueueDescriptorWithParametersoperator= (QueueDescriptorWithParameters const &)=default
 
- Protected Member Functions inherited from QueueDescriptor
 ~QueueDescriptor ()=default
 
 QueueDescriptor ()
 
 QueueDescriptor (QueueDescriptor const &)=default
 
QueueDescriptoroperator= (QueueDescriptor const &)=default
 

Detailed Description

Definition at line 415 of file WorkloadData.hpp.

Constructor & Destructor Documentation

◆ LstmQueueDescriptor()

LstmQueueDescriptor ( )
inline

Definition at line 417 of file WorkloadData.hpp.

418  : m_InputToInputWeights(nullptr)
419  , m_InputToForgetWeights(nullptr)
420  , m_InputToCellWeights(nullptr)
421  , m_InputToOutputWeights(nullptr)
422  , m_RecurrentToInputWeights(nullptr)
423  , m_RecurrentToForgetWeights(nullptr)
424  , m_RecurrentToCellWeights(nullptr)
425  , m_RecurrentToOutputWeights(nullptr)
426  , m_CellToInputWeights(nullptr)
427  , m_CellToForgetWeights(nullptr)
428  , m_CellToOutputWeights(nullptr)
429  , m_InputGateBias(nullptr)
430  , m_ForgetGateBias(nullptr)
431  , m_CellBias(nullptr)
432  , m_OutputGateBias(nullptr)
433  , m_ProjectionWeights(nullptr)
434  , m_ProjectionBias(nullptr)
435  , m_InputLayerNormWeights(nullptr)
436  , m_ForgetLayerNormWeights(nullptr)
437  , m_CellLayerNormWeights(nullptr)
438  , m_OutputLayerNormWeights(nullptr)
439  {
440  }
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 1937 of file WorkloadData.cpp.

References armnn::BFloat16, armnn::Float16, armnn::Float32, WorkloadInfo::m_InputTensorInfos, WorkloadInfo::m_OutputTensorInfos, and armnn::QSymmS16.

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

Referenced by LstmLayer::CreateWorkload().

◆ m_CellLayerNormWeights

const ConstTensorHandle* m_CellLayerNormWeights

Definition at line 461 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_CellToForgetWeights

const ConstTensorHandle* m_CellToForgetWeights

Definition at line 451 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_CellToInputWeights

const ConstTensorHandle* m_CellToInputWeights

Definition at line 450 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_CellToOutputWeights

const ConstTensorHandle* m_CellToOutputWeights

Definition at line 452 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_ForgetGateBias

const ConstTensorHandle* m_ForgetGateBias

Definition at line 454 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_ForgetLayerNormWeights

const ConstTensorHandle* m_ForgetLayerNormWeights

Definition at line 460 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputGateBias

const ConstTensorHandle* m_InputGateBias

Definition at line 453 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputLayerNormWeights

const ConstTensorHandle* m_InputLayerNormWeights

Definition at line 459 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputToCellWeights

const ConstTensorHandle* m_InputToCellWeights

Definition at line 444 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputToForgetWeights

const ConstTensorHandle* m_InputToForgetWeights

Definition at line 443 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputToInputWeights

const ConstTensorHandle* m_InputToInputWeights

Definition at line 442 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputToOutputWeights

const ConstTensorHandle* m_InputToOutputWeights

Definition at line 445 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_OutputGateBias

const ConstTensorHandle* m_OutputGateBias

Definition at line 456 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_OutputLayerNormWeights

const ConstTensorHandle* m_OutputLayerNormWeights

Definition at line 462 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_ProjectionBias

const ConstTensorHandle* m_ProjectionBias

Definition at line 458 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_ProjectionWeights

const ConstTensorHandle* m_ProjectionWeights

Definition at line 457 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_RecurrentToCellWeights

const ConstTensorHandle* m_RecurrentToCellWeights

Definition at line 448 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_RecurrentToForgetWeights

const ConstTensorHandle* m_RecurrentToForgetWeights

Definition at line 447 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_RecurrentToInputWeights

const ConstTensorHandle* m_RecurrentToInputWeights

Definition at line 446 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_RecurrentToOutputWeights

const ConstTensorHandle* m_RecurrentToOutputWeights

Definition at line 449 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().


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