ArmNN
 21.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 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 392 of file WorkloadData.hpp.

Constructor & Destructor Documentation

◆ LstmQueueDescriptor()

LstmQueueDescriptor ( )
inline

Definition at line 394 of file WorkloadData.hpp.

395  : m_InputToInputWeights(nullptr)
396  , m_InputToForgetWeights(nullptr)
397  , m_InputToCellWeights(nullptr)
398  , m_InputToOutputWeights(nullptr)
399  , m_RecurrentToInputWeights(nullptr)
400  , m_RecurrentToForgetWeights(nullptr)
401  , m_RecurrentToCellWeights(nullptr)
402  , m_RecurrentToOutputWeights(nullptr)
403  , m_CellToInputWeights(nullptr)
404  , m_CellToForgetWeights(nullptr)
405  , m_CellToOutputWeights(nullptr)
406  , m_InputGateBias(nullptr)
407  , m_ForgetGateBias(nullptr)
408  , m_CellBias(nullptr)
409  , m_OutputGateBias(nullptr)
410  , m_ProjectionWeights(nullptr)
411  , m_ProjectionBias(nullptr)
412  , m_InputLayerNormWeights(nullptr)
413  , m_ForgetLayerNormWeights(nullptr)
414  , m_CellLayerNormWeights(nullptr)
415  , m_OutputLayerNormWeights(nullptr)
416  {
417  }
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 1896 of file WorkloadData.cpp.

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

