ArmNN
 20.02
LstmLayer.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #include "LstmLayer.hpp"
6 
7 #include "LayerCloneBase.hpp"
8 
9 #include <armnn/LstmParams.hpp>
10 #include <armnn/TypesUtils.hpp>
13 
14 namespace armnn
15 {
16 
17 LstmLayer::LstmLayer(const LstmDescriptor& param, const char* name)
18  : LayerWithParameters(3, 4, LayerType::Lstm, param, name)
19 {
20 }
21 
22 std::unique_ptr<IWorkload> LstmLayer::CreateWorkload(const IWorkloadFactory& factory) const
23 {
24  LstmQueueDescriptor descriptor;
25 
26  // Basic parameters
34  descriptor.m_CellBias = m_BasicParameters.m_CellBias.get();
36 
37  // Cifg parameters
39  {
44  }
45 
46  // Projection parameters
48  {
51  }
52 
53  // Peephole parameters
55  {
58  }
59 
60  // Layer normalisation parameters
62  {
64  {
66  }
70  }
71 
72  return factory.CreateLstm(descriptor, PrepInfoAndDesc(descriptor));
73 }
74 
76 {
77  auto layer = CloneBase<LstmLayer>(graph, m_Param, GetName());
78 
80  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_InputToForgetWeights)
81  : nullptr;
82  layer->m_BasicParameters.m_InputToCellWeights = m_BasicParameters.m_InputToCellWeights ?
83  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_InputToCellWeights) : nullptr;
84  layer->m_BasicParameters.m_InputToOutputWeights = m_BasicParameters.m_InputToOutputWeights ?
85  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_InputToOutputWeights) : nullptr;
86  layer->m_BasicParameters.m_RecurrentToForgetWeights = m_BasicParameters.m_RecurrentToForgetWeights ?
87  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_RecurrentToForgetWeights) : nullptr;
88  layer->m_BasicParameters.m_RecurrentToCellWeights = m_BasicParameters.m_RecurrentToCellWeights ?
89  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_RecurrentToCellWeights) : nullptr;
90  layer->m_BasicParameters.m_RecurrentToOutputWeights = m_BasicParameters.m_RecurrentToOutputWeights ?
91  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_RecurrentToOutputWeights) : nullptr;
92  layer->m_BasicParameters.m_ForgetGateBias = m_BasicParameters.m_ForgetGateBias ?
93  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_ForgetGateBias) : nullptr;
94  layer->m_BasicParameters.m_CellBias = m_BasicParameters.m_CellBias ?
95  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_CellBias) : nullptr;
96  layer->m_BasicParameters.m_OutputGateBias = m_BasicParameters.m_OutputGateBias ?
97  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_OutputGateBias) : nullptr;
98 
99  if (!m_Param.m_CifgEnabled)
100  {
101  layer->m_CifgParameters.m_InputToInputWeights = m_CifgParameters.m_InputToInputWeights ?
102  std::make_unique<ScopedCpuTensorHandle>(*m_CifgParameters.m_InputToInputWeights) : nullptr;
103  layer->m_CifgParameters.m_RecurrentToInputWeights = m_CifgParameters.m_RecurrentToInputWeights ?
104  std::make_unique<ScopedCpuTensorHandle>(*m_CifgParameters.m_RecurrentToInputWeights) : nullptr;
105  layer->m_CifgParameters.m_CellToInputWeights = m_CifgParameters.m_CellToInputWeights ?
106  std::make_unique<ScopedCpuTensorHandle>(*m_CifgParameters.m_CellToInputWeights) : nullptr;
107  layer->m_CifgParameters.m_InputGateBias = m_CifgParameters.m_InputGateBias ?
108  std::make_unique<ScopedCpuTensorHandle>(*m_CifgParameters.m_InputGateBias) : nullptr;
109  }
110 
111  if (m_Param.m_ProjectionEnabled)
112  {
113  layer->m_ProjectionParameters.m_ProjectionWeights = m_ProjectionParameters.m_ProjectionWeights ?
114  std::make_unique<ScopedCpuTensorHandle>(*m_ProjectionParameters.m_ProjectionWeights) : nullptr;
115  layer->m_ProjectionParameters.m_ProjectionBias = m_ProjectionParameters.m_ProjectionBias ?
116  std::make_unique<ScopedCpuTensorHandle>(*m_ProjectionParameters.m_ProjectionBias) : nullptr;
117  }
118 
119  if (m_Param.m_PeepholeEnabled)
120  {
121  layer->m_PeepholeParameters.m_CellToForgetWeights = m_PeepholeParameters.m_CellToForgetWeights ?
122  std::make_unique<ScopedCpuTensorHandle>(*m_PeepholeParameters.m_CellToForgetWeights) : nullptr;
123  layer->m_PeepholeParameters.m_CellToOutputWeights = m_PeepholeParameters.m_CellToOutputWeights ?
124  std::make_unique<ScopedCpuTensorHandle>(*m_PeepholeParameters.m_CellToOutputWeights) : nullptr;
125  }
126 
127  if (m_Param.m_LayerNormEnabled)
128  {
129  layer->m_LayerNormParameters.m_InputLayerNormWeights = m_LayerNormParameters.m_InputLayerNormWeights ?
130  std::make_unique<ScopedCpuTensorHandle>(*m_LayerNormParameters.m_InputLayerNormWeights) : nullptr;
131  layer->m_LayerNormParameters.m_ForgetLayerNormWeights = m_LayerNormParameters.m_ForgetLayerNormWeights ?
132  std::make_unique<ScopedCpuTensorHandle>(*m_LayerNormParameters.m_ForgetLayerNormWeights) : nullptr;
133  layer->m_LayerNormParameters.m_CellLayerNormWeights = m_LayerNormParameters.m_CellLayerNormWeights ?
134  std::make_unique<ScopedCpuTensorHandle>(*m_LayerNormParameters.m_CellLayerNormWeights) : nullptr;
135  layer->m_LayerNormParameters.m_OutputLayerNormWeights = m_LayerNormParameters.m_OutputLayerNormWeights ?
136  std::make_unique<ScopedCpuTensorHandle>(*m_LayerNormParameters.m_OutputLayerNormWeights) : nullptr;
137  }
138 
139  return std::move(layer);
140 }
141 
142 std::vector<TensorShape> LstmLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const
143 {
144  BOOST_ASSERT(inputShapes.size() == 3);
145 
146  // Get input values for validation
147  unsigned int batchSize = inputShapes[0][0];
148  unsigned int outputSize = inputShapes[1][1];
149  unsigned int numUnits = inputShapes[2][1];
150 
151  std::vector<TensorShape> outShapes;
152  outShapes.push_back(TensorShape({batchSize, numUnits * (m_Param.m_CifgEnabled ? 3 : 4)}));
153  outShapes.push_back(TensorShape({batchSize, outputSize}));
154  outShapes.push_back(TensorShape({batchSize, numUnits}));
155  outShapes.push_back(TensorShape({batchSize, outputSize}));
156 
157  return outShapes;
158 }
159 
161 {
163 
164  auto inferredShapes = InferOutputShapes( {
168  );
169 
170  BOOST_ASSERT(inferredShapes.size() == 4);
171 
172  // Check if the weights are nullptr
173  BOOST_ASSERT_MSG(m_BasicParameters.m_InputToForgetWeights != nullptr,
174  "LstmLayer: m_BasicParameters.m_InputToForgetWeights should not be null.");
175  BOOST_ASSERT_MSG(m_BasicParameters.m_InputToCellWeights != nullptr,
176  "LstmLayer: m_BasicParameters.m_InputToCellWeights should not be null.");
177  BOOST_ASSERT_MSG(m_BasicParameters.m_InputToOutputWeights != nullptr,
178  "LstmLayer: m_BasicParameters.m_InputToOutputWeights should not be null.");
179  BOOST_ASSERT_MSG(m_BasicParameters.m_RecurrentToForgetWeights != nullptr,
180  "LstmLayer: m_BasicParameters.m_RecurrentToForgetWeights should not be null.");
181  BOOST_ASSERT_MSG(m_BasicParameters.m_RecurrentToCellWeights != nullptr,
182  "LstmLayer: m_BasicParameters.m_RecurrentToCellWeights should not be null.");
183  BOOST_ASSERT_MSG(m_BasicParameters.m_RecurrentToOutputWeights != nullptr,
184  "LstmLayer: m_BasicParameters.m_RecurrentToOutputWeights should not be null.");
185  BOOST_ASSERT_MSG(m_BasicParameters.m_ForgetGateBias != nullptr,
186  "LstmLayer: m_BasicParameters.m_ForgetGateBias should not be null.");
187  BOOST_ASSERT_MSG(m_BasicParameters.m_CellBias != nullptr,
188  "LstmLayer: m_BasicParameters.m_CellBias should not be null.");
189  BOOST_ASSERT_MSG(m_BasicParameters.m_OutputGateBias != nullptr,
190  "LstmLayer: m_BasicParameters.m_OutputGateBias should not be null.");
191 
192  if (!m_Param.m_CifgEnabled)
193  {
194  BOOST_ASSERT_MSG(m_CifgParameters.m_InputToInputWeights != nullptr,
195  "LstmLayer: m_CifgParameters.m_InputToInputWeights should not be null.");
196  BOOST_ASSERT_MSG(m_CifgParameters.m_RecurrentToInputWeights != nullptr,
197  "LstmLayer: m_CifgParameters.m_RecurrentToInputWeights should not be null.");
198  BOOST_ASSERT_MSG(m_CifgParameters.m_InputGateBias != nullptr,
199  "LstmLayer: m_CifgParameters.m_InputGateBias should not be null.");
200 
201  ConditionalThrowIfNotEqual<LayerValidationException>(
202  "LstmLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
204  inferredShapes[0]);
205  }
206  else
207  {
208  BOOST_ASSERT_MSG(m_CifgParameters.m_InputToInputWeights == nullptr,
209  "LstmLayer: m_CifgParameters.m_InputToInputWeights should not have a value when CIFG is enabled.");
210  BOOST_ASSERT_MSG(m_CifgParameters.m_RecurrentToInputWeights == nullptr,
211  "LstmLayer: m_CifgParameters.m_RecurrentToInputWeights should not have a value when CIFG is enabled.");
212  BOOST_ASSERT_MSG(m_CifgParameters.m_CellToInputWeights == nullptr,
213  "LstmLayer: m_CifgParameters.m_CellToInputWeights should not have a value when CIFG is enabled.");
214  BOOST_ASSERT_MSG(m_CifgParameters.m_InputGateBias == nullptr,
215  "LstmLayer: m_CifgParameters.m_InputGateBias should not have a value when CIFG is enabled.");
216 
217  ConditionalThrowIfNotEqual<LayerValidationException>(
218  "LstmLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
220  inferredShapes[0]);
221  }
222 
224  {
225  BOOST_ASSERT_MSG(m_ProjectionParameters.m_ProjectionWeights != nullptr,
226  "LstmLayer: m_ProjectionParameters.m_ProjectionWeights should not be null.");
227  }
228 
230  {
231  BOOST_ASSERT_MSG(m_PeepholeParameters.m_CellToForgetWeights != nullptr,
232  "LstmLayer: m_PeepholeParameters.m_CellToForgetWeights should not be null.");
233  BOOST_ASSERT_MSG(m_PeepholeParameters.m_CellToOutputWeights != nullptr,
234  "LstmLayer: m_PeepholeParameters.m_CellToOutputWeights should not be null.");
235  }
236 
237  ConditionalThrowIfNotEqual<LayerValidationException>(
238  "LstmLayer: TensorShape set on OutputSlot[1] does not match the inferred shape.",
240  inferredShapes[1]);
241  ConditionalThrowIfNotEqual<LayerValidationException>(
242  "LstmLayer: TensorShape set on OutputSlot[2] does not match the inferred shape.",
244  inferredShapes[2]);
245  ConditionalThrowIfNotEqual<LayerValidationException>(
246  "LstmLayer: TensorShape set on OutputSlot[3] does not match the inferred shape.",
248  inferredShapes[3]);
249 
251  {
253  {
254  BOOST_ASSERT_MSG(m_LayerNormParameters.m_InputLayerNormWeights != nullptr,
255  "LstmLayer: m_LayerNormParameters.m_inputLayerNormWeights should not be null.");
256  }
257  BOOST_ASSERT_MSG(m_LayerNormParameters.m_ForgetLayerNormWeights != nullptr,
258  "LstmLayer: m_LayerNormParameters.m_forgetLayerNormWeights should not be null.");
259  BOOST_ASSERT_MSG(m_LayerNormParameters.m_CellLayerNormWeights != nullptr,
260  "LstmLayer: m_LayerNormParameters.m_cellLayerNormWeights should not be null.");
261  BOOST_ASSERT_MSG(m_LayerNormParameters.m_OutputLayerNormWeights != nullptr,
262  "LstmLayer: m_LayerNormParameters.m_outputLayerNormWeights should not be null.");
263  }
264 }
265 
267 {
277 
278  // Cifg parameters
283 
284  // Projection parameters
287 
288  // Peephole parameters
291 
292  // Layer normalisation parameters
297 }
298 
299 void LstmLayer::Accept(ILayerVisitor& visitor) const
300 {
301  LstmInputParams inputParams;
302  ConstTensor inputToInputWeightsTensor;
304  {
305  ConstTensor inputToInputWeightsTensorCopy(m_CifgParameters.m_InputToInputWeights->GetTensorInfo(),
307  inputToInputWeightsTensor = inputToInputWeightsTensorCopy;
308  inputParams.m_InputToInputWeights = &inputToInputWeightsTensor;
309  }
310  ConstTensor inputToForgetWeightsTensor;
312  {
313  ConstTensor inputToForgetWeightsTensorCopy(m_BasicParameters.m_InputToForgetWeights->GetTensorInfo(),
315  inputToForgetWeightsTensor = inputToForgetWeightsTensorCopy;
316  inputParams.m_InputToForgetWeights = &inputToForgetWeightsTensor;
317  }
318  ConstTensor inputToCellWeightsTensor;
320  {
321  ConstTensor inputToCellWeightsTensorCopy(m_BasicParameters.m_InputToCellWeights->GetTensorInfo(),
323  inputToCellWeightsTensor = inputToCellWeightsTensorCopy;
324  inputParams.m_InputToCellWeights = &inputToCellWeightsTensor;
325  }
326  ConstTensor inputToOutputWeightsTensor;
328  {
329  ConstTensor inputToOutputWeightsTensorCopy(m_BasicParameters.m_InputToOutputWeights->GetTensorInfo(),
331  inputToOutputWeightsTensor = inputToOutputWeightsTensorCopy;
332  inputParams.m_InputToOutputWeights = &inputToOutputWeightsTensor;
333  }
334  ConstTensor recurrentToInputWeightsTensor;
336  {
337  ConstTensor recurrentToInputWeightsTensorCopy(
340  recurrentToInputWeightsTensor = recurrentToInputWeightsTensorCopy;
341  inputParams.m_RecurrentToInputWeights = &recurrentToInputWeightsTensor;
342  }
343  ConstTensor recurrentToForgetWeightsTensor;
345  {
346  ConstTensor recurrentToForgetWeightsTensorCopy(
349  recurrentToForgetWeightsTensor = recurrentToForgetWeightsTensorCopy;
350  inputParams.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor;
351  }
352  ConstTensor recurrentToCellWeightsTensor;
354  {
355  ConstTensor recurrentToCellWeightsTensorCopy(
358  recurrentToCellWeightsTensor = recurrentToCellWeightsTensorCopy;
359  inputParams.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor;
360  }
361  ConstTensor recurrentToOutputWeightsTensor;
363  {
364  ConstTensor recurrentToOutputWeightsTensorCopy(
367  recurrentToOutputWeightsTensor = recurrentToOutputWeightsTensorCopy;
368  inputParams.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor;
369  }
370  ConstTensor cellToInputWeightsTensor;
371  if (m_CifgParameters.m_CellToInputWeights != nullptr)
372  {
373  ConstTensor cellToInputWeightsTensorCopy(m_CifgParameters.m_CellToInputWeights->GetTensorInfo(),
375  cellToInputWeightsTensor = cellToInputWeightsTensorCopy;
376  inputParams.m_CellToInputWeights = &cellToInputWeightsTensor;
377  }
378  ConstTensor cellToForgetWeightsTensor;
380  {
381  ConstTensor cellToForgetWeightsTensorCopy(m_PeepholeParameters.m_CellToForgetWeights->GetTensorInfo(),
383  cellToForgetWeightsTensor = cellToForgetWeightsTensorCopy;
384  inputParams.m_CellToForgetWeights = &cellToForgetWeightsTensor;
385  }
386  ConstTensor cellToOutputWeightsTensor;
388  {
389  ConstTensor cellToOutputWeightsTensorCopy(m_PeepholeParameters.m_CellToOutputWeights->GetTensorInfo(),
391  cellToOutputWeightsTensor = cellToOutputWeightsTensorCopy;
392  inputParams.m_CellToOutputWeights = &cellToOutputWeightsTensor;
393  }
394  ConstTensor inputGateBiasTensor;
395  if (m_CifgParameters.m_InputGateBias != nullptr)
396  {
397  ConstTensor inputGateBiasTensorCopy(m_CifgParameters.m_InputGateBias->GetTensorInfo(),
398  m_CifgParameters.m_InputGateBias->Map(true));
399  inputGateBiasTensor = inputGateBiasTensorCopy;
400  inputParams.m_InputGateBias = &inputGateBiasTensor;
401  }
402  ConstTensor forgetGateBiasTensor;
403  if (m_BasicParameters.m_ForgetGateBias != nullptr)
404  {
405  ConstTensor forgetGateBiasTensorCopy(m_BasicParameters.m_ForgetGateBias->GetTensorInfo(),
407  forgetGateBiasTensor = forgetGateBiasTensorCopy;
408  inputParams.m_ForgetGateBias = &forgetGateBiasTensor;
409  }
410  ConstTensor cellBiasTensor;
411  if (m_BasicParameters.m_CellBias != nullptr)
412  {
413  ConstTensor cellBiasTensorCopy(m_BasicParameters.m_CellBias->GetTensorInfo(),
414  m_BasicParameters.m_CellBias->Map(true));
415  cellBiasTensor = cellBiasTensorCopy;
416  inputParams.m_CellBias = &cellBiasTensor;
417  }
418  ConstTensor outputGateBias;
419  if (m_BasicParameters.m_OutputGateBias != nullptr)
420  {
421  ConstTensor outputGateBiasCopy(m_BasicParameters.m_OutputGateBias->GetTensorInfo(),
423  outputGateBias = outputGateBiasCopy;
424  inputParams.m_OutputGateBias = &outputGateBias;
425  }
426  ConstTensor projectionWeightsTensor;
428  {
429  ConstTensor projectionWeightsTensorCopy(m_ProjectionParameters.m_ProjectionWeights->GetTensorInfo(),
431  projectionWeightsTensor = projectionWeightsTensorCopy;
432  inputParams.m_ProjectionWeights = &projectionWeightsTensor;
433  }
434  ConstTensor projectionBiasTensor;
436  {
437  ConstTensor projectionBiasTensorCopy(m_ProjectionParameters.m_ProjectionBias->GetTensorInfo(),
439  projectionBiasTensor = projectionBiasTensorCopy;
440  inputParams.m_ProjectionBias = &projectionBiasTensor;
441  }
442  ConstTensor inputLayerNormTensor;
444  {
445  ConstTensor inputLayerNormTensorCopy(m_LayerNormParameters.m_InputLayerNormWeights->GetTensorInfo(),
447  inputLayerNormTensor = inputLayerNormTensorCopy;
448  inputParams.m_InputLayerNormWeights = &inputLayerNormTensor;
449  }
450  ConstTensor forgetLayerNormTensor;
452  {
453  ConstTensor forgetLayerNormTensorCopy(m_LayerNormParameters.m_ForgetLayerNormWeights->GetTensorInfo(),
455  forgetLayerNormTensor = forgetLayerNormTensorCopy;
456  inputParams.m_ForgetLayerNormWeights = &forgetLayerNormTensor;
457  }
458  ConstTensor cellLayerNormTensor;
460  {
461  ConstTensor cellLayerNormTensorCopy(m_LayerNormParameters.m_CellLayerNormWeights->GetTensorInfo(),
463  cellLayerNormTensor = cellLayerNormTensorCopy;
464  inputParams.m_CellLayerNormWeights = &cellLayerNormTensor;
465  }
466  ConstTensor outputLayerNormTensor;
468  {
469  ConstTensor outputLayerNormTensorCopy(m_LayerNormParameters.m_OutputLayerNormWeights->GetTensorInfo(),
471  outputLayerNormTensor = outputLayerNormTensorCopy;
472  inputParams.m_OutputLayerNormWeights = &outputLayerNormTensor;
473  }
474 
475 
476  visitor.VisitLstmLayer(this, GetParameters(), inputParams, GetName());
477 }
478 
479 } // namespace armnn
std::unique_ptr< ScopedCpuTensorHandle > m_ForgetGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:69
std::unique_ptr< ScopedCpuTensorHandle > m_InputToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:61
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:65
bool m_ProjectionEnabled
Enable/disable the projection layer.
LstmBasicParameters m_BasicParameters
Definition: LstmLayer.hpp:81
const ConstTensor * m_ProjectionWeights
Definition: LstmParams.hpp:55
const ConstTensor * m_CellBias
Definition: LstmParams.hpp:53
LstmDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).
const TensorShape & GetShape() const
Definition: Tensor.hpp:88
std::unique_ptr< ScopedCpuTensorHandle > m_InputToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:29
const ConstCpuTensorHandle * m_RecurrentToForgetWeights
std::unique_ptr< ScopedCpuTensorHandle > m_CellToInputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:33
const ConstCpuTensorHandle * m_CellToOutputWeights
const ConstTensor * m_CellToOutputWeights
Definition: LstmParams.hpp:50
const ConstCpuTensorHandle * m_InputToCellWeights
const ConstCpuTensorHandle * m_InputToOutputWeights
std::unique_ptr< ScopedCpuTensorHandle > m_CellLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:21
virtual void VisitLstmLayer(const IConnectableLayer *layer, const LstmDescriptor &descriptor, const LstmInputParams &params, const char *name=nullptr)=0
Function an Lstm layer should call back to when its Accept(ILayerVisitor&) function is invoked...
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:63
const ConstCpuTensorHandle * m_ProjectionBias
virtual std::unique_ptr< IWorkload > CreateLstm(const LstmQueueDescriptor &descriptor, const WorkloadInfo &info) const
const ConstTensor * m_CellToInputWeights
Definition: LstmParams.hpp:48
const ConstCpuTensorHandle * m_OutputGateBias
const ConstTensor * m_InputGateBias
Definition: LstmParams.hpp:51
const ConstCpuTensorHandle * m_CellToInputWeights
std::unique_ptr< ScopedCpuTensorHandle > m_OutputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:73
const ConstTensor * m_RecurrentToCellWeights
Definition: LstmParams.hpp:46
virtual std::unique_ptr< IWorkload > CreateWorkload(const IWorkloadFactory &factory) const override
Makes a workload for the LSTM type.
Definition: LstmLayer.cpp:22
const ConstCpuTensorHandle * m_CellLayerNormWeights
std::unique_ptr< ScopedCpuTensorHandle > m_InputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:17
const ConstTensor * m_ForgetLayerNormWeights
Definition: LstmParams.hpp:58
const ConstTensor * m_CellToForgetWeights
Definition: LstmParams.hpp:49
Copyright (c) 2020 ARM Limited.
This layer represents a LSTM operation.
Definition: LstmLayer.hpp:77
const ConstCpuTensorHandle * m_CellToForgetWeights
const IOutputSlot * GetConnection() const override
Definition: Layer.hpp:199
const ConstCpuTensorHandle * m_CellBias
const ConstCpuTensorHandle * m_RecurrentToInputWeights
std::unique_ptr< ScopedCpuTensorHandle > m_CellBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:71
const ConstTensor * m_OutputGateBias
Definition: LstmParams.hpp:54
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
Definition: Layer.cpp:338
std::unique_ptr< ScopedCpuTensorHandle > m_CellToForgetWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:49
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Definition: Layer.hpp:310
const ConstTensor * m_InputLayerNormWeights
Definition: LstmParams.hpp:57
std::unique_ptr< ScopedCpuTensorHandle > m_OutputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:23
const ConstCpuTensorHandle * m_InputLayerNormWeights
void ValidateTensorShapesFromInputs() override
Check if the input tensor shape(s) will lead to a valid configuration of LstmLayer.
Definition: LstmLayer.cpp:160
const ConstCpuTensorHandle * m_OutputLayerNormWeights
const ConstTensor * m_RecurrentToOutputWeights
Definition: LstmParams.hpp:47
LstmLayer * Clone(Graph &graph) const override
Creates a dynamically-allocated copy of this layer.
Definition: LstmLayer.cpp:75
An LstmDescriptor for the LstmLayer.
const ConstCpuTensorHandle * m_ForgetGateBias
const ConstTensor * m_ProjectionBias
Definition: LstmParams.hpp:56
const ConstCpuTensorHandle * m_InputToInputWeights
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
Definition: Tensor.hpp:199
bool m_PeepholeEnabled
Enable/disable peephole.
LstmOptLayerNormParameters m_LayerNormParameters
Definition: LstmLayer.hpp:85
#define CHECK_LOCATION()
Definition: Exceptions.hpp:192
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:31
Layer::ConstantTensors GetConstantTensorsByRef() override
Retrieve the handles to the constant values stored by the layer.
Definition: LstmLayer.cpp:266
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToOutputWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:67
LstmOptPeepholeParameters m_PeepholeParameters
Definition: LstmLayer.hpp:84
const ConstTensor * m_CellLayerNormWeights
Definition: LstmParams.hpp:59
const ConstTensor * m_ForgetGateBias
Definition: LstmParams.hpp:52
const ConstTensor * m_InputToCellWeights
Definition: LstmParams.hpp:42
const ConstTensor * m_InputToOutputWeights
Definition: LstmParams.hpp:43
LstmOptProjectionParameters m_ProjectionParameters
Definition: LstmLayer.hpp:83
std::unique_ptr< ScopedCpuTensorHandle > m_ProjectionBias
A unique pointer to represent 1D weights tensor with dimensions [output_size].
Definition: LstmLayer.hpp:43
bool m_CifgEnabled
Enable/disable cifg (coupled input & forget gate).
const ConstCpuTensorHandle * m_RecurrentToOutputWeights
void Accept(ILayerVisitor &visitor) const override
Apply a visitor to this layer.
Definition: LstmLayer.cpp:299
std::unique_ptr< ScopedCpuTensorHandle > m_InputToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:59
const ConstTensor * m_RecurrentToForgetWeights
Definition: LstmParams.hpp:45
const ConstCpuTensorHandle * m_ForgetLayerNormWeights
const ConstTensor * m_RecurrentToInputWeights
Definition: LstmParams.hpp:44
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *LayerCreateWorkload.
const ConstCpuTensorHandle * m_InputGateBias
std::unique_ptr< ScopedCpuTensorHandle > m_CellToOutputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:51
LstmLayer(const LstmDescriptor &param, const char *name)
Constructor to create a LstmLayer.
Definition: LstmLayer.cpp:17
bool m_LayerNormEnabled
Enable/disable layer normalization.
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
Definition: Layer.hpp:312
std::unique_ptr< ScopedCpuTensorHandle > m_ProjectionWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:41
virtual const TensorInfo & GetTensorInfo() const =0
const ConstCpuTensorHandle * m_RecurrentToCellWeights
std::unique_ptr< ScopedCpuTensorHandle > m_ForgetLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:19
LstmOptCifgParameters m_CifgParameters
Definition: LstmLayer.hpp:82
const char * GetName() const override
Returns the name of the layer.
Definition: Layer.hpp:305
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, otherwise infers the output shapes from given input shapes and layer properties.
Definition: LstmLayer.cpp:142
const ConstTensor * m_OutputLayerNormWeights
Definition: LstmParams.hpp:60
std::vector< std::reference_wrapper< std::unique_ptr< ScopedCpuTensorHandle > >> ConstantTensors
Definition: Layer.hpp:363
const TensorInfo & GetTensorInfo() const override
Definition: Layer.cpp:63
std::unique_ptr< ScopedCpuTensorHandle > m_InputToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:57
std::unique_ptr< ScopedCpuTensorHandle > m_InputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:35
const ConstCpuTensorHandle * m_ProjectionWeights
const ConstTensor * m_InputToForgetWeights
Definition: LstmParams.hpp:41
const ConstTensor * m_InputToInputWeights
Definition: LstmParams.hpp:40
const ConstCpuTensorHandle * m_InputToForgetWeights