ArmNN
 26.01
Loading...
Searching...
No Matches
LstmLayer Class Reference

This layer represents a LSTM operation. More...

#include <LstmLayer.hpp>

Inheritance diagram for LstmLayer:
[legend]
Collaboration diagram for LstmLayer:
[legend]

Public Member Functions

virtual std::unique_ptr< IWorkloadCreateWorkload (const IWorkloadFactory &factory) const override
 Makes a workload for the LSTM type.
 
LstmLayerClone (Graph &graph) const override
 Creates a dynamically-allocated copy of this layer.
 
void ValidateTensorShapesFromInputs () override
 Check if the input tensor shape(s) will lead to a valid configuration of LstmLayer.
 
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.
 
void ExecuteStrategy (IStrategy &strategy) const override
 Apply a visitor to this layer.
 
- Public Member Functions inherited from LayerWithParameters< LstmDescriptor >
const LstmDescriptorGetParameters () const override
 If the layer has a descriptor return it.
 
void SerializeLayerParameters (ParameterStringifyFunction &fn) const override
 Helper to serialize the layer parameters to string (currently used in DotSerializer and company).
 
- 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)
 
ShapeInferenceMethod GetShapeInferenceMethod () const
 
bool GetAllowExpandedDims () const
 
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 override
 Returns the armnn::LayerType of this layer.
 
DataType GetDataType () const
 
const BackendIdGetBackendId () const
 
void SetBackendId (const BackendId &id) override
 Set the backend of the IConnectableLayer.
 
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.
 
unsigned int GetNumInputSlots () const override
 Returns the number of connectable input slots.
 
unsigned int GetNumOutputSlots () const override
 Returns the number of connectable output slots.
 
const InputSlotGetInputSlot (unsigned int index) const override
 Get a const input slot handle by slot index.
 
InputSlotGetInputSlot (unsigned int index) override
 Get the input slot handle by slot index.
 
const OutputSlotGetOutputSlot (unsigned int index=0) const override
 Get the const output slot handle by slot index.
 
OutputSlotGetOutputSlot (unsigned int index=0) override
 Get the output slot handle by slot index.
 
void SetGuid (LayerGuid guid)
 
LayerGuid GetGuid () const final
 Returns the unique id of the layer.
 
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.
 
Optional< BackendIdGetBackendHint () const
 
void SetShapeInferenceMethod (ShapeInferenceMethod shapeInferenceMethod)
 
void SetAllowExpandedDims (bool allowExpandedDims)
 
template<typename T >
std::shared_ptr< T > GetAdditionalInformation () const
 
void SetAdditionalInfoForObject (const AdditionalInfoObjectPtr &additionalInfo)
 

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.
 
 ~LstmLayer ()=default
 Default destructor.
 
Layer::ImmutableConstantTensors GetConstantTensorsByRef () const override
 Retrieve the handles to the constant values stored by the layer.
 
- 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.
 
Layer::ImmutableConstantTensors GetConnectedConstantAsInputTensors () const
 
- 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
 
void ValidateAndCopyShape (const TensorShape &outputShape, const TensorShape &inferredShape, const ShapeInferenceMethod shapeInferenceMethod, const std::string &layerName, const unsigned int outputSlotIndex=0)
 
void VerifyShapeInferenceType (const TensorShape &outputShape, ShapeInferenceMethod shapeInferenceMethod)
 
template<typename QueueDescriptor >
WorkloadInfo PrepInfoAndDesc (QueueDescriptor &descriptor) const
 Helper function to reduce duplication in *LayerCreateWorkload.
 
template<typename LayerType , typename ... Params>
LayerTypeCloneBase (Graph &graph, Params &&... params) const
 
virtual ConstantTensors GetConstantTensorsByRef () override final
 
void SetAdditionalInfo (QueueDescriptor &descriptor) const
 
- Protected Member Functions inherited from IConnectableLayer
 ~IConnectableLayer ()
 Objects are not deletable via the handle.
 

Additional Inherited Members

