ArmNN
 20.08
LstmLayer.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
8 
9 namespace armnn
10 {
11 
12 class ScopedCpuTensorHandle;
13 
15 {
16  /// A unique pointer to represent 1D weights tensor with dimensions [num_units].
17  std::unique_ptr<ScopedCpuTensorHandle> m_InputLayerNormWeights;
18  /// A unique pointer to represent 1D weights tensor with dimensions [num_units].
19  std::unique_ptr<ScopedCpuTensorHandle> m_ForgetLayerNormWeights;
20  /// A unique pointer to represent 1D weights tensor with dimensions [num_units].
21  std::unique_ptr<ScopedCpuTensorHandle> m_CellLayerNormWeights;
22  /// A unique pointer to represent 1D weights tensor with dimensions [num_units].
23  std::unique_ptr<ScopedCpuTensorHandle> m_OutputLayerNormWeights;
24 };
25 
27 {
28  /// A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
29  std::unique_ptr<ScopedCpuTensorHandle> m_InputToInputWeights;
30  /// A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
31  std::unique_ptr<ScopedCpuTensorHandle> m_RecurrentToInputWeights;
32  /// A unique pointer to represent 1D weights tensor with dimensions [num_units].
33  std::unique_ptr<ScopedCpuTensorHandle> m_InputGateBias;
34 };
35 
37 {
38  /// A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
39  std::unique_ptr<ScopedCpuTensorHandle> m_ProjectionWeights;
40  /// A unique pointer to represent 1D weights tensor with dimensions [output_size].
41  std::unique_ptr<ScopedCpuTensorHandle> m_ProjectionBias;
42 };
43 
45 {
46  /// A unique pointer to represent 1D weights tensor with dimensions [num_units].
47  std::unique_ptr<ScopedCpuTensorHandle> m_CellToInputWeights;
48  /// A unique pointer to represent 1D weights tensor with dimensions [num_units].
49  std::unique_ptr<ScopedCpuTensorHandle> m_CellToForgetWeights;
50  /// A unique pointer to represent 1D weights tensor with dimensions [num_units].
51  std::unique_ptr<ScopedCpuTensorHandle> m_CellToOutputWeights;
52 };
53 
55 {
56  /// A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
57  std::unique_ptr<ScopedCpuTensorHandle> m_InputToForgetWeights;
58  /// A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
59  std::unique_ptr<ScopedCpuTensorHandle> m_InputToCellWeights;
60  /// A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
61  std::unique_ptr<ScopedCpuTensorHandle> m_InputToOutputWeights;
62  /// A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
63  std::unique_ptr<ScopedCpuTensorHandle> m_RecurrentToForgetWeights;
64  /// A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
65  std::unique_ptr<ScopedCpuTensorHandle> m_RecurrentToCellWeights;
66  /// A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
67  std::unique_ptr<ScopedCpuTensorHandle> m_RecurrentToOutputWeights;
68  /// A unique pointer to represent 1D weights tensor with dimensions [num_units].
69  std::unique_ptr<ScopedCpuTensorHandle> m_ForgetGateBias;
70  /// A unique pointer to represent 1D weights tensor with dimensions [num_units].
71  std::unique_ptr<ScopedCpuTensorHandle> m_CellBias;
72  /// A unique pointer to represent 1D weights tensor with dimensions [num_units].
73  std::unique_ptr<ScopedCpuTensorHandle> m_OutputGateBias;
74 };
75 
76 /// This layer represents a LSTM operation.
77 class LstmLayer : public LayerWithParameters<LstmDescriptor>
78 {
79 public:
80 
86 
87  /// Makes a workload for the LSTM type.
88  /// @param [in] graph The graph where this layer can be found.
89  /// @param [in] factory The workload factory which will create the workload.
90  /// @return A pointer to the created workload, or nullptr if not created.
91  virtual std::unique_ptr<IWorkload> CreateWorkload(const IWorkloadFactory& factory) const override;
92 
93  /// Creates a dynamically-allocated copy of this layer.
94  /// @param [in] graph The graph into which this layer is being cloned.
95  LstmLayer* Clone(Graph& graph) const override;
96 
97  /// Check if the input tensor shape(s)
98  /// will lead to a valid configuration of @ref LstmLayer.
99  /// @param [in] shapeInferenceMethod Indicates if output shape shall be overwritten or just validated.
100  void ValidateTensorShapesFromInputs() override;
101 
102  /// By default returns inputShapes if the number of inputs are equal to number of outputs,
103  /// otherwise infers the output shapes from given input shapes and layer properties.
104  /// @param [in] inputShapes The input shapes layer has.
105  /// @return A vector to the inferred output shape.
106  std::vector<TensorShape> InferOutputShapes(const std::vector<TensorShape>& inputShapes) const override;
107 
108  void Accept(ILayerVisitor& visitor) const override;
109 
110 protected:
111  /// Constructor to create a LstmLayer.
112  /// @param [in] param LstmDescriptor to configure the lstm operation.
113  /// @param [in] name Optional name for the layer.
114  LstmLayer(const LstmDescriptor& param, const char* name);
115 
116  /// Default destructor
117  ~LstmLayer() = default;
118 
119  /// Retrieve the handles to the constant values stored by the layer.
120  /// @return A vector of the constant tensors stored by this layer.
121  Layer::ConstantTensors GetConstantTensorsByRef() override;
122 };
123 
124 } // namespace
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< armnn::IWorkload > CreateWorkload(const armnn::IWorkloadFactory &workloadFactory, const armnn::WorkloadInfo &info, const DescriptorType &descriptor)
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
Copyright (c) 2020 ARM Limited.
This layer represents a LSTM operation.
Definition: LstmLayer.hpp:77
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
An LstmDescriptor for the LstmLayer.
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::vector< std::reference_wrapper< std::unique_ptr< ScopedCpuTensorHandle > >> ConstantTensors
Definition: Layer.hpp:378
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