1897 {
1898  // ported from android/ml/nn/common/operations/LSTM.cpp CheckInputTensorDimensions()
1899 
1900  const std::string descriptorName{"LstmQueueDescriptor"};
1901 
1902  // check dimensions of all inputs and outputs
1903  if (workloadInfo.m_InputTensorInfos.size() != 3)
1904  {
1905  throw InvalidArgumentException(descriptorName + ": Invalid number of inputs.");
1906  }
1907  if (workloadInfo.m_OutputTensorInfos.size() != 4)
1908  {
1909  throw InvalidArgumentException(descriptorName + ": Invalid number of outputs.");
1910  }
1911 
1912  std::vector<DataType> supportedTypes =
1913  {
1918  };
1919 
1920  // check for supported type of one input and match them with all the other input and output
1921  ValidateDataTypes(workloadInfo.m_InputTensorInfos[0], supportedTypes, descriptorName);
1922 
1923  // type matches all other inputs
1924  for (uint32_t i = 1u; i < workloadInfo.m_InputTensorInfos.size(); ++i)
1925  {
1926  ValidateTensorDataTypesMatch(workloadInfo.m_InputTensorInfos[0],
1927  workloadInfo.m_InputTensorInfos[i],
1928  descriptorName,
1929  "input_0",
1930  "input_" + std::to_string(i));
1931  }
1932  // type matches all other outputs
1933  for (uint32_t i = 0u; i < workloadInfo.m_OutputTensorInfos.size(); ++i)
1934  {
1935  ValidateTensorDataTypesMatch(workloadInfo.m_InputTensorInfos[0],
1936  workloadInfo.m_OutputTensorInfos[i],
1937  "LstmQueueDescriptor",
1938  "input_0",
1939  "output_" + std::to_string(i));
1940  }
1941 
1942  // Making sure clipping parameters have valid values.
1943  // == 0 means no clipping
1944  // > 0 means clipping
1945  if (m_Parameters.m_ClippingThresCell < 0.0f)
1946  {
1947  throw InvalidArgumentException(descriptorName + ": negative cell clipping threshold is invalid");
1948  }
1949  if (m_Parameters.m_ClippingThresProj < 0.0f)
1950  {
1951  throw InvalidArgumentException(descriptorName + ": negative projection clipping threshold is invalid");
1952  }
1953 
1954 
1955  // Inferring batch size, number of outputs and number of cells from the inputs.
1956  const uint32_t n_input = workloadInfo.m_InputTensorInfos[0].GetShape()[1];
1957  const uint32_t n_batch = workloadInfo.m_InputTensorInfos[0].GetShape()[0];
1958  ValidatePointer(m_InputToOutputWeights, "Null pointer check", "InputToOutputWeights");
1959  const uint32_t n_cell = m_InputToOutputWeights->GetShape()[0];
1960  ValidatePointer(m_RecurrentToOutputWeights, "Null pointer check", "RecurrentToOutputWeights");
1961  const uint32_t n_output = m_RecurrentToOutputWeights->GetShape()[1];
1962 
1963  // input tensor
1964  ValidateTensorNumDimNumElem(workloadInfo.m_InputTensorInfos[0], 2, (n_batch * n_input),
1965  descriptorName + " input_0");
1966  // outputStateInTensor
1967  ValidateTensorNumDimNumElem(workloadInfo.m_InputTensorInfos[1], 2, (n_batch * n_output),
1968  descriptorName + " input_1");
1969  // outputStateInTensor
1970  ValidateTensorNumDimNumElem(workloadInfo.m_InputTensorInfos[2], 2, (n_batch * n_cell),
1971  descriptorName + " input_2");
1972  // scratchBufferTensor
1973  unsigned int scratchBufferSize = m_Parameters.m_CifgEnabled ? n_cell * 3 : n_cell * 4;
1974  ValidateTensorNumDimNumElem(workloadInfo.m_OutputTensorInfos[0], 2, (n_batch * scratchBufferSize),
1975  descriptorName + " output_0");
1976  // outputStateOutTensor
1977  ValidateTensorNumDimNumElem(workloadInfo.m_OutputTensorInfos[1], 2, (n_batch * n_output),
1978  descriptorName + " output_1");
1979  // cellStateOutTensor
1980  ValidateTensorNumDimNumElem(workloadInfo.m_OutputTensorInfos[2], 2, (n_batch * n_cell),
1981  descriptorName + " output_2");
1982  // outputTensor
1983  ValidateTensorNumDimNumElem(workloadInfo.m_OutputTensorInfos[3], 2, (n_batch * n_output),
1984  descriptorName + " output_3");
1985 
1986 
1987  // check that dimensions of inputs/outputs and QueueDescriptor data match with each other
1988  if ( m_InputToInputWeights )
1989  {
1990  ValidateTensorNumDimNumElem(m_InputToInputWeights->GetTensorInfo(), 2,
1991  (n_cell * n_input), "InputLayerNormWeights");
1992  }
1993 
1994  ValidatePointer(m_InputToForgetWeights, "Null pointer check", "InputToForgetWeights");
1995  ValidateTensorNumDimNumElem(m_InputToForgetWeights->GetTensorInfo(), 2,
1996  (n_cell * n_input), "InputToForgetWeights");
1997 
1998  ValidatePointer(m_InputToCellWeights, "Null pointer check", "InputToCellWeights");
1999  ValidateTensorNumDimNumElem(m_InputToCellWeights->GetTensorInfo(), 2,
2000  (n_cell * n_input), "InputToCellWeights");
2001 
2003  {
2004  ValidateTensorNumDimNumElem(m_RecurrentToInputWeights->GetTensorInfo(), 2,
2005  (n_cell * n_output), "RecurrentToInputWeights");
2006  }
2007 
2008  ValidatePointer(m_RecurrentToForgetWeights, "Null pointer check", "RecurrentToForgetWeights");
2009  ValidateTensorNumDimNumElem(m_RecurrentToForgetWeights->GetTensorInfo(), 2,
2010  (n_cell * n_output), "RecurrentToForgetWeights");
2011 
2012  ValidatePointer(m_RecurrentToCellWeights, "Null pointer check", "RecurrentToCellWeights");
2013  ValidateTensorNumDimNumElem(m_RecurrentToCellWeights->GetTensorInfo(), 2,
2014  (n_cell * n_output), "RecurrentToCellWeights");
2015 
2016  // Make sure the input-gate's parameters are either both present (regular
2017  // LSTM) or not at all (CIFG-LSTM). And CifgEnable is set accordingly.
2018  bool cifg_weights_all_or_none = ((m_InputToInputWeights && m_RecurrentToInputWeights &&
2022  if (!cifg_weights_all_or_none)
2023  {
2024  throw InvalidArgumentException(descriptorName + ": Input-Gate's parameters InputToInputWeights and "
2025  "RecurrentToInputWeights must either both be present (regular LSTM) "
2026  "or both not present (CIFG-LSTM). In addition CifgEnable must be set "
2027  "accordingly.");
2028  }
2029 
2030  if ( m_CellToInputWeights )
2031  {
2032  ValidateTensorNumDimNumElem(m_CellToInputWeights->GetTensorInfo(), 1,
2033  n_cell, "CellToInputWeights");
2034  }
2035  if ( m_CellToForgetWeights )
2036  {
2037  ValidateTensorNumDimNumElem(m_CellToForgetWeights->GetTensorInfo(), 1,
2038  n_cell, "CellToForgetWeights");
2039  }
2040  if ( m_CellToOutputWeights )
2041  {
2042  ValidateTensorNumDimNumElem(m_CellToOutputWeights->GetTensorInfo(), 1,
2043  n_cell, "CellToOutputWeights");
2044  }
2045 
2046  // Making sure the peephole weights are there all or none. And PeepholeEnable is set accordingly.
2047  bool peephole_weights_all_or_none =
2052  if (!peephole_weights_all_or_none)
2053  {
2054  throw InvalidArgumentException(descriptorName + ": Invalid combination of peephole parameters.");
2055  }
2056 
2057  // Make sure the input gate bias is present only when not a CIFG-LSTM.
2059  {
2060  if (m_InputGateBias)
2061  {
2062  throw InvalidArgumentException(descriptorName + ": InputGateBias is present and CIFG-LSTM is enabled.");
2063  }
2064  }
2065  else
2066  {
2067  if (!m_InputGateBias)
2068  {
2069  throw InvalidArgumentException(descriptorName + ": If CIFG-LSTM is disabled InputGateBias "
2070  "must be present.");
2071  }
2072  ValidateTensorNumDimNumElem(m_InputGateBias->GetTensorInfo(), 1,
2073  n_cell, "InputGateBias");
2074  }
2075 
2076  ValidatePointer(m_ForgetGateBias, "Null pointer check", "ForgetGateBias");
2077  ValidateTensorNumDimNumElem(m_ForgetGateBias->GetTensorInfo(), 1, n_cell, "ForgetGateBias");
2078 
2079  ValidatePointer(m_CellBias, "Null pointer check", "CellBias");
2080  ValidateTensorNumDimNumElem(m_CellBias->GetTensorInfo(), 1, n_cell, "CellBias");
2081 
2082  ValidatePointer(m_OutputGateBias, "Null pointer check", "OutputGateBias");
2083  ValidateTensorNumDimNumElem(m_OutputGateBias->GetTensorInfo(), 1, n_cell, "OutputGateBias");
2084 
2085  if (m_ProjectionWeights)
2086  {
2087  ValidateTensorNumDimNumElem(m_ProjectionWeights->GetTensorInfo(), 2,
2088  (n_cell * n_output), "ProjectionWeights");
2089  }
2090  if (m_ProjectionBias)
2091  {
2092  ValidateTensorNumDimNumElem(m_ProjectionBias->GetTensorInfo(), 1, n_output, "ProjectionBias");
2093  }
2094 
2095  // Making sure the projection tensors are consistent:
2096  // 1) If projection weight is not present, then projection bias should not be
2097  // present.
2098  // 2) If projection weight is present, then projection bias is optional.
2099  bool projecton_tensors_consistent = ((!m_ProjectionWeights && !m_ProjectionBias &&
2105  if (!projecton_tensors_consistent)
2106  {
2107  throw InvalidArgumentException(descriptorName + ": Projection tensors are inconsistent.");
2108  }
2109 
2110  // The four layer normalization weights either all have values or none of them have values. Additionally, if
2111  // CIFG is used, input layer normalization weights tensor is omitted and the other layer normalization weights
2112  // either all have values or none of them have values. Layer normalization is used when the values of all the
2113  // layer normalization weights are present
2115  {
2116  ValidateTensorNumDimNumElem(m_InputLayerNormWeights->GetTensorInfo(), 1, n_cell, "InputLayerNormWeights");
2117  }
2119  {
2120  ValidateTensorNumDimNumElem(m_ForgetLayerNormWeights->GetTensorInfo(), 1, n_cell, "ForgetLayerNormWeights");
2121  }
2123  {
2124  ValidateTensorNumDimNumElem(m_CellLayerNormWeights->GetTensorInfo(), 1, n_cell, "CellLayerNormWeights");
2125  }
2127  {
2128  ValidateTensorNumDimNumElem(m_OutputLayerNormWeights->GetTensorInfo(), 1, n_cell, "OutputLayerNormWeights");
2129  }
2130 
2132  {
2134  {
2136  {
2137  throw InvalidArgumentException(descriptorName + ": Layer normalisation is enabled and CIFG-LSTM is "
2138  "disabled but InputLayerNormWeights are not present");
2139  }
2140  ValidateTensorNumDimNumElem(m_InputLayerNormWeights->GetTensorInfo(),
2141  1, n_cell, "InputLayerNormWeights");
2142  }
2143  else if (m_InputLayerNormWeights)
2144  {
2145  throw InvalidArgumentException(descriptorName + ":InputLayerNormWeights are present while CIFG is "
2146  "enabled");
2147  }
2148 
2149  ValidatePointer(m_ForgetLayerNormWeights, "Null pointer check layer normalisation enabled",
2150  "ForgetLayerNormWeights");
2151  ValidateTensorNumDimNumElem(m_ForgetLayerNormWeights->GetTensorInfo(), 1, n_cell, "ForgetLayerNormWeights");
2152 
2153  ValidatePointer(m_OutputLayerNormWeights, "Null pointer check layer normalisation enabled",
2154  "OutputLayerNormWeights");
2155  ValidateTensorNumDimNumElem(m_OutputLayerNormWeights->GetTensorInfo(), 1, n_cell, "OutputLayerNormWeights");
2156 
2157  ValidatePointer(m_CellLayerNormWeights, "Null pointer check layer normalisation enabled",
2158  "CellLayerNormWeights");
2159  ValidateTensorNumDimNumElem(m_CellLayerNormWeights->GetTensorInfo(), 1, n_cell, "CellLayerNormWeights");
2160  }
2162  {
2163  throw InvalidArgumentException(descriptorName + ": Layer normalisation is disabled but one or more layer "
2164  "normalisation weights are present.");
2165  }
2166 }
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 432 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_CellLayerNormWeights

const ConstTensorHandle* m_CellLayerNormWeights

Definition at line 438 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_CellToForgetWeights

const ConstTensorHandle* m_CellToForgetWeights

Definition at line 428 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_CellToInputWeights

const ConstTensorHandle* m_CellToInputWeights

Definition at line 427 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_CellToOutputWeights

const ConstTensorHandle* m_CellToOutputWeights

Definition at line 429 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_ForgetGateBias

const ConstTensorHandle* m_ForgetGateBias

Definition at line 431 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_ForgetLayerNormWeights

const ConstTensorHandle* m_ForgetLayerNormWeights

Definition at line 437 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputGateBias

const ConstTensorHandle* m_InputGateBias

Definition at line 430 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputLayerNormWeights

const ConstTensorHandle* m_InputLayerNormWeights

Definition at line 436 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputToCellWeights

const ConstTensorHandle* m_InputToCellWeights

Definition at line 421 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputToForgetWeights

const ConstTensorHandle* m_InputToForgetWeights

Definition at line 420 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputToInputWeights

const ConstTensorHandle* m_InputToInputWeights

Definition at line 419 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputToOutputWeights

const ConstTensorHandle* m_InputToOutputWeights

Definition at line 422 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_OutputGateBias

const ConstTensorHandle* m_OutputGateBias

Definition at line 433 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_OutputLayerNormWeights

const ConstTensorHandle* m_OutputLayerNormWeights

Definition at line 439 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_ProjectionBias

const ConstTensorHandle* m_ProjectionBias

Definition at line 435 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_ProjectionWeights

const ConstTensorHandle* m_ProjectionWeights

Definition at line 434 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_RecurrentToCellWeights

const ConstTensorHandle* m_RecurrentToCellWeights

Definition at line 425 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_RecurrentToForgetWeights

const ConstTensorHandle* m_RecurrentToForgetWeights

Definition at line 424 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_RecurrentToInputWeights

const ConstTensorHandle* m_RecurrentToInputWeights

Definition at line 423 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_RecurrentToOutputWeights

const ConstTensorHandle* m_RecurrentToOutputWeights

Definition at line 426 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().


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