- Public Types inherited from LayerWithParameters< LstmDescriptor >
using DescriptorType
 
- Public Types inherited from IConnectableLayer
using ConstantTensors = std::vector<std::reference_wrapper<std::shared_ptr<ConstTensorHandle>>>
 
using ImmutableConstantTensors = std::vector<std::reference_wrapper<const std::shared_ptr<ConstTensorHandle>>>
 
- Protected Attributes inherited from LayerWithParameters< LstmDescriptor >
LstmDescriptor m_Param
 The parameters for the layer (not including tensor-valued weights etc.).
 
- Protected Attributes inherited from Layer
AdditionalInfoObjectPtr m_AdditionalInfoObject
 
std::vector< OutputHandlerm_OutputHandlers
 
ShapeInferenceMethod m_ShapeInferenceMethod
 

Detailed Description

This layer represents a LSTM operation.

Definition at line 16 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.

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

◆ 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 80 of file LstmLayer.cpp.

81{
82 auto layer = CloneBase<LstmLayer>(graph, m_Param, GetName());
83
84 layer->m_BasicParameters.m_InputToForgetWeights = m_BasicParameters.m_InputToForgetWeights ?
86 : nullptr;
87 layer->m_BasicParameters.m_InputToCellWeights = m_BasicParameters.m_InputToCellWeights ?
89 layer->m_BasicParameters.m_InputToOutputWeights = m_BasicParameters.m_InputToOutputWeights ?
91 layer->m_BasicParameters.m_RecurrentToForgetWeights = m_BasicParameters.m_RecurrentToForgetWeights ?
93 layer->m_BasicParameters.m_RecurrentToCellWeights = m_BasicParameters.m_RecurrentToCellWeights ?
95 layer->m_BasicParameters.m_RecurrentToOutputWeights = m_BasicParameters.m_RecurrentToOutputWeights ?
97 layer->m_BasicParameters.m_ForgetGateBias = m_BasicParameters.m_ForgetGateBias ?
99 layer->m_BasicParameters.m_CellBias = m_BasicParameters.m_CellBias ?
101 layer->m_BasicParameters.m_OutputGateBias = m_BasicParameters.m_OutputGateBias ?
103
105 {
106 layer->m_CifgParameters.m_InputToInputWeights = m_CifgParameters.m_InputToInputWeights ?
108 layer->m_CifgParameters.m_RecurrentToInputWeights = m_CifgParameters.m_RecurrentToInputWeights ?
110 layer->m_CifgParameters.m_InputGateBias = m_CifgParameters.m_InputGateBias ?
112 }
113
115 {
116 layer->m_ProjectionParameters.m_ProjectionWeights = m_ProjectionParameters.m_ProjectionWeights ?
118 layer->m_ProjectionParameters.m_ProjectionBias = m_ProjectionParameters.m_ProjectionBias ?
120 }
121
123 {
125 {
126 layer->m_PeepholeParameters.m_CellToInputWeights = m_PeepholeParameters.m_CellToInputWeights ?
128 }
129 layer->m_PeepholeParameters.m_CellToForgetWeights = m_PeepholeParameters.m_CellToForgetWeights ?
131 layer->m_PeepholeParameters.m_CellToOutputWeights = m_PeepholeParameters.m_CellToOutputWeights ?
133 }
134
136 {
137 layer->m_LayerNormParameters.m_InputLayerNormWeights = m_LayerNormParameters.m_InputLayerNormWeights ?
139 layer->m_LayerNormParameters.m_ForgetLayerNormWeights = m_LayerNormParameters.m_ForgetLayerNormWeights ?
141 layer->m_LayerNormParameters.m_CellLayerNormWeights = m_LayerNormParameters.m_CellLayerNormWeights ?
143 layer->m_LayerNormParameters.m_OutputLayerNormWeights = m_LayerNormParameters.m_OutputLayerNormWeights ?
145 }
146
147 return std::move(layer);
148}
const char * GetName() const override
Returns the name of the layer.
Definition Layer.hpp:332
LstmDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).
LstmOptCifgParameters m_CifgParameters
Definition LstmLayer.hpp:21
LstmOptProjectionParameters m_ProjectionParameters
Definition LstmLayer.hpp:22
LstmOptLayerNormParameters m_LayerNormParameters
Definition LstmLayer.hpp:24
LstmOptPeepholeParameters m_PeepholeParameters
Definition LstmLayer.hpp:23
LstmBasicParameters m_BasicParameters
Definition LstmLayer.hpp:20
std::shared_ptr< ConstTensorHandle > m_RecurrentToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
std::shared_ptr< ConstTensorHandle > m_CellBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
std::shared_ptr< ConstTensorHandle > m_InputToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
std::shared_ptr< ConstTensorHandle > m_RecurrentToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
std::shared_ptr< ConstTensorHandle > m_OutputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
std::shared_ptr< ConstTensorHandle > m_InputToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
std::shared_ptr< ConstTensorHandle > m_InputToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
std::shared_ptr< ConstTensorHandle > m_RecurrentToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
std::shared_ptr< ConstTensorHandle > m_ForgetGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
bool m_PeepholeEnabled
Enable/disable peephole.
bool m_LayerNormEnabled
Enable/disable layer normalization.
bool m_ProjectionEnabled
Enable/disable the projection layer.
bool m_CifgEnabled
Enable/disable cifg (coupled input & forget gate).
std::shared_ptr< ConstTensorHandle > m_InputToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
std::shared_ptr< ConstTensorHandle > m_InputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
std::shared_ptr< ConstTensorHandle > m_RecurrentToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
std::shared_ptr< ConstTensorHandle > m_CellLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
std::shared_ptr< ConstTensorHandle > m_InputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
std::shared_ptr< ConstTensorHandle > m_OutputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
std::shared_ptr< ConstTensorHandle > m_ForgetLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
std::shared_ptr< ConstTensorHandle > m_CellToForgetWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
std::shared_ptr< ConstTensorHandle > m_CellToInputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
std::shared_ptr< ConstTensorHandle > m_CellToOutputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
std::shared_ptr< ConstTensorHandle > m_ProjectionBias
A unique pointer to represent 1D weights tensor with dimensions [output_size].
std::shared_ptr< ConstTensorHandle > m_ProjectionWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].

