ArmNN
 21.02
QLstmLayer.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2020 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 2D weights tensor with dimensions [num_units, inputSize] (QSymmS8).
17  std::unique_ptr<ScopedCpuTensorHandle> m_InputToForgetWeights;
18  /// A unique pointer to represent 2D weights tensor with dimensions [num_units, inputSize] (QSymmS8).
19  std::unique_ptr<ScopedCpuTensorHandle> m_InputToCellWeights;
20  /// A unique pointer to represent 2D weights tensor with dimensions [num_units, inputSize] (QSymmS8).
21  std::unique_ptr<ScopedCpuTensorHandle> m_InputToOutputWeights;
22 
23  /// A unique pointer to represent 2D weights tensor with dimensions [num_units, outputSize] (QSymmS8).
24  std::unique_ptr<ScopedCpuTensorHandle> m_RecurrentToForgetWeights;
25  /// A unique pointer to represent 2D weights tensor with dimensions [num_units, outputSize] (QSymmS8).
26  std::unique_ptr<ScopedCpuTensorHandle> m_RecurrentToCellWeights;
27  /// A unique pointer to represent 2D weights tensor with dimensions [num_units, outputSize] (QSymmS8).
28  std::unique_ptr<ScopedCpuTensorHandle> m_RecurrentToOutputWeights;
29 
30  /// A unique pointer to represent 1D bias tensor with dimensions [num_units] (int32).
31  std::unique_ptr<ScopedCpuTensorHandle> m_ForgetGateBias;
32  /// A unique pointer to represent 1D bias tensor with dimensions [num_units] (int32).
33  std::unique_ptr<ScopedCpuTensorHandle> m_CellBias;
34  /// A unique pointer to represent 1D bias tensor with dimensions [num_units] (int32).
35  std::unique_ptr<ScopedCpuTensorHandle> m_OutputGateBias;
36 };
37 
39 {
40  /// A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units] (QSymmS8).
41  std::unique_ptr<ScopedCpuTensorHandle> m_ProjectionWeights;
42  /// A unique pointer to represent 1D weights tensor with dimensions [output_size] (int32).
43  std::unique_ptr<ScopedCpuTensorHandle> m_ProjectionBias;
44 };
45 
47 {
48  /// A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
49  std::unique_ptr<ScopedCpuTensorHandle> m_CellToInputWeights;
50  /// A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
51  std::unique_ptr<ScopedCpuTensorHandle> m_CellToForgetWeights;
52  /// A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
53  std::unique_ptr<ScopedCpuTensorHandle> m_CellToOutputWeights;
54 };
55 
57 {
58  /// A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units] (QSymmS8).
59  std::unique_ptr<ScopedCpuTensorHandle> m_InputToInputWeights;
60  /// A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units] (QSymmS8).
61  std::unique_ptr<ScopedCpuTensorHandle> m_RecurrentToInputWeights;
62  /// A unique pointer to represent 1D weights tensor with dimensions [num_units] (int32).
63  std::unique_ptr<ScopedCpuTensorHandle> m_InputGateBias;
64 };
65 
67 {
68  /// A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
69  std::unique_ptr<ScopedCpuTensorHandle> m_InputLayerNormWeights;
70  /// A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
71  std::unique_ptr<ScopedCpuTensorHandle> m_ForgetLayerNormWeights;
72  /// A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
73  std::unique_ptr<ScopedCpuTensorHandle> m_CellLayerNormWeights;
74  /// A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
75  std::unique_ptr<ScopedCpuTensorHandle> m_OutputLayerNormWeights;
76 };
77 
78 /// This layer represents a QLstm operation.
79 class QLstmLayer : public LayerWithParameters<QLstmDescriptor>
80 {
81 public:
82 
88 
89  /// Makes a workload for the QLstm type.
90  /// @param [in] graph The graph where this layer can be found.
91  /// @param [in] factory The workload factory which will create the workload.
92  /// @return A pointer to the created workload, or nullptr if not created.
93  virtual std::unique_ptr<IWorkload> CreateWorkload(const IWorkloadFactory& factory) const override;
94 
95  /// Creates a dynamically-allocated copy of this layer.
96  /// @param [in] graph The graph into which this layer is being cloned.
97  QLstmLayer* Clone(Graph& graph) const override;
98 
99  /// Check if the input tensor shape(s)
100  /// will lead to a valid configuration of @ref QLstmLayer.
101  /// @param [in] shapeInferenceMethod Indicates if output shape shall be overwritten or just validated.
102  void ValidateTensorShapesFromInputs() override;
103 
104  /// By default returns inputShapes if the number of inputs are equal to number of outputs,
105  /// otherwise infers the output shapes from given input shapes and layer properties.
106  /// @param [in] inputShapes The input shapes layer has.
107  /// @return A vector to the inferred output shape.
108  std::vector<TensorShape> InferOutputShapes(const std::vector<TensorShape>& inputShapes) const override;
109 
110  void Accept(ILayerVisitor& visitor) const override;
111 
112  void ExecuteStrategy(IStrategy& strategy) const override;
113 
114 protected:
115  /// Constructor to create a QLstmLayer.
116  /// @param [in] name Optional name for the layer.
117  QLstmLayer(const QLstmDescriptor& param, const char* name);
118 
119  /// Default destructor
120  ~QLstmLayer() = default;
121 
122  /// Retrieve the handles to the constant values stored by the layer.
123  /// @return A vector of the constant tensors stored by this layer.
124  Layer::ConstantTensors GetConstantTensorsByRef() override;
125 };
126 
127 } // namespace armnn
std::unique_ptr< armnn::IWorkload > CreateWorkload(const armnn::IWorkloadFactory &workloadFactory, const armnn::WorkloadInfo &info, const DescriptorType &descriptor)
QLstmOptProjectionParameters m_ProjectionParameters
Definition: QLstmLayer.hpp:85
std::unique_ptr< ScopedCpuTensorHandle > m_OutputGateBias
A unique pointer to represent 1D bias tensor with dimensions [num_units] (int32). ...
Definition: QLstmLayer.hpp:35
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units] (QSymmS8)...
Definition: QLstmLayer.hpp:61
std::unique_ptr< ScopedCpuTensorHandle > m_CellLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
Definition: QLstmLayer.hpp:73
std::unique_ptr< ScopedCpuTensorHandle > m_InputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
Definition: QLstmLayer.hpp:69
std::unique_ptr< ScopedCpuTensorHandle > m_InputToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units] (QSymmS8)...
Definition: QLstmLayer.hpp:59
std::unique_ptr< ScopedCpuTensorHandle > m_CellToOutputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
Definition: QLstmLayer.hpp:53
std::unique_ptr< ScopedCpuTensorHandle > m_ProjectionBias
A unique pointer to represent 1D weights tensor with dimensions [output_size] (int32).
Definition: QLstmLayer.hpp:43
std::unique_ptr< ScopedCpuTensorHandle > m_ProjectionWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units] (QSymmS8)...
Definition: QLstmLayer.hpp:41
std::unique_ptr< ScopedCpuTensorHandle > m_InputToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [num_units, inputSize] (QSymmS8)...
Definition: QLstmLayer.hpp:17
std::unique_ptr< ScopedCpuTensorHandle > m_CellBias
A unique pointer to represent 1D bias tensor with dimensions [num_units] (int32). ...
Definition: QLstmLayer.hpp:33
Copyright (c) 2021 ARM Limited and Contributors.
std::unique_ptr< ScopedCpuTensorHandle > m_InputToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [num_units, inputSize] (QSymmS8)...
Definition: QLstmLayer.hpp:21
std::unique_ptr< ScopedCpuTensorHandle > m_OutputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
Definition: QLstmLayer.hpp:75
QLstmOptLayerNormParameters m_LayerNormParameters
Definition: QLstmLayer.hpp:87
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [num_units, outputSize] (QSymmS8)...
Definition: QLstmLayer.hpp:24
std::unique_ptr< ScopedCpuTensorHandle > m_CellToInputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
Definition: QLstmLayer.hpp:49
std::unique_ptr< ScopedCpuTensorHandle > m_CellToForgetWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
Definition: QLstmLayer.hpp:51
std::unique_ptr< ScopedCpuTensorHandle > m_InputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units] (int32).
Definition: QLstmLayer.hpp:63
A QLstmDescriptor for the QLstmLayer.
std::unique_ptr< ScopedCpuTensorHandle > m_ForgetLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
Definition: QLstmLayer.hpp:71
std::unique_ptr< ScopedCpuTensorHandle > m_InputToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [num_units, inputSize] (QSymmS8)...
Definition: QLstmLayer.hpp:19
QLstmBasicParameters m_BasicParameters
Definition: QLstmLayer.hpp:83
This layer represents a QLstm operation.
Definition: QLstmLayer.hpp:79
std::unique_ptr< ScopedCpuTensorHandle > m_ForgetGateBias
A unique pointer to represent 1D bias tensor with dimensions [num_units] (int32). ...
Definition: QLstmLayer.hpp:31
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [num_units, outputSize] (QSymmS8)...
Definition: QLstmLayer.hpp:26
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [num_units, outputSize] (QSymmS8)...
Definition: QLstmLayer.hpp:28
QLstmOptCifgParameters m_CifgParameters
Definition: QLstmLayer.hpp:84
QLstmOptPeepholeParameters m_PeepholeParameters
Definition: QLstmLayer.hpp:86
std::vector< std::reference_wrapper< std::unique_ptr< ScopedCpuTensorHandle > >> ConstantTensors
Definition: Layer.hpp:393