ArmNN
 21.02
LstmLayer.cpp
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 #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  {
43  }
44 
45  // Projection parameters
47  {
50  }
51 
52  // Peephole parameters
54  {
56  {
58  }
61  }
62 
63  // Layer normalisation parameters
65  {
67  {
69  }
73  }
74 
75  SetAdditionalInfo(descriptor);
76 
77  return factory.CreateLstm(descriptor, PrepInfoAndDesc(descriptor));
78 }
79 
81 {
82  auto layer = CloneBase<LstmLayer>(graph, m_Param, GetName());
83 
85  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_InputToForgetWeights)
86  : nullptr;
87  layer->m_BasicParameters.m_InputToCellWeights = m_BasicParameters.m_InputToCellWeights ?
88  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_InputToCellWeights) : nullptr;
89  layer->m_BasicParameters.m_InputToOutputWeights = m_BasicParameters.m_InputToOutputWeights ?
90  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_InputToOutputWeights) : nullptr;
91  layer->m_BasicParameters.m_RecurrentToForgetWeights = m_BasicParameters.m_RecurrentToForgetWeights ?
92  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_RecurrentToForgetWeights) : nullptr;
93  layer->m_BasicParameters.m_RecurrentToCellWeights = m_BasicParameters.m_RecurrentToCellWeights ?
94  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_RecurrentToCellWeights) : nullptr;
95  layer->m_BasicParameters.m_RecurrentToOutputWeights = m_BasicParameters.m_RecurrentToOutputWeights ?
96  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_RecurrentToOutputWeights) : nullptr;
97  layer->m_BasicParameters.m_ForgetGateBias = m_BasicParameters.m_ForgetGateBias ?
98  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_ForgetGateBias) : nullptr;
99  layer->m_BasicParameters.m_CellBias = m_BasicParameters.m_CellBias ?
100  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_CellBias) : nullptr;
101  layer->m_BasicParameters.m_OutputGateBias = m_BasicParameters.m_OutputGateBias ?
102  std::make_unique<ScopedCpuTensorHandle>(*m_BasicParameters.m_OutputGateBias) : nullptr;
103 
104  if (!m_Param.m_CifgEnabled)
105  {
106  layer->m_CifgParameters.m_InputToInputWeights = m_CifgParameters.m_InputToInputWeights ?
107  std::make_unique<ScopedCpuTensorHandle>(*m_CifgParameters.m_InputToInputWeights) : nullptr;
108  layer->m_CifgParameters.m_RecurrentToInputWeights = m_CifgParameters.m_RecurrentToInputWeights ?
109  std::make_unique<ScopedCpuTensorHandle>(*m_CifgParameters.m_RecurrentToInputWeights) : nullptr;
110  layer->m_CifgParameters.m_InputGateBias = m_CifgParameters.m_InputGateBias ?
111  std::make_unique<ScopedCpuTensorHandle>(*m_CifgParameters.m_InputGateBias) : nullptr;
112  }
113 
114  if (m_Param.m_ProjectionEnabled)
115  {
116  layer->m_ProjectionParameters.m_ProjectionWeights = m_ProjectionParameters.m_ProjectionWeights ?
117  std::make_unique<ScopedCpuTensorHandle>(*m_ProjectionParameters.m_ProjectionWeights) : nullptr;
118  layer->m_ProjectionParameters.m_ProjectionBias = m_ProjectionParameters.m_ProjectionBias ?
119  std::make_unique<ScopedCpuTensorHandle>(*m_ProjectionParameters.m_ProjectionBias) : nullptr;
120  }
121 
122  if (m_Param.m_PeepholeEnabled)
123  {
124  if (!m_Param.m_CifgEnabled)
125  {
126  layer->m_PeepholeParameters.m_CellToInputWeights = m_PeepholeParameters.m_CellToInputWeights ?
127  std::make_unique<ScopedCpuTensorHandle>(*m_PeepholeParameters.m_CellToInputWeights) : nullptr;
128  }
129  layer->m_PeepholeParameters.m_CellToForgetWeights = m_PeepholeParameters.m_CellToForgetWeights ?
130  std::make_unique<ScopedCpuTensorHandle>(*m_PeepholeParameters.m_CellToForgetWeights) : nullptr;
131  layer->m_PeepholeParameters.m_CellToOutputWeights = m_PeepholeParameters.m_CellToOutputWeights ?
132  std::make_unique<ScopedCpuTensorHandle>(*m_PeepholeParameters.m_CellToOutputWeights) : nullptr;
133  }
134 
135  if (m_Param.m_LayerNormEnabled)
136  {
137  layer->m_LayerNormParameters.m_InputLayerNormWeights = m_LayerNormParameters.m_InputLayerNormWeights ?
138  std::make_unique<ScopedCpuTensorHandle>(*m_LayerNormParameters.m_InputLayerNormWeights) : nullptr;
139  layer->m_LayerNormParameters.m_ForgetLayerNormWeights = m_LayerNormParameters.m_ForgetLayerNormWeights ?
140  std::make_unique<ScopedCpuTensorHandle>(*m_LayerNormParameters.m_ForgetLayerNormWeights) : nullptr;
141  layer->m_LayerNormParameters.m_CellLayerNormWeights = m_LayerNormParameters.m_CellLayerNormWeights ?
142  std::make_unique<ScopedCpuTensorHandle>(*m_LayerNormParameters.m_CellLayerNormWeights) : nullptr;
143  layer->m_LayerNormParameters.m_OutputLayerNormWeights = m_LayerNormParameters.m_OutputLayerNormWeights ?
144  std::make_unique<ScopedCpuTensorHandle>(*m_LayerNormParameters.m_OutputLayerNormWeights) : nullptr;
145  }
146 
147  return std::move(layer);
148 }
149 
150 std::vector<TensorShape> LstmLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const
151 {
152  ARMNN_ASSERT(inputShapes.size() == 3);
153 
154  // Get input values for validation
155  unsigned int batchSize = inputShapes[0][0];
156  unsigned int outputSize = inputShapes[1][1];
157  unsigned int numUnits = inputShapes[2][1];
158 
159  std::vector<TensorShape> outShapes;
160  outShapes.push_back(TensorShape({batchSize, numUnits * (m_Param.m_CifgEnabled ? 3 : 4)}));
161  outShapes.push_back(TensorShape({batchSize, outputSize}));
162  outShapes.push_back(TensorShape({batchSize, numUnits}));
163  outShapes.push_back(TensorShape({batchSize, outputSize}));
164 
165  return outShapes;
166 }
167 
169 {
171 
172  const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape();
173 
175 
176  auto inferredShapes = InferOutputShapes( {
180  });
181 
182  ARMNN_ASSERT(inferredShapes.size() == 4);
183 
184  // Check if the weights are nullptr
186  "LstmLayer: m_BasicParameters.m_InputToForgetWeights should not be null.");
188  "LstmLayer: m_BasicParameters.m_InputToCellWeights should not be null.");
190  "LstmLayer: m_BasicParameters.m_InputToOutputWeights should not be null.");
192  "LstmLayer: m_BasicParameters.m_RecurrentToForgetWeights should not be null.");
194  "LstmLayer: m_BasicParameters.m_RecurrentToCellWeights should not be null.");
196  "LstmLayer: m_BasicParameters.m_RecurrentToOutputWeights should not be null.");
198  "LstmLayer: m_BasicParameters.m_ForgetGateBias should not be null.");
200  "LstmLayer: m_BasicParameters.m_CellBias should not be null.");
202  "LstmLayer: m_BasicParameters.m_OutputGateBias should not be null.");
203 
204  if (!m_Param.m_CifgEnabled)
205  {
207  "LstmLayer: m_CifgParameters.m_InputToInputWeights should not be null.");
209  "LstmLayer: m_CifgParameters.m_RecurrentToInputWeights should not be null.");
211  "LstmLayer: m_CifgParameters.m_InputGateBias should not be null.");
212 
213  ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "LstmLayer");
214  }
215  else
216  {
218  "LstmLayer: m_CifgParameters.m_InputToInputWeights should not have a value when CIFG is enabled.");
220  "LstmLayer: m_CifgParameters.m_RecurrentToInputWeights should not have a value when CIFG is enabled.");
222  "LstmLayer: m_CifgParameters.m_InputGateBias should not have a value when CIFG is enabled.");
223 
224  ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "LstmLayer");
225  }
226 
228  {
230  "LstmLayer: m_ProjectionParameters.m_ProjectionWeights should not be null.");
231  }
232 
234  {
235  if (!m_Param.m_CifgEnabled)
236  {
238  "LstmLayer: m_PeepholeParameters.m_CellToInputWeights should not be null "
239  "when Peephole is enabled and CIFG is disabled.");
240  }
242  "LstmLayer: m_PeepholeParameters.m_CellToForgetWeights should not be null.");
244  "LstmLayer: m_PeepholeParameters.m_CellToOutputWeights should not be null.");
245  }
246 
248  GetOutputSlot(1).GetTensorInfo().GetShape(), inferredShapes[1], m_ShapeInferenceMethod, "LstmLayer", 1);
250  GetOutputSlot(2).GetTensorInfo().GetShape(), inferredShapes[2], m_ShapeInferenceMethod, "LstmLayer", 2);
252  GetOutputSlot(3).GetTensorInfo().GetShape(), inferredShapes[3], m_ShapeInferenceMethod, "LstmLayer", 3);
253 
255  {
257  {
259  "LstmLayer: m_LayerNormParameters.m_inputLayerNormWeights should not be null.");
260  }
262  "LstmLayer: m_LayerNormParameters.m_forgetLayerNormWeights should not be null.");
264  "LstmLayer: m_LayerNormParameters.m_cellLayerNormWeights should not be null.");
266  "LstmLayer: m_LayerNormParameters.m_outputLayerNormWeights should not be null.");
267  }
268 }
269 
271 {
281 
282  // Cifg parameters
286 
287  // Projection parameters
290 
291  // Peephole parameters
295 
296  // Layer normalisation parameters
301 }
302 
303 void LstmLayer::Accept(ILayerVisitor& visitor) const
304 {
305  LstmInputParams inputParams;
306  ConstTensor inputToInputWeightsTensor;
308  {
309  ConstTensor inputToInputWeightsTensorCopy(m_CifgParameters.m_InputToInputWeights->GetTensorInfo(),
311  inputToInputWeightsTensor = inputToInputWeightsTensorCopy;
312  inputParams.m_InputToInputWeights = &inputToInputWeightsTensor;
313  }
314  ConstTensor inputToForgetWeightsTensor;
316  {
317  ConstTensor inputToForgetWeightsTensorCopy(m_BasicParameters.m_InputToForgetWeights->GetTensorInfo(),
319  inputToForgetWeightsTensor = inputToForgetWeightsTensorCopy;
320  inputParams.m_InputToForgetWeights = &inputToForgetWeightsTensor;
321  }
322  ConstTensor inputToCellWeightsTensor;
324  {
325  ConstTensor inputToCellWeightsTensorCopy(m_BasicParameters.m_InputToCellWeights->GetTensorInfo(),
327  inputToCellWeightsTensor = inputToCellWeightsTensorCopy;
328  inputParams.m_InputToCellWeights = &inputToCellWeightsTensor;
329  }
330  ConstTensor inputToOutputWeightsTensor;
332  {
333  ConstTensor inputToOutputWeightsTensorCopy(m_BasicParameters.m_InputToOutputWeights->GetTensorInfo(),
335  inputToOutputWeightsTensor = inputToOutputWeightsTensorCopy;
336  inputParams.m_InputToOutputWeights = &inputToOutputWeightsTensor;
337  }
338  ConstTensor recurrentToInputWeightsTensor;
340  {
341  ConstTensor recurrentToInputWeightsTensorCopy(
344  recurrentToInputWeightsTensor = recurrentToInputWeightsTensorCopy;
345  inputParams.m_RecurrentToInputWeights = &recurrentToInputWeightsTensor;
346  }
347  ConstTensor recurrentToForgetWeightsTensor;
349  {
350  ConstTensor recurrentToForgetWeightsTensorCopy(
353  recurrentToForgetWeightsTensor = recurrentToForgetWeightsTensorCopy;
354  inputParams.m_RecurrentToForgetWeights = &recurrentToForgetWeightsTensor;
355  }
356  ConstTensor recurrentToCellWeightsTensor;
358  {
359  ConstTensor recurrentToCellWeightsTensorCopy(
362  recurrentToCellWeightsTensor = recurrentToCellWeightsTensorCopy;
363  inputParams.m_RecurrentToCellWeights = &recurrentToCellWeightsTensor;
364  }
365  ConstTensor recurrentToOutputWeightsTensor;
367  {
368  ConstTensor recurrentToOutputWeightsTensorCopy(
371  recurrentToOutputWeightsTensor = recurrentToOutputWeightsTensorCopy;
372  inputParams.m_RecurrentToOutputWeights = &recurrentToOutputWeightsTensor;
373  }
374  ConstTensor cellToInputWeightsTensor;
376  {
377  ConstTensor cellToInputWeightsTensorCopy(m_PeepholeParameters.m_CellToInputWeights->GetTensorInfo(),
379  cellToInputWeightsTensor = cellToInputWeightsTensorCopy;
380  inputParams.m_CellToInputWeights = &cellToInputWeightsTensor;
381  }
382  ConstTensor cellToForgetWeightsTensor;
384  {
385  ConstTensor cellToForgetWeightsTensorCopy(m_PeepholeParameters.m_CellToForgetWeights->GetTensorInfo(),
387  cellToForgetWeightsTensor = cellToForgetWeightsTensorCopy;
388  inputParams.m_CellToForgetWeights = &cellToForgetWeightsTensor;
389  }
390  ConstTensor cellToOutputWeightsTensor;
392  {
393  ConstTensor cellToOutputWeightsTensorCopy(m_PeepholeParameters.m_CellToOutputWeights->GetTensorInfo(),
395  cellToOutputWeightsTensor = cellToOutputWeightsTensorCopy;
396  inputParams.m_CellToOutputWeights = &cellToOutputWeightsTensor;
397  }
398  ConstTensor inputGateBiasTensor;
399  if (m_CifgParameters.m_InputGateBias != nullptr)
400  {
401  ConstTensor inputGateBiasTensorCopy(m_CifgParameters.m_InputGateBias->GetTensorInfo(),
402  m_CifgParameters.m_InputGateBias->Map(true));
403  inputGateBiasTensor = inputGateBiasTensorCopy;
404  inputParams.m_InputGateBias = &inputGateBiasTensor;
405  }
406  ConstTensor forgetGateBiasTensor;
407  if (m_BasicParameters.m_ForgetGateBias != nullptr)
408  {
409  ConstTensor forgetGateBiasTensorCopy(m_BasicParameters.m_ForgetGateBias->GetTensorInfo(),
411  forgetGateBiasTensor = forgetGateBiasTensorCopy;
412  inputParams.m_ForgetGateBias = &forgetGateBiasTensor;
413  }
414  ConstTensor cellBiasTensor;
415  if (m_BasicParameters.m_CellBias != nullptr)
416  {
417  ConstTensor cellBiasTensorCopy(m_BasicParameters.m_CellBias->GetTensorInfo(),
418  m_BasicParameters.m_CellBias->Map(true));
419  cellBiasTensor = cellBiasTensorCopy;
420  inputParams.m_CellBias = &cellBiasTensor;
421  }
422  ConstTensor outputGateBias;
423  if (m_BasicParameters.m_OutputGateBias != nullptr)
424  {
425  ConstTensor outputGateBiasCopy(m_BasicParameters.m_OutputGateBias->GetTensorInfo(),
427  outputGateBias = outputGateBiasCopy;
428  inputParams.m_OutputGateBias = &outputGateBias;
429  }
430  ConstTensor projectionWeightsTensor;
432  {
433  ConstTensor projectionWeightsTensorCopy(m_ProjectionParameters.m_ProjectionWeights->GetTensorInfo(),
435  projectionWeightsTensor = projectionWeightsTensorCopy;
436  inputParams.m_ProjectionWeights = &projectionWeightsTensor;
437  }
438  ConstTensor projectionBiasTensor;
440  {
441  ConstTensor projectionBiasTensorCopy(m_ProjectionParameters.m_ProjectionBias->GetTensorInfo(),
443  projectionBiasTensor = projectionBiasTensorCopy;
444  inputParams.m_ProjectionBias = &projectionBiasTensor;
445  }
446  ConstTensor inputLayerNormTensor;
448  {
449  ConstTensor inputLayerNormTensorCopy(m_LayerNormParameters.m_InputLayerNormWeights->GetTensorInfo(),
451  inputLayerNormTensor = inputLayerNormTensorCopy;
452  inputParams.m_InputLayerNormWeights = &inputLayerNormTensor;
453  }
454  ConstTensor forgetLayerNormTensor;
456  {
457  ConstTensor forgetLayerNormTensorCopy(m_LayerNormParameters.m_ForgetLayerNormWeights->GetTensorInfo(),
459  forgetLayerNormTensor = forgetLayerNormTensorCopy;
460  inputParams.m_ForgetLayerNormWeights = &forgetLayerNormTensor;
461  }
462  ConstTensor cellLayerNormTensor;
464  {
465  ConstTensor cellLayerNormTensorCopy(m_LayerNormParameters.m_CellLayerNormWeights->GetTensorInfo(),
467  cellLayerNormTensor = cellLayerNormTensorCopy;
468  inputParams.m_CellLayerNormWeights = &cellLayerNormTensor;
469  }
470  ConstTensor outputLayerNormTensor;
472  {
473  ConstTensor outputLayerNormTensorCopy(m_LayerNormParameters.m_OutputLayerNormWeights->GetTensorInfo(),
475  outputLayerNormTensor = outputLayerNormTensorCopy;
476  inputParams.m_OutputLayerNormWeights = &outputLayerNormTensor;
477  }
478 
479 
480  visitor.VisitLstmLayer(this, GetParameters(), inputParams, GetName());
481 }
482 
484 {
485  std::vector<ConstTensor> constTensors;
486 
487  LstmDescriptor descriptor = GetParameters();
488 
489  // First add mandatory/basic parameters
491  {
492  constTensors.emplace_back(ConstTensor(m_BasicParameters.m_InputToForgetWeights->GetTensorInfo(),
494  }
496  {
497  constTensors.emplace_back(ConstTensor(m_BasicParameters.m_InputToCellWeights->GetTensorInfo(),
499  }
501  {
502  constTensors.emplace_back(ConstTensor(m_BasicParameters.m_InputToOutputWeights->GetTensorInfo(),
504  }
506  {
507  constTensors.emplace_back(ConstTensor(
510  }
512  {
513  constTensors.emplace_back(ConstTensor(
516  }
518  {
519  constTensors.emplace_back(ConstTensor(
522  }
523  if (m_BasicParameters.m_ForgetGateBias != nullptr)
524  {
525  constTensors.emplace_back(ConstTensor(m_BasicParameters.m_ForgetGateBias->GetTensorInfo(),
526  m_BasicParameters.m_ForgetGateBias->Map(true)));
527  }
528  if (m_BasicParameters.m_CellBias != nullptr)
529  {
530  constTensors.emplace_back(ConstTensor(m_BasicParameters.m_CellBias->GetTensorInfo(),
531  m_BasicParameters.m_CellBias->Map(true)));
532  }
533  if (m_BasicParameters.m_OutputGateBias != nullptr)
534  {
535  constTensors.emplace_back(ConstTensor(m_BasicParameters.m_OutputGateBias->GetTensorInfo(),
536  m_BasicParameters.m_OutputGateBias->Map(true)));
537  }
538 
539  // Add cifg parameters
540  if (!descriptor.m_CifgEnabled)
541  {
543  {
544  constTensors.emplace_back(ConstTensor(m_CifgParameters.m_InputToInputWeights->GetTensorInfo(),
546  }
548  {
549  constTensors.emplace_back(ConstTensor(
552  }
553  if (m_CifgParameters.m_InputGateBias != nullptr)
554  {
555  constTensors.emplace_back(ConstTensor(m_CifgParameters.m_InputGateBias->GetTensorInfo(),
556  m_CifgParameters.m_InputGateBias->Map(true)));
557  }
558  }
559 
560  // Add peephole parameters
561  if (descriptor.m_PeepholeEnabled)
562  {
563  if (!descriptor.m_CifgEnabled)
564  {
566  {
567  constTensors.emplace_back(ConstTensor(m_PeepholeParameters.m_CellToInputWeights->GetTensorInfo(),
569  }
570  }
572  {
573  constTensors.emplace_back(ConstTensor(m_PeepholeParameters.m_CellToForgetWeights->GetTensorInfo(),
575  }
577  {
578  constTensors.emplace_back(ConstTensor(m_PeepholeParameters.m_CellToOutputWeights->GetTensorInfo(),
580  }
581  }
582 
583  // Add projection parameters
584  if (descriptor.m_ProjectionEnabled)
585  {
587  {
588  constTensors.emplace_back(ConstTensor(m_ProjectionParameters.m_ProjectionWeights->GetTensorInfo(),
590  }
592  {
593  constTensors.emplace_back(ConstTensor(m_ProjectionParameters.m_ProjectionBias->GetTensorInfo(),
595  }
596  }
597 
598  // Add norm parameters
599  if (descriptor.m_LayerNormEnabled)
600  {
601  if (!descriptor.m_CifgEnabled)
602  {
604  {
605  constTensors.emplace_back(ConstTensor(m_LayerNormParameters.m_InputLayerNormWeights->GetTensorInfo(),
607  }
608  }
610  {
611  constTensors.emplace_back(ConstTensor(m_LayerNormParameters.m_ForgetLayerNormWeights->GetTensorInfo(),
613  }
615  {
616  constTensors.emplace_back(ConstTensor(m_LayerNormParameters.m_CellLayerNormWeights->GetTensorInfo(),
618  }
620  {
621  constTensors.emplace_back(ConstTensor(m_LayerNormParameters.m_OutputLayerNormWeights->GetTensorInfo(),
623  }
624  }
625 
626  strategy.ExecuteStrategy(this, GetParameters(), constTensors, GetName());
627 }
628 
629 } // 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:187
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
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
virtual void ExecuteStrategy(const armnn::IConnectableLayer *layer, const armnn::BaseDescriptor &descriptor, const std::vector< armnn::ConstTensor > &constants, const char *name, const armnn::LayerBindingId id=0)=0
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
void VerifyShapeInferenceType(const TensorShape &outputShape, ShapeInferenceMethod shapeInferenceMethod)
Definition: Layer.cpp:432
const ConstTensor * m_CellToForgetWeights
Definition: LstmParams.hpp:49
Copyright (c) 2021 ARM Limited and Contributors.
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
void ExecuteStrategy(IStrategy &strategy) const override
Apply a visitor to this layer.
Definition: LstmLayer.cpp:483
std::unique_ptr< ScopedCpuTensorHandle > m_CellBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:71
void ValidateAndCopyShape(const TensorShape &outputShape, const TensorShape &inferredShape, const ShapeInferenceMethod shapeInferenceMethod, const std::string &layerName, const unsigned int outputSlotIndex=0)
Definition: Layer.cpp:392
const ConstTensor * m_OutputGateBias
Definition: LstmParams.hpp:54
void VerifyLayerConnections(unsigned int expectedConnections, const CheckLocation &location) const
Definition: Layer.cpp:348
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:316
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:168
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:80
An LstmDescriptor for the LstmLayer.
#define ARMNN_ASSERT_MSG(COND, MSG)
Definition: Assert.hpp:15
const ConstCpuTensorHandle * m_ForgetGateBias
const ConstTensor * m_ProjectionBias
Definition: LstmParams.hpp:56
std::unique_ptr< ScopedCpuTensorHandle > m_CellToInputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:47
const ConstCpuTensorHandle * m_InputToInputWeights
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
Definition: Tensor.hpp:314
bool m_PeepholeEnabled
Enable/disable peephole.
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
LstmOptLayerNormParameters m_LayerNormParameters
Definition: LstmLayer.hpp:85
#define CHECK_LOCATION()
Definition: Exceptions.hpp:197
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:270
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
void SetAdditionalInfo(QueueDescriptor &descriptor) const
Definition: Layer.cpp:245
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:41
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:303
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:318
std::unique_ptr< ScopedCpuTensorHandle > m_ProjectionWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:39
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:311
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:150
const ConstTensor * m_OutputLayerNormWeights
Definition: LstmParams.hpp:60
std::vector< std::reference_wrapper< std::unique_ptr< ScopedCpuTensorHandle > >> ConstantTensors
Definition: Layer.hpp:393
const TensorInfo & GetTensorInfo(const ITensorHandle *tensorHandle)
float32 helpers
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:33
ShapeInferenceMethod m_ShapeInferenceMethod
Definition: Layer.hpp:408
const ConstCpuTensorHandle * m_ProjectionWeights
const ConstTensor * m_InputToForgetWeights
Definition: LstmParams.hpp:41
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below...
Definition: Types.hpp:419
const ConstTensor * m_InputToInputWeights
Definition: LstmParams.hpp:40
const ConstCpuTensorHandle * m_InputToForgetWeights