ArmNN
 24.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 ScopedTensorHandle;
13 
15 {
16  /// A unique pointer to represent 2D weights tensor with dimensions [num_units, inputSize] (QSymmS8).
17  std::shared_ptr<ConstTensorHandle> m_InputToForgetWeights;
18  /// A unique pointer to represent 2D weights tensor with dimensions [num_units, inputSize] (QSymmS8).
19  std::shared_ptr<ConstTensorHandle> m_InputToCellWeights;
20  /// A unique pointer to represent 2D weights tensor with dimensions [num_units, inputSize] (QSymmS8).
21  std::shared_ptr<ConstTensorHandle> m_InputToOutputWeights;
22 
23  /// A unique pointer to represent 2D weights tensor with dimensions [num_units, outputSize] (QSymmS8).
24  std::shared_ptr<ConstTensorHandle> m_RecurrentToForgetWeights;
25  /// A unique pointer to represent 2D weights tensor with dimensions [num_units, outputSize] (QSymmS8).
26  std::shared_ptr<ConstTensorHandle> m_RecurrentToCellWeights;
27  /// A unique pointer to represent 2D weights tensor with dimensions [num_units, outputSize] (QSymmS8).
28  std::shared_ptr<ConstTensorHandle> m_RecurrentToOutputWeights;
29 
30  /// A unique pointer to represent 1D bias tensor with dimensions [num_units] (int32).
31  std::shared_ptr<ConstTensorHandle> m_ForgetGateBias;
32  /// A unique pointer to represent 1D bias tensor with dimensions [num_units] (int32).
33  std::shared_ptr<ConstTensorHandle> m_CellBias;
34  /// A unique pointer to represent 1D bias tensor with dimensions [num_units] (int32).
35  std::shared_ptr<ConstTensorHandle> m_OutputGateBias;
36 };
37 
39 {
40  /// A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units] (QSymmS8).
41  std::shared_ptr<ConstTensorHandle> m_ProjectionWeights;
42  /// A unique pointer to represent 1D weights tensor with dimensions [output_size] (int32).
43  std::shared_ptr<ConstTensorHandle> m_ProjectionBias;
44 };
45 
47 {
48  /// A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
49  std::shared_ptr<ConstTensorHandle> m_CellToInputWeights;
50  /// A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
51  std::shared_ptr<ConstTensorHandle> m_CellToForgetWeights;
52  /// A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
53  std::shared_ptr<ConstTensorHandle> m_CellToOutputWeights;
54 };
55 
57 {
58  /// A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units] (QSymmS8).
59  std::shared_ptr<ConstTensorHandle> m_InputToInputWeights;
60  /// A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units] (QSymmS8).
61  std::shared_ptr<ConstTensorHandle> m_RecurrentToInputWeights;
62  /// A unique pointer to represent 1D weights tensor with dimensions [num_units] (int32).
63  std::shared_ptr<ConstTensorHandle> m_InputGateBias;
64 };
65 
67 {
68  /// A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
69  std::shared_ptr<ConstTensorHandle> m_InputLayerNormWeights;
70  /// A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
71  std::shared_ptr<ConstTensorHandle> m_ForgetLayerNormWeights;
72  /// A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
73  std::shared_ptr<ConstTensorHandle> m_CellLayerNormWeights;
74  /// A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
75  std::shared_ptr<ConstTensorHandle> 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 ExecuteStrategy(IStrategy& strategy) const override;
111 
112 protected:
113  /// Constructor to create a QLstmLayer.
114  /// @param [in] name Optional name for the layer.
115  QLstmLayer(const QLstmDescriptor& param, const char* name);
116 
117  /// Default destructor
118  ~QLstmLayer() = default;
119 
120  /// Retrieve the handles to the constant values stored by the layer.
121  /// @return A vector of the constant tensors stored by this layer.
123 };
124 
125 } // namespace armnn
armnn::QLstmLayer::m_CifgParameters
QLstmOptCifgParameters m_CifgParameters
Definition: QLstmLayer.hpp:84
armnn::QLstmOptPeepholeParameters::m_CellToForgetWeights
std::shared_ptr< ConstTensorHandle > m_CellToForgetWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
Definition: QLstmLayer.hpp:51
armnn::QLstmDescriptor
A QLstmDescriptor for the QLstmLayer.
Definition: Descriptors.hpp:1380
armnn::QLstmBasicParameters::m_ForgetGateBias
std::shared_ptr< ConstTensorHandle > m_ForgetGateBias
A unique pointer to represent 1D bias tensor with dimensions [num_units] (int32).
Definition: QLstmLayer.hpp:31
armnn::QLstmLayer
This layer represents a QLstm operation.
Definition: QLstmLayer.hpp:79
armnn::QLstmOptLayerNormParameters::m_ForgetLayerNormWeights
std::shared_ptr< ConstTensorHandle > m_ForgetLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
Definition: QLstmLayer.hpp:71
armnn::QLstmLayer::QLstmLayer
QLstmLayer(const QLstmDescriptor &param, const char *name)
Constructor to create a QLstmLayer.
Definition: QLstmLayer.cpp:17
armnn::QLstmLayer::Clone
QLstmLayer * Clone(Graph &graph) const override
Creates a dynamically-allocated copy of this layer.
Definition: QLstmLayer.cpp:81
armnn::QLstmOptPeepholeParameters::m_CellToOutputWeights
std::shared_ptr< ConstTensorHandle > m_CellToOutputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
Definition: QLstmLayer.hpp:53
armnn::QLstmOptProjectionParameters
Definition: QLstmLayer.hpp:38
armnn::QLstmOptLayerNormParameters::m_OutputLayerNormWeights
std::shared_ptr< ConstTensorHandle > m_OutputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
Definition: QLstmLayer.hpp:75
armnn::QLstmOptLayerNormParameters
Definition: QLstmLayer.hpp:66
armnn::IStrategy
Definition: IStrategy.hpp:16
armnn::LayerWithParameters
Definition: LayerWithParameters.hpp:14
armnn::QLstmOptProjectionParameters::m_ProjectionWeights
std::shared_ptr< ConstTensorHandle > m_ProjectionWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units] (QSymmS8).
Definition: QLstmLayer.hpp:41
armnn::QLstmOptLayerNormParameters::m_CellLayerNormWeights
std::shared_ptr< ConstTensorHandle > m_CellLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
Definition: QLstmLayer.hpp:73
armnn::IConnectableLayer::ImmutableConstantTensors
std::vector< std::reference_wrapper< const std::shared_ptr< ConstTensorHandle > >> ImmutableConstantTensors
Definition: INetwork.hpp:141
armnn::QLstmBasicParameters
Definition: QLstmLayer.hpp:14
armnn::QLstmOptPeepholeParameters::m_CellToInputWeights
std::shared_ptr< ConstTensorHandle > m_CellToInputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
Definition: QLstmLayer.hpp:49
armnn::QLstmLayer::CreateWorkload
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const override
Makes a workload for the QLstm type.
Definition: QLstmLayer.cpp:22
armnn::IWorkloadFactory
Definition: WorkloadFactory.hpp:22
armnn::QLstmOptCifgParameters::m_RecurrentToInputWeights
std::shared_ptr< ConstTensorHandle > m_RecurrentToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units] (QSymmS8).
Definition: QLstmLayer.hpp:61
armnn::QLstmLayer::~QLstmLayer
~QLstmLayer()=default
Default destructor.
armnn::QLstmOptCifgParameters::m_InputGateBias
std::shared_ptr< ConstTensorHandle > m_InputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units] (int32).
Definition: QLstmLayer.hpp:63
armnn::QLstmOptLayerNormParameters::m_InputLayerNormWeights
std::shared_ptr< ConstTensorHandle > m_InputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units] (QSymmS16).
Definition: QLstmLayer.hpp:69
LayerWithParameters.hpp
armnn::QLstmLayer::ExecuteStrategy
void ExecuteStrategy(IStrategy &strategy) const override
Apply a visitor to this layer.
Definition: QLstmLayer.cpp:307
armnn::QLstmLayer::GetConstantTensorsByRef
Layer::ImmutableConstantTensors GetConstantTensorsByRef() const override
Retrieve the handles to the constant values stored by the layer.
Definition: QLstmLayer.cpp:272
armnn::QLstmLayer::m_LayerNormParameters
QLstmOptLayerNormParameters m_LayerNormParameters
Definition: QLstmLayer.hpp:87
armnn::QLstmBasicParameters::m_RecurrentToOutputWeights
std::shared_ptr< ConstTensorHandle > m_RecurrentToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [num_units, outputSize] (QSymmS8).
Definition: QLstmLayer.hpp:28
armnn::QLstmOptCifgParameters
Definition: QLstmLayer.hpp:56
armnn::QLstmLayer::m_PeepholeParameters
QLstmOptPeepholeParameters m_PeepholeParameters
Definition: QLstmLayer.hpp:86
armnn::QLstmBasicParameters::m_CellBias
std::shared_ptr< ConstTensorHandle > m_CellBias
A unique pointer to represent 1D bias tensor with dimensions [num_units] (int32).
Definition: QLstmLayer.hpp:33
armnn::QLstmBasicParameters::m_OutputGateBias
std::shared_ptr< ConstTensorHandle > m_OutputGateBias
A unique pointer to represent 1D bias tensor with dimensions [num_units] (int32).
Definition: QLstmLayer.hpp:35
armnn::QLstmBasicParameters::m_RecurrentToCellWeights
std::shared_ptr< ConstTensorHandle > m_RecurrentToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [num_units, outputSize] (QSymmS8).
Definition: QLstmLayer.hpp:26
armnn::QLstmOptCifgParameters::m_InputToInputWeights
std::shared_ptr< ConstTensorHandle > m_InputToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units] (QSymmS8).
Definition: QLstmLayer.hpp:59
armnn::QLstmLayer::ValidateTensorShapesFromInputs
void ValidateTensorShapesFromInputs() override
Check if the input tensor shape(s) will lead to a valid configuration of QLstmLayer.
Definition: QLstmLayer.cpp:170
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::QLstmLayer::m_ProjectionParameters
QLstmOptProjectionParameters m_ProjectionParameters
Definition: QLstmLayer.hpp:85
armnn::QLstmLayer::InferOutputShapes
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,...
Definition: QLstmLayer.cpp:153
armnn::QLstmBasicParameters::m_RecurrentToForgetWeights
std::shared_ptr< ConstTensorHandle > m_RecurrentToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [num_units, outputSize] (QSymmS8).
Definition: QLstmLayer.hpp:24
armnn::QLstmOptProjectionParameters::m_ProjectionBias
std::shared_ptr< ConstTensorHandle > m_ProjectionBias
A unique pointer to represent 1D weights tensor with dimensions [output_size] (int32).
Definition: QLstmLayer.hpp:43
armnn::QLstmLayer::m_BasicParameters
QLstmBasicParameters m_BasicParameters
Definition: QLstmLayer.hpp:83
armnn::QLstmOptPeepholeParameters
Definition: QLstmLayer.hpp:46
armnn::QLstmBasicParameters::m_InputToOutputWeights
std::shared_ptr< ConstTensorHandle > m_InputToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [num_units, inputSize] (QSymmS8).
Definition: QLstmLayer.hpp:21
armnn::Graph
Definition: Graph.hpp:30
armnn::QLstmBasicParameters::m_InputToForgetWeights
std::shared_ptr< ConstTensorHandle > m_InputToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [num_units, inputSize] (QSymmS8).
Definition: QLstmLayer.hpp:17
armnn::QLstmBasicParameters::m_InputToCellWeights
std::shared_ptr< ConstTensorHandle > m_InputToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [num_units, inputSize] (QSymmS8).
Definition: QLstmLayer.hpp:19