ArmNN
 20.05
LstmLayer Class Reference

This layer represents a LSTM operation. More...

#include <LstmLayer.hpp>

Inheritance diagram for LstmLayer:
LayerWithParameters< LstmDescriptor > Layer IConnectableLayer

Public Member Functions

virtual std::unique_ptr< IWorkloadCreateWorkload (const IWorkloadFactory &factory) const override
 Makes a workload for the LSTM type. More...
 
LstmLayerClone (Graph &graph) const override
 Creates a dynamically-allocated copy of this layer. More...
 
void ValidateTensorShapesFromInputs () override
 Check if the input tensor shape(s) will lead to a valid configuration of LstmLayer. More...
 
std::vector< TensorShapeInferOutputShapes (const std::vector< TensorShape > &inputShapes) const override
 By default returns inputShapes if the number of inputs are equal to number of outputs, otherwise infers the output shapes from given input shapes and layer properties. More...
 
void Accept (ILayerVisitor &visitor) const override
 Apply a visitor to this layer. More...
 
- Public Member Functions inherited from LayerWithParameters< LstmDescriptor >
const LstmDescriptorGetParameters () const
 
void SerializeLayerParameters (ParameterStringifyFunction &fn) const override
 Helper to serialize the layer parameters to string (currently used in DotSerializer and company). More...
 
- Public Member Functions inherited from Layer
 Layer (unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const char *name)
 
 Layer (unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, DataLayout layout, const char *name)
 
const std::string & GetNameStr () const
 
const OutputHandlerGetOutputHandler (unsigned int i=0) const
 
OutputHandlerGetOutputHandler (unsigned int i=0)
 
const std::vector< InputSlot > & GetInputSlots () const
 
const std::vector< OutputSlot > & GetOutputSlots () const
 
std::vector< InputSlot >::iterator BeginInputSlots ()
 
std::vector< InputSlot >::iterator EndInputSlots ()
 
std::vector< OutputSlot >::iterator BeginOutputSlots ()
 
std::vector< OutputSlot >::iterator EndOutputSlots ()
 
bool IsOutputUnconnected ()
 
void ResetPriority () const
 
LayerPriority GetPriority () const
 
LayerType GetType () const
 
DataType GetDataType () const
 
const BackendIdGetBackendId () const
 
void SetBackendId (const BackendId &id)
 
virtual void CreateTensorHandles (const TensorHandleFactoryRegistry &registry, const IWorkloadFactory &factory, const bool IsMemoryManaged=true)
 
void VerifyLayerConnections (unsigned int expectedConnections, const CheckLocation &location) const
 
virtual void ReleaseConstantData ()
 
template<typename Op >
void OperateOnConstantTensors (Op op)
 
const char * GetName () const override
 Returns the name of the layer. More...
 
unsigned int GetNumInputSlots () const override
 Returns the number of connectable input slots. More...
 
unsigned int GetNumOutputSlots () const override
 Returns the number of connectable output slots. More...
 
const InputSlotGetInputSlot (unsigned int index) const override
 Get a const input slot handle by slot index. More...
 
InputSlotGetInputSlot (unsigned int index) override
 Get the input slot handle by slot index. More...
 
const OutputSlotGetOutputSlot (unsigned int index=0) const override
 Get the const output slot handle by slot index. More...
 
OutputSlotGetOutputSlot (unsigned int index=0) override
 Get the output slot handle by slot index. More...
 
void SetGuid (LayerGuid guid)
 
LayerGuid GetGuid () const final
 Returns the unique id of the layer. More...
 
void AddRelatedLayerName (const std::string layerName)
 
const std::list< std::string > & GetRelatedLayerNames ()
 
virtual void Reparent (Graph &dest, std::list< Layer *>::const_iterator iterator)=0
 
void BackendSelectionHint (Optional< BackendId > backend) final
 Provide a hint for the optimizer as to which backend to prefer for this layer. More...
 
Optional< BackendIdGetBackendHint () const
 

Public Attributes

LstmBasicParameters m_BasicParameters
 
LstmOptCifgParameters m_CifgParameters
 
LstmOptProjectionParameters m_ProjectionParameters
 
LstmOptPeepholeParameters m_PeepholeParameters
 
LstmOptLayerNormParameters m_LayerNormParameters
 

Protected Member Functions

 LstmLayer (const LstmDescriptor &param, const char *name)
 Constructor to create a LstmLayer. More...
 
 ~LstmLayer ()=default
 Default destructor. More...
 
Layer::ConstantTensors GetConstantTensorsByRef () override
 Retrieve the handles to the constant values stored by the layer. More...
 
- Protected Member Functions inherited from LayerWithParameters< LstmDescriptor >
 LayerWithParameters (unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const LstmDescriptor &param, const char *name)
 
 ~LayerWithParameters ()=default
 
WorkloadInfo PrepInfoAndDesc (QueueDescriptor &descriptor) const
 Helper function to reduce duplication in *LayerCreateWorkload. More...
 
- Protected Member Functions inherited from Layer
virtual ~Layer ()=default
 
template<typename QueueDescriptor >
void CollectQueueDescriptorInputs (QueueDescriptor &descriptor, WorkloadInfo &info) const
 
template<typename QueueDescriptor >
void CollectQueueDescriptorOutputs (QueueDescriptor &descriptor, WorkloadInfo &info) const
 
template<typename QueueDescriptor >
WorkloadInfo PrepInfoAndDesc (QueueDescriptor &descriptor) const
 Helper function to reduce duplication in *LayerCreateWorkload. More...
 
template<typename LayerType , typename ... Params>
LayerTypeCloneBase (Graph &graph, Params &&... params) const
 
- Protected Member Functions inherited from IConnectableLayer
 ~IConnectableLayer ()
 Objects are not deletable via the handle. More...
 

Additional Inherited Members

- Public Types inherited from LayerWithParameters< LstmDescriptor >
using DescriptorType = LstmDescriptor
 
- Protected Types inherited from Layer
using ConstantTensors = std::vector< std::reference_wrapper< std::unique_ptr< ScopedCpuTensorHandle > >>
 
- Protected Attributes inherited from LayerWithParameters< LstmDescriptor >
LstmDescriptor m_Param
 The parameters for the layer (not including tensor-valued weights etc.). More...
 
- Protected Attributes inherited from Layer
std::vector< OutputHandlerm_OutputHandlers
 

Detailed Description

This layer represents a LSTM operation.

Definition at line 77 of file LstmLayer.hpp.

Constructor & Destructor Documentation

◆ LstmLayer()

LstmLayer ( const LstmDescriptor param,
const char *  name 
)
protected