References Layer::GetName(), 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, LstmOptProjectionParameters::m_ProjectionBias, LstmDescriptor::m_ProjectionEnabled, LstmLayer::m_ProjectionParameters, LstmOptProjectionParameters::m_ProjectionWeights, LstmBasicParameters::m_RecurrentToCellWeights, LstmBasicParameters::m_RecurrentToForgetWeights, LstmOptCifgParameters::m_RecurrentToInputWeights, and LstmBasicParameters::m_RecurrentToOutputWeights.

◆ 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.

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 SetAdditionalInfo(descriptor);
76
77 return factory.CreateWorkload(LayerType::Lstm, descriptor, PrepInfoAndDesc(descriptor));
78}
void SetAdditionalInfo(QueueDescriptor &descriptor) const
Definition Layer.cpp:303
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *LayerCreateWorkload.

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

◆ ExecuteStrategy()

void ExecuteStrategy ( IStrategy & strategy) const
overridevirtual

Apply a visitor to this layer.

Reimplemented from LayerWithParameters< LstmDescriptor >.

Definition at line 402 of file LstmLayer.cpp.

403{
404 std::vector<ConstTensor> constTensors;
405
406 LstmDescriptor descriptor = GetParameters();
407
408 ManagedConstTensorHandle managedInputToForgetWeights(m_BasicParameters.m_InputToForgetWeights);
409 ManagedConstTensorHandle managedInputToCellWeights(m_BasicParameters.m_InputToCellWeights);
410 ManagedConstTensorHandle managedInputToOutputWeights(m_BasicParameters.m_InputToOutputWeights);
411 ManagedConstTensorHandle managedRecurrentToForgetWeights(m_BasicParameters.m_RecurrentToForgetWeights);
412 ManagedConstTensorHandle managedRecurrentToCellWeights(m_BasicParameters.m_RecurrentToCellWeights);
413 ManagedConstTensorHandle managedRecurrentToOutputWeights(m_BasicParameters.m_RecurrentToOutputWeights);
414 ManagedConstTensorHandle managedForgetGateBias(m_BasicParameters.m_ForgetGateBias);
415 ManagedConstTensorHandle managedCellBias(m_BasicParameters.m_CellBias);
416 ManagedConstTensorHandle managedOutputGateBias(m_BasicParameters.m_OutputGateBias);
417
418 // Cifg parameters
419 ManagedConstTensorHandle managedInputToInputWeights(m_CifgParameters.m_InputToInputWeights);
420 ManagedConstTensorHandle managedRecurrentToInputWeights(m_CifgParameters.m_RecurrentToInputWeights);
421 ManagedConstTensorHandle managedInputGateBias(m_CifgParameters.m_InputGateBias);
422
423 // Projection parameters
424 ManagedConstTensorHandle managedProjectionWeights(m_ProjectionParameters.m_ProjectionWeights);
425 ManagedConstTensorHandle managedProjectionBias(m_ProjectionParameters.m_ProjectionBias);
426
427 // Peephole parameters
428 ManagedConstTensorHandle managedCellToInputWeights(m_PeepholeParameters.m_CellToInputWeights);
429 ManagedConstTensorHandle managedCellToForgetWeights(m_PeepholeParameters.m_CellToForgetWeights);
430 ManagedConstTensorHandle managedCellToOutputWeights(m_PeepholeParameters.m_CellToOutputWeights);
431
432 // Layer normalisation parameters
433 ManagedConstTensorHandle managedInputLayerNormWeights(m_LayerNormParameters.m_InputLayerNormWeights);
434 ManagedConstTensorHandle managedForgetLayerNormWeights(m_LayerNormParameters.m_ForgetLayerNormWeights);
435 ManagedConstTensorHandle managedCellLayerNormWeights(m_LayerNormParameters.m_CellLayerNormWeights);
436 ManagedConstTensorHandle managedOutputLayerNormWeights(m_LayerNormParameters.m_OutputLayerNormWeights);
437
438 // First add mandatory/basic parameters
440 {
441 constTensors.emplace_back(ConstTensor(managedInputToForgetWeights.GetTensorInfo(),
442 managedInputToForgetWeights.Map()));
443 }
445 {
446 constTensors.emplace_back(ConstTensor(managedInputToCellWeights.GetTensorInfo(),
447 managedInputToCellWeights.Map()));
448 }
450 {
451 constTensors.emplace_back(ConstTensor(managedInputToOutputWeights.GetTensorInfo(),
452 managedInputToOutputWeights.Map()));
453 }
455 {
456 constTensors.emplace_back(ConstTensor(
457 managedRecurrentToForgetWeights.GetTensorInfo(),
458 managedRecurrentToForgetWeights.Map()));
459 }
461 {
462 constTensors.emplace_back(ConstTensor(
463 managedRecurrentToCellWeights.GetTensorInfo(),
464 managedRecurrentToCellWeights.Map()));
465 }
467 {
468 constTensors.emplace_back(ConstTensor(
469 managedRecurrentToOutputWeights.GetTensorInfo(),
470 managedRecurrentToOutputWeights.Map()));
471 }
472 if (m_BasicParameters.m_ForgetGateBias != nullptr)
473 {
474 constTensors.emplace_back(ConstTensor(managedForgetGateBias.GetTensorInfo(),
475 managedForgetGateBias.Map()));
476 }
477 if (m_BasicParameters.m_CellBias != nullptr)
478 {
479 constTensors.emplace_back(ConstTensor(managedCellBias.GetTensorInfo(),
480 managedCellBias.Map()));
481 }
482 if (m_BasicParameters.m_OutputGateBias != nullptr)
483 {
484 constTensors.emplace_back(ConstTensor(managedOutputGateBias.GetTensorInfo(),
485 managedOutputGateBias.Map()));
486 }
487
488 // Add cifg parameters
489 if (!descriptor.m_CifgEnabled)
490 {
492 {
493 constTensors.emplace_back(ConstTensor(managedInputToInputWeights.GetTensorInfo(),
494 managedInputToInputWeights.Map()));
495 }
497 {
498 constTensors.emplace_back(ConstTensor(
499 managedRecurrentToInputWeights.GetTensorInfo(),
500 managedRecurrentToInputWeights.Map()));
501 }
502 if (m_CifgParameters.m_InputGateBias != nullptr)
503 {
504 constTensors.emplace_back(ConstTensor(managedInputGateBias.GetTensorInfo(),
505 managedInputGateBias.Map()));
506 }
507 }
508
509 // Add peephole parameters
510 if (descriptor.m_PeepholeEnabled)
511 {
512 if (!descriptor.m_CifgEnabled)
513 {
515 {
516 constTensors.emplace_back(ConstTensor(managedCellToInputWeights.GetTensorInfo(),
517 managedCellToInputWeights.Map()));
518 }
519 }
521 {
522 constTensors.emplace_back(ConstTensor(managedCellToForgetWeights.GetTensorInfo(),
523 managedCellToForgetWeights.Map()));
524 }
526 {
527 constTensors.emplace_back(ConstTensor(managedCellToOutputWeights.GetTensorInfo(),
528 managedCellToOutputWeights.Map()));
529 }
530 }
531
532 // Add projection parameters
533 if (descriptor.m_ProjectionEnabled)
534 {
536 {
537 constTensors.emplace_back(ConstTensor(managedProjectionWeights.GetTensorInfo(),
538 managedProjectionWeights.Map()));
539 }
541 {
542 constTensors.emplace_back(ConstTensor(managedProjectionBias.GetTensorInfo(),
543 managedProjectionBias.Map()));
544 }
545 }
546
547 // Add norm parameters
548 if (descriptor.m_LayerNormEnabled)
549 {
550 if (!descriptor.m_CifgEnabled)
551 {
553 {
554 constTensors.emplace_back(ConstTensor(managedInputLayerNormWeights.GetTensorInfo(),
555 managedInputLayerNormWeights.Map()));
556 }
557 }
559 {
560 constTensors.emplace_back(ConstTensor(managedForgetLayerNormWeights.GetTensorInfo(),
561 managedForgetLayerNormWeights.Map()));
562 }
564 {
565 constTensors.emplace_back(ConstTensor(managedCellLayerNormWeights.GetTensorInfo(),
566 managedCellLayerNormWeights.Map()));
567 }
569 {
570 constTensors.emplace_back(ConstTensor(managedOutputLayerNormWeights.GetTensorInfo(),
571 managedOutputLayerNormWeights.Map()));
572 }
573 }
574
575 strategy.ExecuteStrategy(this, GetParameters(), constTensors, GetName());
576}
const LstmDescriptor & GetParameters() const override

