ArmNN
 24.02
ClUnidirectionalSequenceLstmFloatWorkload.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include <armnn/Descriptors.hpp>
9 #include <armnn/LstmParams.hpp>
12 
13 #include <arm_compute/graph/Tensor.h>
14 #include <arm_compute/runtime/CL/functions/CLLSTMLayer.h>
15 #include <arm_compute/runtime/CL/functions/CLPermute.h>
16 #include <arm_compute/runtime/CL/functions/CLSplit.h>
17 #include <arm_compute/runtime/CL/functions/CLConcatenateLayer.h>
18 
19 namespace armnn
20 {
21 
22 class ClUnidirectionalSequenceLstmFloatWorkload : public FloatWorkload<UnidirectionalSequenceLstmQueueDescriptor>
23 {
24 public:
26  const WorkloadInfo& info,
27  const arm_compute::CLCompileContext& clCompileContext);
28  virtual void Execute() const override;
29 
30 private:
31 
32  //
33  // ACL layers required to fully form a Unidirectional Sequence LSTM layer.
34  //
35 
36  // permutation for input (only used when input is batch major)
37  mutable std::unique_ptr<arm_compute::CLPermute> m_Permute1;
38  mutable std::unique_ptr<arm_compute::IFunction> m_Splitter;
39  mutable std::vector<std::unique_ptr<arm_compute::CLLSTMLayer>> m_Layers;
40  mutable std::unique_ptr<arm_compute::CLConcatenateLayer> m_Concat;
41  // permutation for output (only used when input is batch major)
42  mutable std::unique_ptr<arm_compute::CLPermute> m_Permute2;
43 
44  //
45  // ACL LSTM arm_compute::CLTensors.
46  //
47  std::unique_ptr<arm_compute::CLTensor> m_InputToInputWeightsTensor;
48  std::unique_ptr<arm_compute::CLTensor> m_InputToForgetWeightsTensor;
49  std::unique_ptr<arm_compute::CLTensor> m_InputToCellWeightsTensor;
50  std::unique_ptr<arm_compute::CLTensor> m_InputToOutputWeightsTensor;
51  std::unique_ptr<arm_compute::CLTensor> m_RecurrentToInputWeightsTensor;
52  std::unique_ptr<arm_compute::CLTensor> m_RecurrentToForgetWeightsTensor;
53  std::unique_ptr<arm_compute::CLTensor> m_RecurrentToCellWeightsTensor;
54  std::unique_ptr<arm_compute::CLTensor> m_RecurrentToOutputWeightsTensor;
55  std::unique_ptr<arm_compute::CLTensor> m_CellToInputWeightsTensor;
56  std::unique_ptr<arm_compute::CLTensor> m_CellToForgetWeightsTensor;
57  std::unique_ptr<arm_compute::CLTensor> m_CellToOutputWeightsTensor;
58  std::unique_ptr<arm_compute::CLTensor> m_InputGateBiasTensor;
59  std::unique_ptr<arm_compute::CLTensor> m_ForgetGateBiasTensor;
60  std::unique_ptr<arm_compute::CLTensor> m_CellBiasTensor;
61  std::unique_ptr<arm_compute::CLTensor> m_OutputGateBiasTensor;
62  std::unique_ptr<arm_compute::CLTensor> m_ProjectionWeightsTensor;
63  std::unique_ptr<arm_compute::CLTensor> m_ProjectionBiasTensor;
64 
65  std::unique_ptr<arm_compute::CLTensor> m_ScratchBuffer;
66 
67  std::unique_ptr<arm_compute::CLTensor> m_InputLayerNormWeightsTensor;
68  std::unique_ptr<arm_compute::CLTensor> m_ForgetLayerNormWeightsTensor;
69  std::unique_ptr<arm_compute::CLTensor> m_CellLayerNormWeightsTensor;
70  std::unique_ptr<arm_compute::CLTensor> m_OutputLayerNormWeightsTensor;
71 
72  //
73  // Additional ACL arm_compute::CLTensors and std::vector<arm_compute::CLTensor>.
74  // Required to perform splitting, concatenation and permutations.
75  //
76  arm_compute::CLTensor m_PermuteFirstOut;
77  std::vector<arm_compute::CLTensor> m_SplitterOutputsTensors;
78  std::vector<arm_compute::CLTensor> m_ConcatInputsTensors;
79  std::vector<arm_compute::ICLTensor*> m_SplitterOutputs;
80  std::vector<const arm_compute::ICLTensor*> m_ConcatInputs;
81  arm_compute::CLTensor concat_out;
82 
83  void FreeUnusedTensors();
84 };
85 
88  const TensorInfo& outputStateIn,
89  const TensorInfo& cellStateIn,
90  const TensorInfo& outputStateOut,
91  const TensorInfo& cellStateOut,
92  const TensorInfo& output,
93  const UnidirectionalSequenceLstmDescriptor& descriptor,
94  const LstmInputParamsInfo& paramsInfo);
95 
96 } //namespace armnn
armnn::ClUnidirectionalSequenceLstmFloatWorkload
Definition: ClUnidirectionalSequenceLstmFloatWorkload.hpp:22
Descriptors.hpp
WorkloadData.hpp
armnn::TensorInfo
Definition: Tensor.hpp:152
armnn::ClUnidirectionalSequenceLstmFloatWorkloadValidate
arm_compute::Status ClUnidirectionalSequenceLstmFloatWorkloadValidate(const TensorInfo &input, const TensorInfo &outputStateIn, const TensorInfo &cellStateIn, const TensorInfo &outputStateOut, const TensorInfo &cellStateOut, const TensorInfo &output, const UnidirectionalSequenceLstmDescriptor &descriptor, const LstmInputParamsInfo &paramsInfo)
Definition: ClUnidirectionalSequenceLstmFloatWorkload.cpp:508
armnn::TypedWorkload
Definition: Workload.hpp:101
armnn::ClUnidirectionalSequenceLstmFloatWorkload::ClUnidirectionalSequenceLstmFloatWorkload
ClUnidirectionalSequenceLstmFloatWorkload(const UnidirectionalSequenceLstmQueueDescriptor &descriptor, const WorkloadInfo &info, const arm_compute::CLCompileContext &clCompileContext)
Definition: ClUnidirectionalSequenceLstmFloatWorkload.cpp:32
LstmParams.hpp
armnn::WorkloadInfo
Contains information about TensorInfos of a layer.
Definition: WorkloadInfo.hpp:16
Workload.hpp
armnn::BoostLogSeverityMapping::info
@ info
armnn::LstmDescriptor
An LstmDescriptor for the LstmLayer.
Definition: Descriptors.hpp:1102
armnn::Status
Status
Definition: Types.hpp:42
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::LstmInputParamsInfo
Definition: LstmParams.hpp:63
armnn::UnidirectionalSequenceLstmQueueDescriptor
Definition: WorkloadData.hpp:696
armnn::ClUnidirectionalSequenceLstmFloatWorkload::Execute
virtual void Execute() const override
Definition: ClUnidirectionalSequenceLstmFloatWorkload.cpp:482