Constructor to create a LstmLayer.

Parameters
[in]paramLstmDescriptor to configure the lstm operation.
[in]nameOptional name for the layer.

Definition at line 17 of file LstmLayer.cpp.

References armnn::Lstm.

18  : LayerWithParameters(3, 4, LayerType::Lstm, param, name)
19 {
20 }
LayerWithParameters(unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const LstmDescriptor &param, const char *name)

◆ ~LstmLayer()

~LstmLayer ( )
protecteddefault

Default destructor.

Member Function Documentation

◆ Accept()

void Accept ( ILayerVisitor visitor) const
overridevirtual

Apply a visitor to this layer.

Implements IConnectableLayer.

Definition at line 309 of file LstmLayer.cpp.

References Layer::GetName(), LayerWithParameters< LstmDescriptor >::GetParameters(), LstmLayer::m_BasicParameters, LstmInputParams::m_CellBias, LstmBasicParameters::m_CellBias, LstmOptLayerNormParameters::m_CellLayerNormWeights, LstmInputParams::m_CellLayerNormWeights, LstmOptPeepholeParameters::m_CellToForgetWeights, LstmInputParams::m_CellToForgetWeights, LstmOptPeepholeParameters::m_CellToInputWeights, LstmInputParams::m_CellToInputWeights, LstmInputParams::m_CellToOutputWeights, LstmOptPeepholeParameters::m_CellToOutputWeights, LstmLayer::m_CifgParameters, LstmInputParams::m_ForgetGateBias, LstmBasicParameters::m_ForgetGateBias, LstmOptLayerNormParameters::m_ForgetLayerNormWeights, LstmInputParams::m_ForgetLayerNormWeights, LstmOptCifgParameters::m_InputGateBias, LstmInputParams::m_InputGateBias, LstmOptLayerNormParameters::m_InputLayerNormWeights, LstmInputParams::m_InputLayerNormWeights, LstmInputParams::m_InputToCellWeights, LstmBasicParameters::m_InputToCellWeights, LstmInputParams::m_InputToForgetWeights, LstmBasicParameters::m_InputToForgetWeights, LstmOptCifgParameters::m_InputToInputWeights, LstmInputParams::m_InputToInputWeights, LstmInputParams::m_InputToOutputWeights, LstmBasicParameters::m_InputToOutputWeights, LstmLayer::m_LayerNormParameters, LstmInputParams::m_OutputGateBias, LstmBasicParameters::m_OutputGateBias, LstmOptLayerNormParameters::m_OutputLayerNormWeights, LstmInputParams::m_OutputLayerNormWeights, LstmLayer::m_PeepholeParameters, LstmOptProjectionParameters::m_ProjectionBias, LstmInputParams::m_ProjectionBias, LstmLayer::m_ProjectionParameters, LstmOptProjectionParameters::m_ProjectionWeights, LstmInputParams::m_ProjectionWeights, LstmInputParams::m_RecurrentToCellWeights, LstmBasicParameters::m_RecurrentToCellWeights, LstmInputParams::m_RecurrentToForgetWeights, LstmBasicParameters::m_RecurrentToForgetWeights, LstmOptCifgParameters::m_RecurrentToInputWeights, LstmInputParams::m_RecurrentToInputWeights, LstmInputParams::m_RecurrentToOutputWeights, LstmBasicParameters::m_RecurrentToOutputWeights, and ILayerVisitor::VisitLstmLayer().

