ArmNN
 24.08
NeonQuantizedLstmWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019,2021-2023 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 #include "NeonWorkloadUtils.hpp"
8 
12 
13 namespace armnn
14 {
15 using namespace armcomputetensorutils;
16 
18  const WorkloadInfo &info)
20 {
21  // Basic parameters
22  m_InputToInputWeightsTensor = std::make_unique<arm_compute::Tensor>();
23  BuildArmComputeTensor(*m_InputToInputWeightsTensor, m_Data.m_InputToInputWeights->GetTensorInfo());
24 
25  m_InputToForgetWeightsTensor = std::make_unique<arm_compute::Tensor>();
26  BuildArmComputeTensor(*m_InputToForgetWeightsTensor, m_Data.m_InputToForgetWeights->GetTensorInfo());
27 
28  m_InputToCellWeightsTensor = std::make_unique<arm_compute::Tensor>();
29  BuildArmComputeTensor(*m_InputToCellWeightsTensor, m_Data.m_InputToCellWeights->GetTensorInfo());
30 
31  m_InputToOutputWeightsTensor = std::make_unique<arm_compute::Tensor>();
32  BuildArmComputeTensor(*m_InputToOutputWeightsTensor, m_Data.m_InputToOutputWeights->GetTensorInfo());
33 
34  m_RecurrentToInputWeightsTensor = std::make_unique<arm_compute::Tensor>();
35  BuildArmComputeTensor(*m_RecurrentToInputWeightsTensor, m_Data.m_RecurrentToInputWeights->GetTensorInfo());
36 
37  m_RecurrentToForgetWeightsTensor = std::make_unique<arm_compute::Tensor>();
38  BuildArmComputeTensor(*m_RecurrentToForgetWeightsTensor, m_Data.m_RecurrentToForgetWeights->GetTensorInfo());
39 
40  m_RecurrentToCellWeightsTensor = std::make_unique<arm_compute::Tensor>();
41  BuildArmComputeTensor(*m_RecurrentToCellWeightsTensor, m_Data.m_RecurrentToCellWeights->GetTensorInfo());
42 
43  m_RecurrentToOutputWeightsTensor = std::make_unique<arm_compute::Tensor>();
44  BuildArmComputeTensor(*m_RecurrentToOutputWeightsTensor, m_Data.m_RecurrentToOutputWeights->GetTensorInfo());
45 
46  m_InputGateBiasTensor = std::make_unique<arm_compute::Tensor>();
47  BuildArmComputeTensor(*m_InputGateBiasTensor, m_Data.m_InputGateBias->GetTensorInfo());
48 
49  m_ForgetGateBiasTensor = std::make_unique<arm_compute::Tensor>();
50  BuildArmComputeTensor(*m_ForgetGateBiasTensor, m_Data.m_ForgetGateBias->GetTensorInfo());
51 
52  m_CellBiasTensor = std::make_unique<arm_compute::Tensor>();
53  BuildArmComputeTensor(*m_CellBiasTensor, m_Data.m_CellBias->GetTensorInfo());
54 
55  m_OutputGateBiasTensor = std::make_unique<arm_compute::Tensor>();
56  BuildArmComputeTensor(*m_OutputGateBiasTensor, m_Data.m_OutputGateBias->GetTensorInfo());
57 
58  const arm_compute::ITensor& input = static_cast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
59  arm_compute::ITensor& cell_state_in = static_cast<IAclTensorHandle*>(m_Data.m_Inputs[1])->GetTensor();
60  const arm_compute::ITensor& output_state_in = static_cast<IAclTensorHandle*>(m_Data.m_Inputs[2])->GetTensor();
61 
62  arm_compute::ITensor& cell_state_out = static_cast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
63  arm_compute::ITensor& output_state_out = static_cast<IAclTensorHandle*>(m_Data.m_Outputs[1])->GetTensor();
64 
65  m_QuantizedLstmLayer.configure(&input,
66  m_InputToInputWeightsTensor.get(),
67  m_InputToForgetWeightsTensor.get(),
68  m_InputToCellWeightsTensor.get(),
69  m_InputToOutputWeightsTensor.get(),
70  m_RecurrentToInputWeightsTensor.get(),
71  m_RecurrentToForgetWeightsTensor.get(),
72  m_RecurrentToCellWeightsTensor.get(),
73  m_RecurrentToOutputWeightsTensor.get(),
74  m_InputGateBiasTensor.get(),
75  m_ForgetGateBiasTensor.get(),
76  m_CellBiasTensor.get(),
77  m_OutputGateBiasTensor.get(),
78  &cell_state_in,
79  &output_state_in,
80  &cell_state_out,
81  &output_state_out);
82 
83  InitializeArmComputeTensorData(*m_InputToInputWeightsTensor,
85 
86  InitializeArmComputeTensorData(*m_InputToForgetWeightsTensor,
88 
89  InitializeArmComputeTensorData(*m_InputToCellWeightsTensor,
91 
92  InitializeArmComputeTensorData(*m_InputToOutputWeightsTensor,
94 
95  InitializeArmComputeTensorData(*m_RecurrentToInputWeightsTensor,
97 
98  InitializeArmComputeTensorData(*m_RecurrentToForgetWeightsTensor,
100 
101  InitializeArmComputeTensorData(*m_RecurrentToCellWeightsTensor,
103 
104  InitializeArmComputeTensorData(*m_RecurrentToOutputWeightsTensor,
106 
107  InitializeArmComputeTensorData(*m_InputGateBiasTensor,
109 
110  InitializeArmComputeTensorData(*m_ForgetGateBiasTensor,
112 
113  InitializeArmComputeTensorData(*m_CellBiasTensor,
115 
116  InitializeArmComputeTensorData(*m_OutputGateBiasTensor,
118 
119  // Force Compute Library to perform the necessary copying and reshaping, after which
120  // delete all the input tensors that will no longer be needed
121  m_QuantizedLstmLayer.prepare();
122  FreeUnusedTensors();
123 }
124 
126 {
127  ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID("NeonQuantizedLstmWorkload_Execute");
128  m_QuantizedLstmLayer.run();
129 }
130 
132  const TensorInfo& cellStateIn,
133  const TensorInfo& outputStateIn,
134  const TensorInfo& cellStateOut,
135  const TensorInfo& outputStateOut,
136  const QuantizedLstmInputParamsInfo& paramsInfo)
137 {
138  // The inputs and outputs
139  const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input);
140  const arm_compute::TensorInfo aclCellStateInInfo = BuildArmComputeTensorInfo(cellStateIn);
141  const arm_compute::TensorInfo aclOutputStateInInfo = BuildArmComputeTensorInfo(outputStateIn);
142  const arm_compute::TensorInfo aclCellStateOutInfo = BuildArmComputeTensorInfo(cellStateOut);
143  const arm_compute::TensorInfo aclOutputStateOutInfo = BuildArmComputeTensorInfo(outputStateOut);
144 
145  // Basic parameters
146  const arm_compute::TensorInfo aclInputToInputWeightsInfo
147  = BuildArmComputeTensorInfo(paramsInfo.GetInputToInputWeights());
148  const arm_compute::TensorInfo aclInputToForgetWeightsInfo
149  = BuildArmComputeTensorInfo(paramsInfo.GetInputToForgetWeights());
150  const arm_compute::TensorInfo aclInputToCellWeightsInfo
151  = BuildArmComputeTensorInfo(paramsInfo.GetInputToCellWeights());
152  const arm_compute::TensorInfo aclInputToOutputWeightsInfo
153  = BuildArmComputeTensorInfo(paramsInfo.GetInputToOutputWeights());
154 
155  const arm_compute::TensorInfo aclRecurrentToInputWeightsInfo
156  = BuildArmComputeTensorInfo(paramsInfo.GetRecurrentToInputWeights());
157  const arm_compute::TensorInfo aclRecurrentToForgetWeightsInfo
158  = BuildArmComputeTensorInfo(paramsInfo.GetRecurrentToForgetWeights());
159  const arm_compute::TensorInfo aclRecurrentToCellWeightsInfo
160  = BuildArmComputeTensorInfo(paramsInfo.GetRecurrentToCellWeights());
161  const arm_compute::TensorInfo aclRecurrentToOutputWeightsInfo
162  = BuildArmComputeTensorInfo(paramsInfo.GetRecurrentToOutputWeights());
163 
164  const arm_compute::TensorInfo aclInputGateBiasInfo
165  = BuildArmComputeTensorInfo(paramsInfo.GetInputGateBias());
166  const arm_compute::TensorInfo aclForgetGateBiasInfo
167  = BuildArmComputeTensorInfo(paramsInfo.GetForgetGateBias());
168  const arm_compute::TensorInfo aclCellBiasInfo
169  = BuildArmComputeTensorInfo(paramsInfo.GetCellBias());
170  const arm_compute::TensorInfo aclOutputGateBiasInfo
171  = BuildArmComputeTensorInfo(paramsInfo.GetOutputGateBias());
172 
173  return arm_compute::NELSTMLayerQuantized::validate(&aclInputInfo,
174  &aclInputToInputWeightsInfo,
175  &aclInputToForgetWeightsInfo,
176  &aclInputToCellWeightsInfo,
177  &aclInputToOutputWeightsInfo,
178  &aclRecurrentToInputWeightsInfo,
179  &aclRecurrentToForgetWeightsInfo,
180  &aclRecurrentToCellWeightsInfo,
181  &aclRecurrentToOutputWeightsInfo,
182  &aclInputGateBiasInfo,
183  &aclForgetGateBiasInfo,
184  &aclCellBiasInfo,
185  &aclOutputGateBiasInfo,
186  &aclCellStateInInfo,
187  &aclOutputStateInInfo,
188  &aclCellStateOutInfo,
189  &aclOutputStateOutInfo);
190 }
191 
192 void NeonQuantizedLstmWorkload::FreeUnusedTensors()
193 {
194  FreeTensorIfUnused(m_InputToInputWeightsTensor);
195  FreeTensorIfUnused(m_InputToForgetWeightsTensor);
196  FreeTensorIfUnused(m_InputToCellWeightsTensor);
197  FreeTensorIfUnused(m_InputToOutputWeightsTensor);
198  FreeTensorIfUnused(m_RecurrentToInputWeightsTensor);
199  FreeTensorIfUnused(m_RecurrentToForgetWeightsTensor);
200  FreeTensorIfUnused(m_RecurrentToCellWeightsTensor);
201  FreeTensorIfUnused(m_RecurrentToOutputWeightsTensor);
202  FreeTensorIfUnused(m_InputGateBiasTensor);
203  FreeTensorIfUnused(m_ForgetGateBiasTensor);
204  FreeTensorIfUnused(m_CellBiasTensor);
205  FreeTensorIfUnused(m_OutputGateBiasTensor);
206  FreeTensorIfUnused(m_CellStateInTensor);
207  FreeTensorIfUnused(m_OutputStateInTensor);
208  FreeTensorIfUnused(m_CellStateOutTensor);
209 }
210 
211 } //namespace armnn
armnn::QuantizedLstmQueueDescriptor::m_CellBias
const ConstTensorHandle * m_CellBias
Definition: WorkloadData.hpp:645
armnn::QuantizedLstmInputParamsInfo::GetForgetGateBias
const TensorInfo & GetForgetGateBias() const
Definition: QuantizedLstmParams.hpp:203
armnn::QuantizedLstmQueueDescriptor::m_RecurrentToInputWeights
const ConstTensorHandle * m_RecurrentToInputWeights
Definition: WorkloadData.hpp:638
armnn::QuantizedLstmInputParamsInfo::GetInputToForgetWeights
const TensorInfo & GetInputToForgetWeights() const
Definition: QuantizedLstmParams.hpp:169
armnn::QuantizedLstmQueueDescriptor::m_InputToForgetWeights
const ConstTensorHandle * m_InputToForgetWeights
Definition: WorkloadData.hpp:634
armnn::QuantizedLstmInputParamsInfo::GetRecurrentToForgetWeights
const TensorInfo & GetRecurrentToForgetWeights() const
Definition: QuantizedLstmParams.hpp:186
armnn::TensorInfo
Definition: Tensor.hpp:152
NeonTensorHandle.hpp
armnn::QuantizedLstmQueueDescriptor::m_RecurrentToOutputWeights
const ConstTensorHandle * m_RecurrentToOutputWeights
Definition: WorkloadData.hpp:641
armnn::QuantizedLstmQueueDescriptor::m_InputGateBias
const ConstTensorHandle * m_InputGateBias
Definition: WorkloadData.hpp:643
armnn::ConstTensorHandle::GetTensorInfo
const TensorInfo & GetTensorInfo() const
Definition: TensorHandle.hpp:40
armnn::QuantizedLstmInputParamsInfo::GetInputGateBias
const TensorInfo & GetInputGateBias() const
Definition: QuantizedLstmParams.hpp:199
armnn::NeonQuantizedLstmWorkload::Execute
virtual void Execute() const override
Definition: NeonQuantizedLstmWorkload.cpp:125
armnn::QuantizedLstmInputParamsInfo
Definition: QuantizedLstmParams.hpp:119
armnn::InitializeArmComputeTensorData
void InitializeArmComputeTensorData(arm_compute::Tensor &tensor, TensorInfo tensorInfo, const ITensorHandle *handle)
Definition: NeonWorkloadUtils.hpp:69
armnn::QuantizedLstmQueueDescriptor::m_RecurrentToCellWeights
const ConstTensorHandle * m_RecurrentToCellWeights
Definition: WorkloadData.hpp:640
armnn::QuantizedLstmInputParamsInfo::GetRecurrentToOutputWeights
const TensorInfo & GetRecurrentToOutputWeights() const
Definition: QuantizedLstmParams.hpp:194
armnn::QuantizedLstmInputParamsInfo::GetInputToInputWeights
const TensorInfo & GetInputToInputWeights() const
Definition: QuantizedLstmParams.hpp:165
armnn::IAclTensorHandle
Definition: ArmComputeTensorHandle.hpp:16
armnn::QuantizedLstmInputParamsInfo::GetCellBias
const TensorInfo & GetCellBias() const
Definition: QuantizedLstmParams.hpp:207
armnn::QuantizedLstmQueueDescriptor::m_InputToInputWeights
const ConstTensorHandle * m_InputToInputWeights
Definition: WorkloadData.hpp:633
armnn::WorkloadInfo
Contains information about TensorInfos of a layer.
Definition: WorkloadInfo.hpp:16
armnn::QuantizedLstmQueueDescriptor::m_RecurrentToForgetWeights
const ConstTensorHandle * m_RecurrentToForgetWeights
Definition: WorkloadData.hpp:639
armnn::QuantizedLstmInputParamsInfo::GetRecurrentToCellWeights
const TensorInfo & GetRecurrentToCellWeights() const
Definition: QuantizedLstmParams.hpp:190
armnn::QuantizedLstmQueueDescriptor::m_InputToCellWeights
const ConstTensorHandle * m_InputToCellWeights
Definition: WorkloadData.hpp:635
armnn::QuantizedLstmInputParamsInfo::GetInputToOutputWeights
const TensorInfo & GetInputToOutputWeights() const
Definition: QuantizedLstmParams.hpp:177
armnn::BoostLogSeverityMapping::info
@ info
armnn::QueueDescriptor::m_Outputs
std::vector< ITensorHandle * > m_Outputs
Definition: WorkloadData.hpp:27
armnn::NeonQuantizedLstmWorkload::NeonQuantizedLstmWorkload
NeonQuantizedLstmWorkload(const QuantizedLstmQueueDescriptor &descriptor, const WorkloadInfo &info)
Definition: NeonQuantizedLstmWorkload.cpp:17
armnn::NeonQuantizedLstmWorkloadValidate
arm_compute::Status NeonQuantizedLstmWorkloadValidate(const TensorInfo &input, const TensorInfo &cellStateIn, const TensorInfo &outputStateIn, const TensorInfo &cellStateOut, const TensorInfo &outputStateOut, const QuantizedLstmInputParamsInfo &paramsInfo)
Definition: NeonQuantizedLstmWorkload.cpp:131
armnn::QuantizedLstmQueueDescriptor::m_InputToOutputWeights
const ConstTensorHandle * m_InputToOutputWeights
Definition: WorkloadData.hpp:636
armnn::QuantizedLstmQueueDescriptor
Definition: WorkloadData.hpp:614
TensorHandle.hpp
armnn::Status
Status
Definition: Types.hpp:42
armnn::BaseWorkload< QuantizedLstmQueueDescriptor >::m_Data
QuantizedLstmQueueDescriptor m_Data
Definition: Workload.hpp:89
armnn::QuantizedLstmInputParamsInfo::GetOutputGateBias
const TensorInfo & GetOutputGateBias() const
Definition: QuantizedLstmParams.hpp:211
NeonQuantizedLstmWorkload.hpp
NeonWorkloadUtils.hpp
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
ArmComputeTensorUtils.hpp
ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID
#define ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID(label)
Creates a profiling event that uses GetGuid() and GetName() from the calling class.
Definition: NeonWorkloadUtils.hpp:33
armnn::QuantizedLstmInputParamsInfo::GetInputToCellWeights
const TensorInfo & GetInputToCellWeights() const
Definition: QuantizedLstmParams.hpp:173
armnn::QuantizedLstmQueueDescriptor::m_OutputGateBias
const ConstTensorHandle * m_OutputGateBias
Definition: WorkloadData.hpp:646
armnn::NeonBaseWorkload
Definition: NeonBaseWorkload.hpp:13
armnn::QuantizedLstmInputParamsInfo::GetRecurrentToInputWeights
const TensorInfo & GetRecurrentToInputWeights() const
Definition: QuantizedLstmParams.hpp:182
armnn::QueueDescriptor::m_Inputs
std::vector< ITensorHandle * > m_Inputs
Definition: WorkloadData.hpp:26
armnn::QuantizedLstmQueueDescriptor::m_ForgetGateBias
const ConstTensorHandle * m_ForgetGateBias
Definition: WorkloadData.hpp:644