References IStrategy::ExecuteStrategy(), Layer::GetName(), LayerWithParameters< LstmDescriptor >::GetParameters(), ManagedConstTensorHandle::GetTensorInfo(), 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, LstmDescriptor::m_PeepholeEnabled, LstmLayer::m_PeepholeParameters, LstmOptProjectionParameters::m_ProjectionBias, LstmDescriptor::m_ProjectionEnabled, LstmLayer::m_ProjectionParameters, LstmOptProjectionParameters::m_ProjectionWeights, LstmBasicParameters::m_RecurrentToCellWeights, LstmBasicParameters::m_RecurrentToForgetWeights, LstmOptCifgParameters::m_RecurrentToInputWeights, LstmBasicParameters::m_RecurrentToOutputWeights, and ManagedConstTensorHandle::Map().

◆ GetConstantTensorsByRef()

Layer::ImmutableConstantTensors GetConstantTensorsByRef ( ) const
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 368 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.

◆ 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 150 of file LstmLayer.cpp.

151{
152 if (inputShapes.size() != 3)
153 {
154 throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) +
155 "\" - should be \"3\".");
156 }
157
158 // Get input values for validation
159 unsigned int batchSize = inputShapes[0][0];
160 unsigned int outputSize = inputShapes[1][1];
161 unsigned int numUnits = inputShapes[2][1];
162
163 std::vector<TensorShape> outShapes;
164 outShapes.push_back(TensorShape({batchSize, numUnits * (m_Param.m_CifgEnabled ? 3 : 4)}));
165 outShapes.push_back(TensorShape({batchSize, outputSize}));
166 outShapes.push_back(TensorShape({batchSize, numUnits}));
167 outShapes.push_back(TensorShape({batchSize, outputSize}));
168
169 return outShapes;
170}
Base class for all ArmNN exceptions so that users can filter to just those.

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