310 {
311  LstmInputParams inputParams;
312  ConstTensor inputToInputWeightsTensor;
314  {
315  ConstTensor inputToInputWeightsTensorCopy(m_CifgParameters.m_InputToInputWeights->GetTensorInfo(),
317  inputToInputWeightsTensor = inputToInputWeightsTensorCopy;
318  inputParams.m_InputToInputWeights = &inputToInputWeightsTensor;
319  }
320  ConstTensor inputToForgetWeightsTensor;
322  {
323  ConstTensor inputToForgetWeightsTensorCopy(m_BasicParameters.m_InputToForgetWeights->GetTensorInfo(),
325  inputToForgetWeightsTensor = inputToForgetWeightsTensorCopy;
326  inputParams.m_InputToForgetWeights = &inputToForgetWeightsTensor;
327  }
328  ConstTensor inputToCellWeightsTensor;
330  {
331  ConstTensor inputToCellWeightsTensorCopy(m_BasicParameters.m_InputToCellWeights->GetTensorInfo(),
333  inputToCellWeightsTensor = inputToCellWeightsTensorCopy;
334  inputParams.m_InputToCellWeights = &inputToCellWeightsTensor;
335  }
336  ConstTensor inputToOutputWeightsTensor;
338  {
339  ConstTensor inputToOutputWeightsTensorCopy(m_BasicParameters.m_InputToOutputWeights->GetTensorInfo(),
341  inputToOutputWeightsTensor = inputToOutputWeightsTensorCopy;
342  inputParams.m_InputToOutputWeights = &inputToOutputWeightsTensor;
343  }
344  ConstTensor recurrentToInputWeightsTensor;
346  {
347  ConstTensor recurrentToInputWeightsTensorCopy(
350  recurrentToInputWeightsTensor = recurrentToInputWeightsTensorCopy;
351  inputParams.m_RecurrentToInputWeights = &recurrentToInputWeightsTensor;
352  }
353  ConstTensor recurrentToForgetWeightsTensor;
355  {
356  ConstTensor recurrentToForgetWeightsTensorCopy(
359  recurrentToForgetWeightsTensor = recurrentToForgetWeightsTensorCopy;
360  inputParams.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor;
361  }
362  ConstTensor recurrentToCellWeightsTensor;
364  {
365  ConstTensor recurrentToCellWeightsTensorCopy(
368  recurrentToCellWeightsTensor = recurrentToCellWeightsTensorCopy;
369  inputParams.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor;
370  }
371  ConstTensor recurrentToOutputWeightsTensor;
373  {
374  ConstTensor recurrentToOutputWeightsTensorCopy(
377  recurrentToOutputWeightsTensor = recurrentToOutputWeightsTensorCopy;
378  inputParams.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor;
379  }
380  ConstTensor cellToInputWeightsTensor;
382  {
383  ConstTensor cellToInputWeightsTensorCopy(m_PeepholeParameters.m_CellToInputWeights->GetTensorInfo(),
385  cellToInputWeightsTensor = cellToInputWeightsTensorCopy;
386  inputParams.m_CellToInputWeights = &cellToInputWeightsTensor;
387  }
388  ConstTensor cellToForgetWeightsTensor;
390  {
391  ConstTensor cellToForgetWeightsTensorCopy(m_PeepholeParameters.m_CellToForgetWeights->GetTensorInfo(),
393  cellToForgetWeightsTensor = cellToForgetWeightsTensorCopy;
394  inputParams.m_CellToForgetWeights = &cellToForgetWeightsTensor;
395  }
396  ConstTensor cellToOutputWeightsTensor;
398  {
399  ConstTensor cellToOutputWeightsTensorCopy(m_PeepholeParameters.m_CellToOutputWeights->GetTensorInfo(),
401  cellToOutputWeightsTensor = cellToOutputWeightsTensorCopy;
402  inputParams.m_CellToOutputWeights = &cellToOutputWeightsTensor;
403  }
404  ConstTensor inputGateBiasTensor;
405  if (m_CifgParameters.m_InputGateBias != nullptr)
406  {
407  ConstTensor inputGateBiasTensorCopy(m_CifgParameters.m_InputGateBias->GetTensorInfo(),
408  m_CifgParameters.m_InputGateBias->Map(true));
409  inputGateBiasTensor = inputGateBiasTensorCopy;
410  inputParams.m_InputGateBias = &inputGateBiasTensor;
411  }
412  ConstTensor forgetGateBiasTensor;
413  if (m_BasicParameters.m_ForgetGateBias != nullptr)
414  {
415  ConstTensor forgetGateBiasTensorCopy(m_BasicParameters.m_ForgetGateBias->GetTensorInfo(),
417  forgetGateBiasTensor = forgetGateBiasTensorCopy;
418  inputParams.m_ForgetGateBias = &forgetGateBiasTensor;
419  }
420  ConstTensor cellBiasTensor;
421  if (m_BasicParameters.m_CellBias != nullptr)
422  {
423  ConstTensor cellBiasTensorCopy(m_BasicParameters.m_CellBias->GetTensorInfo(),
424  m_BasicParameters.m_CellBias->Map(true));
425  cellBiasTensor = cellBiasTensorCopy;
426  inputParams.m_CellBias = &cellBiasTensor;
427  }
428  ConstTensor outputGateBias;
429  if (m_BasicParameters.m_OutputGateBias != nullptr)
430  {
431  ConstTensor outputGateBiasCopy(m_BasicParameters.m_OutputGateBias->GetTensorInfo(),
433  outputGateBias = outputGateBiasCopy;
434  inputParams.m_OutputGateBias = &outputGateBias;
435  }
436  ConstTensor projectionWeightsTensor;
438  {
439  ConstTensor projectionWeightsTensorCopy(m_ProjectionParameters.m_ProjectionWeights->GetTensorInfo(),
441  projectionWeightsTensor = projectionWeightsTensorCopy;
442  inputParams.m_ProjectionWeights = &projectionWeightsTensor;
443  }
444  ConstTensor projectionBiasTensor;
446  {
447  ConstTensor projectionBiasTensorCopy(m_ProjectionParameters.m_ProjectionBias->GetTensorInfo(),
449  projectionBiasTensor = projectionBiasTensorCopy;
450  inputParams.m_ProjectionBias = &projectionBiasTensor;
451  }
452  ConstTensor inputLayerNormTensor;
454  {
455  ConstTensor inputLayerNormTensorCopy(m_LayerNormParameters.m_InputLayerNormWeights->GetTensorInfo(),
457  inputLayerNormTensor = inputLayerNormTensorCopy;
458  inputParams.m_InputLayerNormWeights = &inputLayerNormTensor;
459  }
460  ConstTensor forgetLayerNormTensor;
462  {
463  ConstTensor forgetLayerNormTensorCopy(m_LayerNormParameters.m_ForgetLayerNormWeights->GetTensorInfo(),
465  forgetLayerNormTensor = forgetLayerNormTensorCopy;
466  inputParams.m_ForgetLayerNormWeights = &forgetLayerNormTensor;
467  }
468  ConstTensor cellLayerNormTensor;
470  {
471  ConstTensor cellLayerNormTensorCopy(m_LayerNormParameters.m_CellLayerNormWeights->GetTensorInfo(),
473  cellLayerNormTensor = cellLayerNormTensorCopy;
474  inputParams.m_CellLayerNormWeights = &cellLayerNormTensor;
475  }
476  ConstTensor outputLayerNormTensor;
478  {
479  ConstTensor outputLayerNormTensorCopy(m_LayerNormParameters.m_OutputLayerNormWeights->GetTensorInfo(),
481  outputLayerNormTensor = outputLayerNormTensorCopy;
482  inputParams.m_OutputLayerNormWeights = &outputLayerNormTensor;
483  }
484 
485 
486  visitor.VisitLstmLayer(this, GetParameters(), inputParams, GetName());
487 }
std::unique_ptr< ScopedCpuTensorHandle > m_ForgetGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:69
std::unique_ptr< ScopedCpuTensorHandle > m_InputToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:61
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:65
LstmBasicParameters m_BasicParameters
Definition: LstmLayer.hpp:81
std::unique_ptr< ScopedCpuTensorHandle > m_InputToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:29
std::unique_ptr< ScopedCpuTensorHandle > m_CellLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:21
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:63
std::unique_ptr< ScopedCpuTensorHandle > m_OutputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:73
std::unique_ptr< ScopedCpuTensorHandle > m_InputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:17
std::unique_ptr< ScopedCpuTensorHandle > m_CellBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:71
std::unique_ptr< ScopedCpuTensorHandle > m_CellToForgetWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:49
std::unique_ptr< ScopedCpuTensorHandle > m_OutputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:23
std::unique_ptr< ScopedCpuTensorHandle > m_CellToInputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:47
LstmOptLayerNormParameters m_LayerNormParameters
Definition: LstmLayer.hpp:85
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:31
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:67
LstmOptPeepholeParameters m_PeepholeParameters
Definition: LstmLayer.hpp:84
LstmOptProjectionParameters m_ProjectionParameters
Definition: LstmLayer.hpp:83
std::unique_ptr< ScopedCpuTensorHandle > m_ProjectionBias
A unique pointer to represent 1D weights tensor with dimensions [output_size].
Definition: LstmLayer.hpp:41
std::unique_ptr< ScopedCpuTensorHandle > m_InputToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:59
std::unique_ptr< ScopedCpuTensorHandle > m_CellToOutputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:51
std::unique_ptr< ScopedCpuTensorHandle > m_ProjectionWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:39
std::unique_ptr< ScopedCpuTensorHandle > m_ForgetLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:19
LstmOptCifgParameters m_CifgParameters
Definition: LstmLayer.hpp:82
const char * GetName() const override
Returns the name of the layer.
Definition: Layer.hpp:305
std::unique_ptr< ScopedCpuTensorHandle > m_InputToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:57
std::unique_ptr< ScopedCpuTensorHandle > m_InputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:33

◆ Clone()

LstmLayer * Clone ( Graph graph) const
overridevirtual

Creates a dynamically-allocated copy of this layer.

Parameters
[in]graphThe graph into which this layer is being cloned.

Implements Layer.

Definition at line 78 of file LstmLayer.cpp.

References Layer::GetName(), LstmLayer::m_BasicParameters, LstmBasicParameters::m_CellBias, LstmOptLayerNormParameters::m_CellLayerNormWeights, LstmOptPeepholeParameters::m_CellToForgetWeights, LstmOptPeepholeParameters::m_CellToInputWeights, LstmOptPeepholeParameters::m_CellToOutputWeights, LstmLayer::m_CifgParameters, LstmBasicParameters::m_ForgetGateBias, LstmOptLayerNormParameters::m_ForgetLayerNormWeights, LstmOptCifgParameters::m_InputGateBias, LstmOptLayerNormParameters::m_InputLayerNormWeights, LstmBasicParameters::m_InputToCellWeights, LstmBasicParameters::m_InputToForgetWeights, LstmOptCifgParameters::m_InputToInputWeights, LstmBasicParameters::m_InputToOutputWeights, LstmLayer::m_LayerNormParameters, LstmBasicParameters::m_OutputGateBias, LstmOptLayerNormParameters::m_OutputLayerNormWeights, LayerWithParameters< LstmDescriptor >::m_Param, LstmLayer::m_PeepholeParameters, LstmOptProjectionParameters::m_ProjectionBias, LstmLayer::m_ProjectionParameters, LstmOptProjectionParameters::m_ProjectionWeights, LstmBasicParameters::m_RecurrentToCellWeights, LstmBasicParameters::m_RecurrentToForgetWeights, LstmOptCifgParameters::m_RecurrentToInputWeights, and LstmBasicParameters::m_RecurrentToOutputWeights.

79 {
80  auto layer = CloneBase<LstmLayer>(graph, m_Param, GetName());
81 
82  layer->m_BasicParameters.m_InputToForgetWeights = m_BasicParameters.m_InputToForgetWeights ?
83  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_InputToForgetWeights)
84  : nullptr;
85  layer->m_BasicParameters.m_InputToCellWeights = m_BasicParameters.m_InputToCellWeights ?
86  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_InputToCellWeights) : nullptr;
87  layer->m_BasicParameters.m_InputToOutputWeights = m_BasicParameters.m_InputToOutputWeights ?
88  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_InputToOutputWeights) : nullptr;
89  layer->m_BasicParameters.m_RecurrentToForgetWeights = m_BasicParameters.m_RecurrentToForgetWeights ?
90  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_RecurrentToForgetWeights) : nullptr;
91  layer->m_BasicParameters.m_RecurrentToCellWeights = m_BasicParameters.m_RecurrentToCellWeights ?
92  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_RecurrentToCellWeights) : nullptr;
93  layer->m_BasicParameters.m_RecurrentToOutputWeights = m_BasicParameters.m_RecurrentToOutputWeights ?
94  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_RecurrentToOutputWeights) : nullptr;
95  layer->m_BasicParameters.m_ForgetGateBias = m_BasicParameters.m_ForgetGateBias ?
96  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_ForgetGateBias) : nullptr;
97  layer->m_BasicParameters.m_CellBias = m_BasicParameters.m_CellBias ?
98  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_CellBias) : nullptr;
99  layer->m_BasicParameters.m_OutputGateBias = m_BasicParameters.m_OutputGateBias ?
100  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_OutputGateBias) : nullptr;
101 
102  if (!m_Param.m_CifgEnabled)
103  {
104  layer->m_CifgParameters.m_InputToInputWeights = m_CifgParameters.m_InputToInputWeights ?
105  std::make_unique<ScopedCpuTensorHandle>(*m_CifgParameters.m_InputToInputWeights) : nullptr;
106  layer->m_CifgParameters.m_RecurrentToInputWeights = m_CifgParameters.m_RecurrentToInputWeights ?
107  std::make_unique<ScopedCpuTensorHandle>(*m_CifgParameters.m_RecurrentToInputWeights) : nullptr;
108  layer->m_CifgParameters.m_InputGateBias = m_CifgParameters.m_InputGateBias ?
109  std::make_unique<ScopedCpuTensorHandle>(*m_CifgParameters.m_InputGateBias) : nullptr;
110  }
111 
112  if (m_Param.m_ProjectionEnabled)
113  {
114  layer->m_ProjectionParameters.m_ProjectionWeights = m_ProjectionParameters.m_ProjectionWeights ?
115  std::make_unique<ScopedCpuTensorHandle>(*m_ProjectionParameters.m_ProjectionWeights) : nullptr;
116  layer->m_ProjectionParameters.m_ProjectionBias = m_ProjectionParameters.m_ProjectionBias ?
117  std::make_unique<ScopedCpuTensorHandle>(*m_ProjectionParameters.m_ProjectionBias) : nullptr;
118  }
119 
120  if (m_Param.m_PeepholeEnabled)
121  {
122  if (!m_Param.m_CifgEnabled)
123  {
124  layer->m_PeepholeParameters.m_CellToInputWeights = m_PeepholeParameters.m_CellToInputWeights ?
125  std::make_unique<ScopedCpuTensorHandle>(*m_PeepholeParameters.m_CellToInputWeights) : nullptr;
126  }
127  layer->m_PeepholeParameters.m_CellToForgetWeights = m_PeepholeParameters.m_CellToForgetWeights ?
128  std::make_unique<ScopedCpuTensorHandle>(*m_PeepholeParameters.m_CellToForgetWeights) : nullptr;
129  layer->m_PeepholeParameters.m_CellToOutputWeights = m_PeepholeParameters.m_CellToOutputWeights ?
130  std::make_unique<ScopedCpuTensorHandle>(*m_PeepholeParameters.m_CellToOutputWeights) : nullptr;
131  }
132 
133  if (m_Param.m_LayerNormEnabled)
134  {
135  layer->m_LayerNormParameters.m_InputLayerNormWeights = m_LayerNormParameters.m_InputLayerNormWeights ?
136  std::make_unique<ScopedCpuTensorHandle>(*m_LayerNormParameters.m_InputLayerNormWeights) : nullptr;
137  layer->m_LayerNormParameters.m_ForgetLayerNormWeights = m_LayerNormParameters.m_ForgetLayerNormWeights ?
138  std::make_unique<ScopedCpuTensorHandle>(*m_LayerNormParameters.m_ForgetLayerNormWeights) : nullptr;
139  layer->m_LayerNormParameters.m_CellLayerNormWeights = m_LayerNormParameters.m_CellLayerNormWeights ?
140  std::make_unique<ScopedCpuTensorHandle>(*m_LayerNormParameters.m_CellLayerNormWeights) : nullptr;
141  layer->m_LayerNormParameters.m_OutputLayerNormWeights = m_LayerNormParameters.m_OutputLayerNormWeights ?
142  std::make_unique<ScopedCpuTensorHandle>(*m_LayerNormParameters.m_OutputLayerNormWeights) : nullptr;
143  }
144 
145  return std::move(layer);
146 }
std::unique_ptr< ScopedCpuTensorHandle > m_ForgetGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:69
std::unique_ptr< ScopedCpuTensorHandle > m_InputToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:61
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:65
LstmBasicParameters m_BasicParameters
Definition: LstmLayer.hpp:81
LstmDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).
std::unique_ptr< ScopedCpuTensorHandle > m_InputToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:29
std::unique_ptr< ScopedCpuTensorHandle > m_CellLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:21
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:63
std::unique_ptr< ScopedCpuTensorHandle > m_OutputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:73
std::unique_ptr< ScopedCpuTensorHandle > m_InputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:17
std::unique_ptr< ScopedCpuTensorHandle > m_CellBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:71
std::unique_ptr< ScopedCpuTensorHandle > m_CellToForgetWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:49
std::unique_ptr< ScopedCpuTensorHandle > m_OutputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:23
std::unique_ptr< ScopedCpuTensorHandle > m_CellToInputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:47
LstmOptLayerNormParameters m_LayerNormParameters
Definition: LstmLayer.hpp:85
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:31
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:67
LstmOptPeepholeParameters m_PeepholeParameters
Definition: LstmLayer.hpp:84
LstmOptProjectionParameters m_ProjectionParameters
Definition: LstmLayer.hpp:83
std::unique_ptr< ScopedCpuTensorHandle > m_ProjectionBias
A unique pointer to represent 1D weights tensor with dimensions [output_size].
Definition: LstmLayer.hpp:41
std::unique_ptr< ScopedCpuTensorHandle > m_InputToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:59
std::unique_ptr< ScopedCpuTensorHandle > m_CellToOutputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:51
std::unique_ptr< ScopedCpuTensorHandle > m_ProjectionWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:39
std::unique_ptr< ScopedCpuTensorHandle > m_ForgetLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:19
LstmOptCifgParameters m_CifgParameters
Definition: LstmLayer.hpp:82
const char * GetName() const override
Returns the name of the layer.
Definition: Layer.hpp:305
std::unique_ptr< ScopedCpuTensorHandle > m_InputToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:57
std::unique_ptr< ScopedCpuTensorHandle > m_InputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:33

◆ CreateWorkload()

std::unique_ptr< IWorkload > CreateWorkload ( const IWorkloadFactory factory) const
overridevirtual

Makes a workload for the LSTM type.

Parameters
[in]graphThe graph where this layer can be found.
[in]factoryThe workload factory which will create the workload.
Returns
A pointer to the created workload, or nullptr if not created.

Implements Layer.

Definition at line 22 of file LstmLayer.cpp.

References IWorkloadFactory::CreateLstm(), LstmLayer::m_BasicParameters, LstmBasicParameters::m_CellBias, LstmQueueDescriptor::m_CellBias, LstmOptLayerNormParameters::m_CellLayerNormWeights, LstmQueueDescriptor::m_CellLayerNormWeights, LstmOptPeepholeParameters::m_CellToForgetWeights, LstmQueueDescriptor::m_CellToForgetWeights, LstmOptPeepholeParameters::m_CellToInputWeights, LstmQueueDescriptor::m_CellToInputWeights, LstmOptPeepholeParameters::m_CellToOutputWeights, LstmQueueDescriptor::m_CellToOutputWeights, LstmDescriptor::m_CifgEnabled, LstmLayer::m_CifgParameters, LstmBasicParameters::m_ForgetGateBias, LstmQueueDescriptor::m_ForgetGateBias, LstmOptLayerNormParameters::m_ForgetLayerNormWeights, LstmQueueDescriptor::m_ForgetLayerNormWeights, LstmOptCifgParameters::m_InputGateBias, LstmQueueDescriptor::m_InputGateBias, LstmOptLayerNormParameters::m_InputLayerNormWeights, LstmQueueDescriptor::m_InputLayerNormWeights, LstmBasicParameters::m_InputToCellWeights, LstmQueueDescriptor::m_InputToCellWeights, LstmBasicParameters::m_InputToForgetWeights, LstmQueueDescriptor::m_InputToForgetWeights, LstmOptCifgParameters::m_InputToInputWeights, LstmQueueDescriptor::m_InputToInputWeights, LstmBasicParameters::m_InputToOutputWeights, LstmQueueDescriptor::m_InputToOutputWeights, LstmDescriptor::m_LayerNormEnabled, LstmLayer::m_LayerNormParameters, LstmBasicParameters::m_OutputGateBias, LstmQueueDescriptor::m_OutputGateBias, LstmOptLayerNormParameters::m_OutputLayerNormWeights, LstmQueueDescriptor::m_OutputLayerNormWeights, LayerWithParameters< LstmDescriptor >::m_Param, LstmDescriptor::m_PeepholeEnabled, LstmLayer::m_PeepholeParameters, LstmOptProjectionParameters::m_ProjectionBias, LstmQueueDescriptor::m_ProjectionBias, LstmDescriptor::m_ProjectionEnabled, LstmLayer::m_ProjectionParameters, LstmOptProjectionParameters::m_ProjectionWeights, LstmQueueDescriptor::m_ProjectionWeights, LstmBasicParameters::m_RecurrentToCellWeights, LstmQueueDescriptor::m_RecurrentToCellWeights, LstmBasicParameters::m_RecurrentToForgetWeights, LstmQueueDescriptor::m_RecurrentToForgetWeights, LstmOptCifgParameters::m_RecurrentToInputWeights, LstmQueueDescriptor::m_RecurrentToInputWeights, LstmBasicParameters::m_RecurrentToOutputWeights, LstmQueueDescriptor::m_RecurrentToOutputWeights, and LayerWithParameters< LstmDescriptor >::PrepInfoAndDesc().

23 {
24  LstmQueueDescriptor descriptor;
25 
26  // Basic parameters
27  descriptor.m_InputToForgetWeights = m_BasicParameters.m_InputToForgetWeights.get();
28  descriptor.m_InputToCellWeights = m_BasicParameters.m_InputToCellWeights.get();
29  descriptor.m_InputToOutputWeights = m_BasicParameters.m_InputToOutputWeights.get();
30  descriptor.m_RecurrentToForgetWeights = m_BasicParameters.m_RecurrentToForgetWeights.get();
31  descriptor.m_RecurrentToCellWeights = m_BasicParameters.m_RecurrentToCellWeights.get();
32  descriptor.m_RecurrentToOutputWeights = m_BasicParameters.m_RecurrentToOutputWeights.get();
33  descriptor.m_ForgetGateBias = m_BasicParameters.m_ForgetGateBias.get();
34  descriptor.m_CellBias = m_BasicParameters.m_CellBias.get();
35  descriptor.m_OutputGateBias = m_BasicParameters.m_OutputGateBias.get();
36 
37  // Cifg parameters
39  {
40  descriptor.m_InputToInputWeights = m_CifgParameters.m_InputToInputWeights.get();
41  descriptor.m_RecurrentToInputWeights = m_CifgParameters.m_RecurrentToInputWeights.get();
42  descriptor.m_InputGateBias = m_CifgParameters.m_InputGateBias.get();
43  }
44 
45  // Projection parameters
47  {
48  descriptor.m_ProjectionWeights = m_ProjectionParameters.m_ProjectionWeights.get();
49  descriptor.m_ProjectionBias = m_ProjectionParameters.m_ProjectionBias.get();
50  }
51 
52  // Peephole parameters
54  {
56  {
57  descriptor.m_CellToInputWeights = m_PeepholeParameters.m_CellToInputWeights.get();
58  }
59  descriptor.m_CellToForgetWeights = m_PeepholeParameters.m_CellToForgetWeights.get();
60  descriptor.m_CellToOutputWeights = m_PeepholeParameters.m_CellToOutputWeights.get();
61  }
62 
63  // Layer normalisation parameters
65  {
67  {
68  descriptor.m_InputLayerNormWeights = m_LayerNormParameters.m_InputLayerNormWeights.get();
69  }
70  descriptor.m_ForgetLayerNormWeights = m_LayerNormParameters.m_ForgetLayerNormWeights.get();
71  descriptor.m_CellLayerNormWeights = m_LayerNormParameters.m_CellLayerNormWeights.get();
72  descriptor.m_OutputLayerNormWeights = m_LayerNormParameters.m_OutputLayerNormWeights.get();
73  }
74 
75  return factory.CreateLstm(descriptor, PrepInfoAndDesc(descriptor));
76 }
std::unique_ptr< ScopedCpuTensorHandle > m_ForgetGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:69
std::unique_ptr< ScopedCpuTensorHandle > m_InputToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:61
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:65
bool m_ProjectionEnabled
Enable/disable the projection layer.
LstmBasicParameters m_BasicParameters
Definition: LstmLayer.hpp:81
LstmDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).
std::unique_ptr< ScopedCpuTensorHandle > m_InputToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:29
std::unique_ptr< ScopedCpuTensorHandle > m_CellLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:21
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:63
std::unique_ptr< ScopedCpuTensorHandle > m_OutputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:73
std::unique_ptr< ScopedCpuTensorHandle > m_InputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:17
std::unique_ptr< ScopedCpuTensorHandle > m_CellBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:71
std::unique_ptr< ScopedCpuTensorHandle > m_CellToForgetWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:49
std::unique_ptr< ScopedCpuTensorHandle > m_OutputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:23
std::unique_ptr< ScopedCpuTensorHandle > m_CellToInputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:47
bool m_PeepholeEnabled
Enable/disable peephole.
LstmOptLayerNormParameters m_LayerNormParameters
Definition: LstmLayer.hpp:85
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:31
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:67
LstmOptPeepholeParameters m_PeepholeParameters
Definition: LstmLayer.hpp:84
LstmOptProjectionParameters m_ProjectionParameters
Definition: LstmLayer.hpp:83
std::unique_ptr< ScopedCpuTensorHandle > m_ProjectionBias
A unique pointer to represent 1D weights tensor with dimensions [output_size].
Definition: LstmLayer.hpp:41
bool m_CifgEnabled
Enable/disable cifg (coupled input & forget gate).
std::unique_ptr< ScopedCpuTensorHandle > m_InputToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:59
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *LayerCreateWorkload.
std::unique_ptr< ScopedCpuTensorHandle > m_CellToOutputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:51
bool m_LayerNormEnabled
Enable/disable layer normalization.
std::unique_ptr< ScopedCpuTensorHandle > m_ProjectionWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:39
std::unique_ptr< ScopedCpuTensorHandle > m_ForgetLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:19
LstmOptCifgParameters m_CifgParameters
Definition: LstmLayer.hpp:82
std::unique_ptr< ScopedCpuTensorHandle > m_InputToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:57
std::unique_ptr< ScopedCpuTensorHandle > m_InputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:33

◆ GetConstantTensorsByRef()

Layer::ConstantTensors GetConstantTensorsByRef ( )
overrideprotectedvirtual

Retrieve the handles to the constant values stored by the layer.

Returns
A vector of the constant tensors stored by this layer.

Reimplemented from Layer.

Definition at line 276 of file LstmLayer.cpp.

References LstmLayer::m_BasicParameters, LstmBasicParameters::m_CellBias, LstmOptLayerNormParameters::m_CellLayerNormWeights, LstmOptPeepholeParameters::m_CellToForgetWeights, LstmOptPeepholeParameters::m_CellToInputWeights, LstmOptPeepholeParameters::m_CellToOutputWeights, LstmLayer::m_CifgParameters, LstmBasicParameters::m_ForgetGateBias, LstmOptLayerNormParameters::m_ForgetLayerNormWeights, LstmOptCifgParameters::m_InputGateBias, LstmOptLayerNormParameters::m_InputLayerNormWeights, LstmBasicParameters::m_InputToCellWeights, LstmBasicParameters::m_InputToForgetWeights, LstmOptCifgParameters::m_InputToInputWeights, LstmBasicParameters::m_InputToOutputWeights, LstmLayer::m_LayerNormParameters, LstmBasicParameters::m_OutputGateBias, LstmOptLayerNormParameters::m_OutputLayerNormWeights, LstmLayer::m_PeepholeParameters, LstmOptProjectionParameters::m_ProjectionBias, LstmLayer::m_ProjectionParameters, LstmOptProjectionParameters::m_ProjectionWeights, LstmBasicParameters::m_RecurrentToCellWeights, LstmBasicParameters::m_RecurrentToForgetWeights, LstmOptCifgParameters::m_RecurrentToInputWeights, and LstmBasicParameters::m_RecurrentToOutputWeights.

277 {
287 
288  // Cifg parameters
292 
293  // Projection parameters
296 
297  // Peephole parameters
301 
302  // Layer normalisation parameters
307 }
std::unique_ptr< ScopedCpuTensorHandle > m_ForgetGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:69
std::unique_ptr< ScopedCpuTensorHandle > m_InputToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:61
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:65
LstmBasicParameters m_BasicParameters
Definition: LstmLayer.hpp:81
std::unique_ptr< ScopedCpuTensorHandle > m_InputToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:29
std::unique_ptr< ScopedCpuTensorHandle > m_CellLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:21
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:63
std::unique_ptr< ScopedCpuTensorHandle > m_OutputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:73
std::unique_ptr< ScopedCpuTensorHandle > m_InputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:17
std::unique_ptr< ScopedCpuTensorHandle > m_CellBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:71
std::unique_ptr< ScopedCpuTensorHandle > m_CellToForgetWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:49
std::unique_ptr< ScopedCpuTensorHandle > m_OutputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:23
std::unique_ptr< ScopedCpuTensorHandle > m_CellToInputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:47
LstmOptLayerNormParameters m_LayerNormParameters
Definition: LstmLayer.hpp:85
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:31
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:67
LstmOptPeepholeParameters m_PeepholeParameters
Definition: LstmLayer.hpp:84
LstmOptProjectionParameters m_ProjectionParameters
Definition: LstmLayer.hpp:83
std::unique_ptr< ScopedCpuTensorHandle > m_ProjectionBias
A unique pointer to represent 1D weights tensor with dimensions [output_size].
Definition: LstmLayer.hpp:41
std::unique_ptr< ScopedCpuTensorHandle > m_InputToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:59
std::unique_ptr< ScopedCpuTensorHandle > m_CellToOutputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:51
std::unique_ptr< ScopedCpuTensorHandle > m_ProjectionWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:39
std::unique_ptr< ScopedCpuTensorHandle > m_ForgetLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:19
LstmOptCifgParameters m_CifgParameters
Definition: LstmLayer.hpp:82
std::unique_ptr< ScopedCpuTensorHandle > m_InputToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:57
std::unique_ptr< ScopedCpuTensorHandle > m_InputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:33

◆ InferOutputShapes()

std::vector< TensorShape > InferOutputShapes ( const std::vector< TensorShape > &  inputShapes) const
overridevirtual

By default returns inputShapes if the number of inputs are equal to number of outputs, otherwise infers the output shapes from given input shapes and layer properties.

Parameters
[in]inputShapesThe input shapes layer has.
Returns
A vector to the inferred output shape.

Reimplemented from Layer.

Definition at line 148 of file LstmLayer.cpp.

References ARMNN_ASSERT, LstmDescriptor::m_CifgEnabled, and LayerWithParameters< LstmDescriptor >::m_Param.

Referenced by LstmLayer::ValidateTensorShapesFromInputs().

149 {
150  ARMNN_ASSERT(inputShapes.size() == 3);
151 
152  // Get input values for validation
153  unsigned int batchSize = inputShapes[0][0];
154  unsigned int outputSize = inputShapes[1][1];
155  unsigned int numUnits = inputShapes[2][1];
156 
157  std::vector<TensorShape> outShapes;
158  outShapes.push_back(TensorShape({batchSize, numUnits * (m_Param.m_CifgEnabled ? 3 : 4)}));
159  outShapes.push_back(TensorShape({batchSize, outputSize}));
160  outShapes.push_back(TensorShape({batchSize, numUnits}));
161  outShapes.push_back(TensorShape({batchSize, outputSize}));
162 
163  return outShapes;
164 }
LstmDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
bool m_CifgEnabled
Enable/disable cifg (coupled input & forget gate).

◆ ValidateTensorShapesFromInputs()

void ValidateTensorShapesFromInputs ( )
overridevirtual

Check if the input tensor shape(s) will lead to a valid configuration of LstmLayer.

Implements Layer.

Definition at line 166 of file LstmLayer.cpp.

References ARMNN_ASSERT, ARMNN_ASSERT_MSG, CHECK_LOCATION, InputSlot::GetConnection(), Layer::GetInputSlot(), Layer::GetOutputSlot(), TensorInfo::GetShape(), IOutputSlot::GetTensorInfo(), OutputSlot::GetTensorInfo(), LstmLayer::InferOutputShapes(), LstmLayer::m_BasicParameters, LstmBasicParameters::m_CellBias, LstmOptLayerNormParameters::m_CellLayerNormWeights, LstmOptPeepholeParameters::m_CellToForgetWeights, LstmOptPeepholeParameters::m_CellToInputWeights, LstmOptPeepholeParameters::m_CellToOutputWeights, LstmDescriptor::m_CifgEnabled, LstmLayer::m_CifgParameters, LstmBasicParameters::m_ForgetGateBias, LstmOptLayerNormParameters::m_ForgetLayerNormWeights, LstmOptCifgParameters::m_InputGateBias, LstmOptLayerNormParameters::m_InputLayerNormWeights, LstmBasicParameters::m_InputToCellWeights, LstmBasicParameters::m_InputToForgetWeights, LstmOptCifgParameters::m_InputToInputWeights, LstmBasicParameters::m_InputToOutputWeights, LstmDescriptor::m_LayerNormEnabled, LstmLayer::m_LayerNormParameters, LstmBasicParameters::m_OutputGateBias, LstmOptLayerNormParameters::m_OutputLayerNormWeights, LayerWithParameters< LstmDescriptor >::m_Param, LstmDescriptor::m_PeepholeEnabled, LstmLayer::m_PeepholeParameters, LstmDescriptor::m_ProjectionEnabled, LstmLayer::m_ProjectionParameters, LstmOptProjectionParameters::m_ProjectionWeights, LstmBasicParameters::m_RecurrentToCellWeights, LstmBasicParameters::m_RecurrentToForgetWeights, LstmOptCifgParameters::m_RecurrentToInputWeights, LstmBasicParameters::m_RecurrentToOutputWeights, and Layer::VerifyLayerConnections().

167 {
169 
170  auto inferredShapes = InferOutputShapes( {
174  );
175 
176  ARMNN_ASSERT(inferredShapes.size() == 4);
177 
178  // Check if the weights are nullptr
180  "LstmLayer: m_BasicParameters.m_InputToForgetWeights should not be null.");
182  "LstmLayer: m_BasicParameters.m_InputToCellWeights should not be null.");
184  "LstmLayer: m_BasicParameters.m_InputToOutputWeights should not be null.");
186  "LstmLayer: m_BasicParameters.m_RecurrentToForgetWeights should not be null.");
188  "LstmLayer: m_BasicParameters.m_RecurrentToCellWeights should not be null.");
190  "LstmLayer: m_BasicParameters.m_RecurrentToOutputWeights should not be null.");
192  "LstmLayer: m_BasicParameters.m_ForgetGateBias should not be null.");
194  "LstmLayer: m_BasicParameters.m_CellBias should not be null.");
196  "LstmLayer: m_BasicParameters.m_OutputGateBias should not be null.");
197 
198  if (!m_Param.m_CifgEnabled)
199  {
201  "LstmLayer: m_CifgParameters.m_InputToInputWeights should not be null.");
203  "LstmLayer: m_CifgParameters.m_RecurrentToInputWeights should not be null.");
205  "LstmLayer: m_CifgParameters.m_InputGateBias should not be null.");
206 
207  ConditionalThrowIfNotEqual<LayerValidationException>(
208  "LstmLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
210  inferredShapes[0]);
211  }
212  else
213  {
215  "LstmLayer: m_CifgParameters.m_InputToInputWeights should not have a value when CIFG is enabled.");
217  "LstmLayer: m_CifgParameters.m_RecurrentToInputWeights should not have a value when CIFG is enabled.");
219  "LstmLayer: m_CifgParameters.m_InputGateBias should not have a value when CIFG is enabled.");
220 
221  ConditionalThrowIfNotEqual<LayerValidationException>(
222  "LstmLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
224  inferredShapes[0]);
225  }
226 
228  {
230  "LstmLayer: m_ProjectionParameters.m_ProjectionWeights should not be null.");
231  }
232 
234  {
235  if (!m_Param.m_CifgEnabled)
236  {
238  "LstmLayer: m_PeepholeParameters.m_CellToInputWeights should not be null "
239  "when Peephole is enabled and CIFG is disabled.");
240  }
242  "LstmLayer: m_PeepholeParameters.m_CellToForgetWeights should not be null.");
244  "LstmLayer: m_PeepholeParameters.m_CellToOutputWeights should not be null.");
245  }
246 
247  ConditionalThrowIfNotEqual<LayerValidationException>(
248  "LstmLayer: TensorShape set on OutputSlot[1] does not match the inferred shape.",
250  inferredShapes[1]);
251  ConditionalThrowIfNotEqual<LayerValidationException>(
252  "LstmLayer: TensorShape set on OutputSlot[2] does not match the inferred shape.",
254  inferredShapes[2]);
255  ConditionalThrowIfNotEqual<LayerValidationException>(
256  "LstmLayer: TensorShape set on OutputSlot[3] does not match the inferred shape.",
258  inferredShapes[3]);
259 
261  {
263  {
265  "LstmLayer: m_LayerNormParameters.m_inputLayerNormWeights should not be null.");
266  }
268  "LstmLayer: m_LayerNormParameters.m_forgetLayerNormWeights should not be null.");
270  "LstmLayer: m_LayerNormParameters.m_cellLayerNormWeights should not be null.");
272  "LstmLayer: m_LayerNormParameters.m_outputLayerNormWeights should not be null.");
273  }
274 }
std::unique_ptr< ScopedCpuTensorHandle > m_ForgetGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:69
std::unique_ptr< ScopedCpuTensorHandle > m_InputToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:61
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:65
bool m_ProjectionEnabled
Enable/disable the projection layer.
LstmBasicParameters m_BasicParameters
Definition: LstmLayer.hpp:81
LstmDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).
const TensorShape & GetShape() const
Definition: Tensor.hpp:88
std::unique_ptr< ScopedCpuTensorHandle > m_InputToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:29
std::unique_ptr< ScopedCpuTensorHandle > m_CellLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:21
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:63
std::unique_ptr< ScopedCpuTensorHandle > m_OutputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:73
std::unique_ptr< ScopedCpuTensorHandle > m_InputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:17
const IOutputSlot * GetConnection() const override
Definition: Layer.hpp:199
std::unique_ptr< ScopedCpuTensorHandle > m_CellBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:71
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
Definition: Layer.cpp:339
std::unique_ptr< ScopedCpuTensorHandle > m_CellToForgetWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:49
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Definition: Layer.hpp:310
std::unique_ptr< ScopedCpuTensorHandle > m_OutputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:23
#define ARMNN_ASSERT_MSG(COND, MSG)
Definition: Assert.hpp:15
std::unique_ptr< ScopedCpuTensorHandle > m_CellToInputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:47
bool m_PeepholeEnabled
Enable/disable peephole.
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
LstmOptLayerNormParameters m_LayerNormParameters
Definition: LstmLayer.hpp:85
#define CHECK_LOCATION()
Definition: Exceptions.hpp:192
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:31
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:67
LstmOptPeepholeParameters m_PeepholeParameters
Definition: LstmLayer.hpp:84
LstmOptProjectionParameters m_ProjectionParameters
Definition: LstmLayer.hpp:83
bool m_CifgEnabled
Enable/disable cifg (coupled input & forget gate).
std::unique_ptr< ScopedCpuTensorHandle > m_InputToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:59
std::unique_ptr< ScopedCpuTensorHandle > m_CellToOutputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:51
bool m_LayerNormEnabled
Enable/disable layer normalization.
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
Definition: Layer.hpp:312
std::unique_ptr< ScopedCpuTensorHandle > m_ProjectionWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:39
virtual const TensorInfo & GetTensorInfo() const =0
std::unique_ptr< ScopedCpuTensorHandle > m_ForgetLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:19
LstmOptCifgParameters m_CifgParameters
Definition: LstmLayer.hpp:82
std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const override
By default returns inputShapes if the number of inputs are equal to number of outputs, otherwise infers the output shapes from given input shapes and layer properties.
Definition: LstmLayer.cpp:148
const TensorInfo & GetTensorInfo() const override
Definition: Layer.cpp:63
std::unique_ptr< ScopedCpuTensorHandle > m_InputToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:57
std::unique_ptr< ScopedCpuTensorHandle > m_InputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:33

Member Data Documentation

◆ m_BasicParameters

◆ m_CifgParameters

◆ m_LayerNormParameters

◆ m_PeepholeParameters

◆ m_ProjectionParameters


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