ArmNN
 21.08
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 404 of file WorkloadData.hpp.

Constructor & Destructor Documentation

◆ LstmQueueDescriptor()

LstmQueueDescriptor ( )
inline

Definition at line 406 of file WorkloadData.hpp.

407  : m_InputToInputWeights(nullptr)
408  , m_InputToForgetWeights(nullptr)
409  , m_InputToCellWeights(nullptr)
410  , m_InputToOutputWeights(nullptr)
411  , m_RecurrentToInputWeights(nullptr)
412  , m_RecurrentToForgetWeights(nullptr)
413  , m_RecurrentToCellWeights(nullptr)
414  , m_RecurrentToOutputWeights(nullptr)
415  , m_CellToInputWeights(nullptr)
416  , m_CellToForgetWeights(nullptr)
417  , m_CellToOutputWeights(nullptr)
418  , m_InputGateBias(nullptr)
419  , m_ForgetGateBias(nullptr)
420  , m_CellBias(nullptr)
421  , m_OutputGateBias(nullptr)
422  , m_ProjectionWeights(nullptr)
423  , m_ProjectionBias(nullptr)
424  , m_InputLayerNormWeights(nullptr)
425  , m_ForgetLayerNormWeights(nullptr)
426  , m_CellLayerNormWeights(nullptr)
427  , m_OutputLayerNormWeights(nullptr)
428  {
429  }
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 1881 of file WorkloadData.cpp.

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

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

Referenced by LstmLayer::CreateWorkload().

◆ m_CellLayerNormWeights

const ConstTensorHandle* m_CellLayerNormWeights

Definition at line 450 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_CellToForgetWeights

const ConstTensorHandle* m_CellToForgetWeights

Definition at line 440 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_CellToInputWeights

const ConstTensorHandle* m_CellToInputWeights

Definition at line 439 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_CellToOutputWeights

const ConstTensorHandle* m_CellToOutputWeights

Definition at line 441 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_ForgetGateBias

const ConstTensorHandle* m_ForgetGateBias

Definition at line 443 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_ForgetLayerNormWeights

const ConstTensorHandle* m_ForgetLayerNormWeights

Definition at line 449 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputGateBias

const ConstTensorHandle* m_InputGateBias

Definition at line 442 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputLayerNormWeights

const ConstTensorHandle* m_InputLayerNormWeights

Definition at line 448 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputToCellWeights

const ConstTensorHandle* m_InputToCellWeights

Definition at line 433 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputToForgetWeights

const ConstTensorHandle* m_InputToForgetWeights

Definition at line 432 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputToInputWeights

const ConstTensorHandle* m_InputToInputWeights

Definition at line 431 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_InputToOutputWeights

const ConstTensorHandle* m_InputToOutputWeights

Definition at line 434 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_OutputGateBias

const ConstTensorHandle* m_OutputGateBias

Definition at line 445 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_OutputLayerNormWeights

const ConstTensorHandle* m_OutputLayerNormWeights

Definition at line 451 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_ProjectionBias

const ConstTensorHandle* m_ProjectionBias

Definition at line 447 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_ProjectionWeights

const ConstTensorHandle* m_ProjectionWeights

Definition at line 446 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_RecurrentToCellWeights

const ConstTensorHandle* m_RecurrentToCellWeights

Definition at line 437 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_RecurrentToForgetWeights

const ConstTensorHandle* m_RecurrentToForgetWeights

Definition at line 436 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_RecurrentToInputWeights

const ConstTensorHandle* m_RecurrentToInputWeights

Definition at line 435 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().

◆ m_RecurrentToOutputWeights

const ConstTensorHandle* m_RecurrentToOutputWeights

Definition at line 438 of file WorkloadData.hpp.

Referenced by LstmLayer::CreateWorkload().


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