Referenced by LstmLayer::ValidateTensorShapesFromInputs().

◆ ValidateTensorShapesFromInputs()

void ValidateTensorShapesFromInputs ( )
overridevirtual

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

Parameters
[in]shapeInferenceMethodIndicates if output shape shall be overwritten or just validated.

Implements Layer.

Definition at line 172 of file LstmLayer.cpp.

173{
175
176 const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape();
177
179
180 auto inferredShapes = InferOutputShapes( {
184 });
185
186 if (inferredShapes.size() != 4)
187 {
188 throw armnn::Exception("inferredShapes has "
189 + std::to_string(inferredShapes.size()) +
190 " element(s) - should only have 4.");
191 }
192
193 // Check if the weights are nullptr
195 {
196 throw armnn::NullPointerException("LstmLayer: "
197 "m_BasicParameters.m_InputToForgetWeights should not be null.");
198 }
199
201 {
202 throw armnn::NullPointerException("LstmLayer: "
203 "m_BasicParameters.m_InputToCellWeights should not be null.");
204 }
205
207 {
208 throw armnn::NullPointerException("LstmLayer: "
209 "m_BasicParameters.m_InputToOutputWeights should not be null.");
210 }
211
213 {
214 throw armnn::NullPointerException("LstmLayer: "
215 "m_BasicParameters.m_RecurrentToForgetWeights should not be null.");
216 }
217
219 {
220 throw armnn::NullPointerException("LstmLayer: "
221 "m_BasicParameters.m_RecurrentToCellWeights should not be null.");
222 }
223
225 {
226 throw armnn::NullPointerException("LstmLayer: "
227 "m_BasicParameters.m_RecurrentToOutputWeights should not be null.");
228 }
229
231 {
232 throw armnn::NullPointerException("LstmLayer: "
233 "m_BasicParameters.m_ForgetGateBias should not be null.");
234 }
235
237 {
238 throw armnn::NullPointerException("LstmLayer: "
239 "m_BasicParameters.m_CellBias should not be null.");
240 }
241
243 {
244 throw armnn::NullPointerException("LstmLayer: "
245 "m_BasicParameters.m_OutputGateBias should not be null.");
246 }
247
249 {
251 {
252 throw armnn::NullPointerException("LstmLayer: "
253 "m_CifgParameters.m_InputToInputWeights should not be null.");
254 }
255
257 {
258 throw armnn::NullPointerException("LstmLayer: "
259 "m_CifgParameters.m_RecurrentToInputWeights should not be null.");
260 }
261
263 {
264 throw armnn::NullPointerException("LstmLayer: "
265 "m_CifgParameters.m_InputGateBias should not be null.");
266 }
267
268 ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "LstmLayer");
269 }
270 else
271 {
273 {
274 throw armnn::Exception("LstmLayer: "
275 "m_CifgParameters.m_InputToInputWeights should not have a value "
276 "when CIFG is enabled.");
277 }
278
280 {
281 throw armnn::Exception("LstmLayer: "
282 "m_CifgParameters.m_RecurrentToInputWeights should not have a value "
283 "when CIFG is enabled.");
284 }
285
287 {
288 throw armnn::Exception("LstmLayer: "
289 "m_CifgParameters.m_InputGateBias should not have a value "
290 "when CIFG is enabled.");
291 }
292
293 ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "LstmLayer");
294 }
295
297 {
299 {
300 throw armnn::NullPointerException("LstmLayer: "
301 "m_ProjectionParameters.m_ProjectionWeights should not be null.");
302 }
303 }
304
306 {
308 {
310 {
311 throw armnn::NullPointerException("LstmLayer: "
312 "m_PeepholeParameters.m_CellToInputWeights should not be null "
313 "when Peephole is enabled and CIFG is disabled.");
314 }
315 }
316
318 {
319 throw armnn::NullPointerException("LstmLayer: "
320 "m_PeepholeParameters.m_CellToForgetWeights should not be null.");
321 }
322
324 {
325 throw armnn::NullPointerException("LstmLayer: "
326 "m_PeepholeParameters.m_CellToOutputWeights should not be null.");
327 }
328 }
329
331 GetOutputSlot(1).GetTensorInfo().GetShape(), inferredShapes[1], m_ShapeInferenceMethod, "LstmLayer", 1);
333 GetOutputSlot(2).GetTensorInfo().GetShape(), inferredShapes[2], m_ShapeInferenceMethod, "LstmLayer", 2);
335 GetOutputSlot(3).GetTensorInfo().GetShape(), inferredShapes[3], m_ShapeInferenceMethod, "LstmLayer", 3);
336
338 {
340 {
342 {
343 throw armnn::NullPointerException("LstmLayer: "
344 "m_LayerNormParameters.m_inputLayerNormWeights should not be null.");
345 }
346 }
347
349 {
350 throw armnn::NullPointerException("LstmLayer: "
351 "m_LayerNormParameters.m_forgetLayerNormWeights should not be null.");
352 }
353
355 {
356 throw armnn::NullPointerException("LstmLayer: "
357 "m_LayerNormParameters.m_cellLayerNormWeights should not be null.");
358 }
359
361 {
362 throw armnn::NullPointerException("LstmLayer: "
363 "m_LayerNormParameters.m_outputLayerNormWeights should not be null.");
364 }
365 }
366}
#define CHECK_LOCATION()
const TensorInfo & GetTensorInfo() const override
Gets the TensorInfo for this InputSlot.
Definition Layer.cpp:614
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
Definition Layer.cpp:410
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Definition Layer.hpp:337
void VerifyShapeInferenceType(const TensorShape &outputShape, ShapeInferenceMethod shapeInferenceMethod)
Definition Layer.cpp:526
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
Definition Layer.hpp:339
void ValidateAndCopyShape(const TensorShape &outputShape, const TensorShape &inferredShape, const ShapeInferenceMethod shapeInferenceMethod, const std::string &layerName, const unsigned int outputSlotIndex=0)
Definition Layer.cpp:457
ShapeInferenceMethod m_ShapeInferenceMethod
Definition Layer.hpp:441
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,...
const TensorInfo & GetTensorInfo() const override
Definition Layer.cpp:100
const TensorShape & GetShape() const
Definition Tensor.hpp:193
armnn::TensorInfo GetTensorInfo(unsigned int numberOfBatches, unsigned int numberOfChannels, unsigned int height, unsigned int width, const armnn::DataLayout dataLayout, const armnn::DataType dataType)

References CHECK_LOCATION, Layer::GetInputSlot(), Layer::GetOutputSlot(), TensorInfo::GetShape(), InputSlot::GetTensorInfo(), OutputSlot::GetTensorInfo(), armnnUtils::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, Layer::m_ShapeInferenceMethod, Layer::ValidateAndCopyShape(), Layer::VerifyLayerConnections(), and Layer::VerifyShapeInferenceType().

Member Data Documentation

◆ m_BasicParameters

◆ m_CifgParameters

◆ m_LayerNormParameters

◆ m_PeepholeParameters

◆ m_ProjectionParameters


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