ArmNN
 24.02
QuantizedLstmLayer.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 
7 #include <Layer.hpp>
8 
9 namespace armnn
10 {
11 
12 class ScopedTensorHandle;
13 
15 {
16  /// A unique pointer to represent 2D weights tensor with dimensions [outputSize, inputSize] (QAsymm8).
17  std::shared_ptr<ConstTensorHandle> m_InputToInputWeights;
18  /// A unique pointer to represent 2D weights tensor with dimensions [outputSize, inputSize] (QAsymm8).
19  std::shared_ptr<ConstTensorHandle> m_InputToForgetWeights;
20  /// A unique pointer to represent 2D weights tensor with dimensions [outputSize, inputSize] (QAsymm8).
21  std::shared_ptr<ConstTensorHandle> m_InputToCellWeights;
22  /// A unique pointer to represent 2D weights tensor with dimensions [outputSize, inputSize] (QAsymm8).
23  std::shared_ptr<ConstTensorHandle> m_InputToOutputWeights;
24 
25  /// A unique pointer to represent 2D weights tensor with dimensions [outputSize, outputSize] (QAsymm8).
26  std::shared_ptr<ConstTensorHandle> m_RecurrentToInputWeights;
27  /// A unique pointer to represent 2D weights tensor with dimensions [outputSize, outputSize] (QAsymm8).
28  std::shared_ptr<ConstTensorHandle> m_RecurrentToForgetWeights;
29  /// A unique pointer to represent 2D weights tensor with dimensions [outputSize, outputSize] (QAsymm8).
30  std::shared_ptr<ConstTensorHandle> m_RecurrentToCellWeights;
31  /// A unique pointer to represent 2D weights tensor with dimensions [outputSize, outputSize] (QAsymm8).
32  std::shared_ptr<ConstTensorHandle> m_RecurrentToOutputWeights;
33 
34  /// A unique pointer to represent 1D bias tensor with dimensions [outputSize] (int32).
35  std::shared_ptr<ConstTensorHandle> m_InputGateBias;
36  /// A unique pointer to represent 1D bias tensor with dimensions [outputSize] (int32).
37  std::shared_ptr<ConstTensorHandle> m_ForgetGateBias;
38  /// A unique pointer to represent 1D bias tensor with dimensions [outputSize] (int32).
39  std::shared_ptr<ConstTensorHandle> m_CellBias;
40  /// A unique pointer to represent 1D bias tensor with dimensions [outputSize] (int32).
41  std::shared_ptr<ConstTensorHandle> m_OutputGateBias;
42 };
43 
44 /// This layer represents a QuantizedLstm operation.
45 class QuantizedLstmLayer : public Layer
46 {
47 public:
48 
50 
51  /// Makes a workload for the QuantizedLstm type.
52  /// @param [in] graph The graph where this layer can be found.
53  /// @param [in] factory The workload factory which will create the workload.
54  /// @return A pointer to the created workload, or nullptr if not created.
55  virtual std::unique_ptr<IWorkload> CreateWorkload(const IWorkloadFactory& factory) const override;
56 
57  /// Creates a dynamically-allocated copy of this layer.
58  /// @param [in] graph The graph into which this layer is being cloned.
59  QuantizedLstmLayer* Clone(Graph& graph) const override;
60 
61  /// Check if the input tensor shape(s)
62  /// will lead to a valid configuration of @ref QuantizedLstmLayer.
63  /// @param [in] shapeInferenceMethod Indicates if output shape shall be overwritten or just validated.
64  void ValidateTensorShapesFromInputs() override;
65 
66  /// By default returns inputShapes if the number of inputs are equal to number of outputs,
67  /// otherwise infers the output shapes from given input shapes and layer properties.
68  /// @param [in] inputShapes The input shapes layer has.
69  /// @return A vector to the inferred output shape.
70  std::vector<TensorShape> InferOutputShapes(const std::vector<TensorShape>& inputShapes) const override;
71 
72  void ExecuteStrategy(IStrategy& strategy) const override;
73 
74 protected:
75  /// Constructor to create a QuantizedLstmLayer.
76  /// @param [in] name Optional name for the layer.
77  QuantizedLstmLayer(const char* name);
78 
79  /// Default destructor
80  ~QuantizedLstmLayer() = default;
81 
82  /// Retrieve the handles to the constant values stored by the layer.
83  /// @return A vector of the constant tensors stored by this layer.
85 };
86 
87 } // namespace armnn
armnn::QuantizedLstmParameters::m_InputToInputWeights
std::shared_ptr< ConstTensorHandle > m_InputToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [outputSize, inputSize] (QAsymm8).
Definition: QuantizedLstmLayer.hpp:17
armnn::QuantizedLstmParameters::m_CellBias
std::shared_ptr< ConstTensorHandle > m_CellBias
A unique pointer to represent 1D bias tensor with dimensions [outputSize] (int32).
Definition: QuantizedLstmLayer.hpp:39
armnn::QuantizedLstmLayer::ValidateTensorShapesFromInputs
void ValidateTensorShapesFromInputs() override
Check if the input tensor shape(s) will lead to a valid configuration of QuantizedLstmLayer.
Definition: QuantizedLstmLayer.cpp:96
armnn::QuantizedLstmLayer::GetConstantTensorsByRef
Layer::ImmutableConstantTensors GetConstantTensorsByRef() const override
Retrieve the handles to the constant values stored by the layer.
Definition: QuantizedLstmLayer.cpp:151
armnn::QuantizedLstmLayer::Clone
QuantizedLstmLayer * Clone(Graph &graph) const override
Creates a dynamically-allocated copy of this layer.
Definition: QuantizedLstmLayer.cpp:47
armnn::QuantizedLstmParameters::m_OutputGateBias
std::shared_ptr< ConstTensorHandle > m_OutputGateBias
A unique pointer to represent 1D bias tensor with dimensions [outputSize] (int32).
Definition: QuantizedLstmLayer.hpp:41
armnn::QuantizedLstmParameters
Definition: QuantizedLstmLayer.hpp:14
armnn::IStrategy
Definition: IStrategy.hpp:16
armnn::QuantizedLstmParameters::m_RecurrentToOutputWeights
std::shared_ptr< ConstTensorHandle > m_RecurrentToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [outputSize, outputSize] (QAsymm8).
Definition: QuantizedLstmLayer.hpp:32
armnn::QuantizedLstmParameters::m_InputToForgetWeights
std::shared_ptr< ConstTensorHandle > m_InputToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [outputSize, inputSize] (QAsymm8).
Definition: QuantizedLstmLayer.hpp:19
armnn::Layer
Definition: Layer.hpp:230
armnn::IConnectableLayer::ImmutableConstantTensors
std::vector< std::reference_wrapper< const std::shared_ptr< ConstTensorHandle > >> ImmutableConstantTensors
Definition: INetwork.hpp:141
armnn::QuantizedLstmParameters::m_InputToCellWeights
std::shared_ptr< ConstTensorHandle > m_InputToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [outputSize, inputSize] (QAsymm8).
Definition: QuantizedLstmLayer.hpp:21
armnn::QuantizedLstmParameters::m_ForgetGateBias
std::shared_ptr< ConstTensorHandle > m_ForgetGateBias
A unique pointer to represent 1D bias tensor with dimensions [outputSize] (int32).
Definition: QuantizedLstmLayer.hpp:37
armnn::QuantizedLstmParameters::m_InputToOutputWeights
std::shared_ptr< ConstTensorHandle > m_InputToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [outputSize, inputSize] (QAsymm8).
Definition: QuantizedLstmLayer.hpp:23
armnn::IWorkloadFactory
Definition: WorkloadFactory.hpp:22
armnn::QuantizedLstmLayer
This layer represents a QuantizedLstm operation.
Definition: QuantizedLstmLayer.hpp:45
armnn::QuantizedLstmLayer::m_QuantizedLstmParameters
QuantizedLstmParameters m_QuantizedLstmParameters
Definition: QuantizedLstmLayer.hpp:49
armnn::QuantizedLstmLayer::~QuantizedLstmLayer
~QuantizedLstmLayer()=default
Default destructor.
armnn::QuantizedLstmLayer::CreateWorkload
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const override
Makes a workload for the QuantizedLstm type.
Definition: QuantizedLstmLayer.cpp:22
armnn::QuantizedLstmLayer::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: QuantizedLstmLayer.cpp:81
armnn::QuantizedLstmLayer::ExecuteStrategy
void ExecuteStrategy(IStrategy &strategy) const override
Apply a visitor to this layer.
Definition: QuantizedLstmLayer.cpp:173
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
Layer.hpp
armnn::QuantizedLstmParameters::m_RecurrentToCellWeights
std::shared_ptr< ConstTensorHandle > m_RecurrentToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [outputSize, outputSize] (QAsymm8).
Definition: QuantizedLstmLayer.hpp:30
armnn::QuantizedLstmParameters::m_InputGateBias
std::shared_ptr< ConstTensorHandle > m_InputGateBias
A unique pointer to represent 1D bias tensor with dimensions [outputSize] (int32).
Definition: QuantizedLstmLayer.hpp:35
armnn::QuantizedLstmLayer::QuantizedLstmLayer
QuantizedLstmLayer(const char *name)
Constructor to create a QuantizedLstmLayer.
Definition: QuantizedLstmLayer.cpp:17
armnn::Graph
Definition: Graph.hpp:30
armnn::QuantizedLstmParameters::m_RecurrentToInputWeights
std::shared_ptr< ConstTensorHandle > m_RecurrentToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [outputSize, outputSize] (QAsymm8).
Definition: QuantizedLstmLayer.hpp:26
armnn::QuantizedLstmParameters::m_RecurrentToForgetWeights
std::shared_ptr< ConstTensorHandle > m_RecurrentToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [outputSize, outputSize] (QAsymm8).
Definition: QuantizedLstmLayer.hpp:28