ArmNN
 20.02
LstmLayer Class Reference

This layer represents a LSTM operation. More...

#include <LstmLayer.hpp>

Inheritance diagram for LstmLayer:
LayerWithParameters< LstmDescriptor > Layer IConnectableLayer

Public Member Functions

virtual std::unique_ptr< IWorkloadCreateWorkload (const IWorkloadFactory &factory) const override
 Makes a workload for the LSTM type. More...
 
LstmLayerClone (Graph &graph) const override
 Creates a dynamically-allocated copy of this layer. More...
 
void ValidateTensorShapesFromInputs () override
 Check if the input tensor shape(s) will lead to a valid configuration of LstmLayer. More...
 
std::vector< TensorShapeInferOutputShapes (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. More...
 
void Accept (ILayerVisitor &visitor) const override
 Apply a visitor to this layer. More...
 
- Public Member Functions inherited from LayerWithParameters< LstmDescriptor >
const LstmDescriptorGetParameters () const
 
void SerializeLayerParameters (ParameterStringifyFunction &fn) const override
 Helper to serialize the layer parameters to string (currently used in DotSerializer and company). More...
 
- Public Member Functions inherited from Layer
 Layer (unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const char *name)
 
 Layer (unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, DataLayout layout, const char *name)
 
const std::string & GetNameStr () const
 
const OutputHandlerGetOutputHandler (unsigned int i=0) const
 
OutputHandlerGetOutputHandler (unsigned int i=0)
 
const std::vector< InputSlot > & GetInputSlots () const
 
const std::vector< OutputSlot > & GetOutputSlots () const
 
std::vector< InputSlot >::iterator BeginInputSlots ()
 
std::vector< InputSlot >::iterator EndInputSlots ()
 
std::vector< OutputSlot >::iterator BeginOutputSlots ()
 
std::vector< OutputSlot >::iterator EndOutputSlots ()
 
bool IsOutputUnconnected ()
 
void ResetPriority () const
 
LayerPriority GetPriority () const
 
LayerType GetType () const
 
DataType GetDataType () const
 
const BackendIdGetBackendId () const
 
void SetBackendId (const BackendId &id)
 
virtual void CreateTensorHandles (const TensorHandleFactoryRegistry &registry, const IWorkloadFactory &factory, const bool IsMemoryManaged=true)
 
void VerifyLayerConnections (unsigned int expectedConnections, const CheckLocation &location) const
 
virtual void ReleaseConstantData ()
 
template<typename Op >
void OperateOnConstantTensors (Op op)
 
const char * GetName () const override
 Returns the name of the layer. More...
 
unsigned int GetNumInputSlots () const override
 Returns the number of connectable input slots. More...
 
unsigned int GetNumOutputSlots () const override
 Returns the number of connectable output slots. More...
 
const InputSlotGetInputSlot (unsigned int index) const override
 Get a const input slot handle by slot index. More...
 
InputSlotGetInputSlot (unsigned int index) override
 Get the input slot handle by slot index. More...
 
const OutputSlotGetOutputSlot (unsigned int index=0) const override
 Get the const output slot handle by slot index. More...
 
OutputSlotGetOutputSlot (unsigned int index=0) override
 Get the output slot handle by slot index. More...
 
void SetGuid (LayerGuid guid)
 
LayerGuid GetGuid () const final
 Returns the unique id of the layer. More...
 
void AddRelatedLayerName (const std::string layerName)
 
const std::list< std::string > & GetRelatedLayerNames ()
 
virtual void Reparent (Graph &dest, std::list< Layer *>::const_iterator iterator)=0
 
void BackendSelectionHint (Optional< BackendId > backend) final
 Provide a hint for the optimizer as to which backend to prefer for this layer. More...
 
Optional< BackendIdGetBackendHint () const
 

Public Attributes

LstmBasicParameters m_BasicParameters
 
LstmOptCifgParameters m_CifgParameters
 
LstmOptProjectionParameters m_ProjectionParameters
 
LstmOptPeepholeParameters m_PeepholeParameters
 
LstmOptLayerNormParameters m_LayerNormParameters
 

Protected Member Functions

 LstmLayer (const LstmDescriptor &param, const char *name)
 Constructor to create a LstmLayer. More...
 
 ~LstmLayer ()=default
 Default destructor. More...
 
Layer::ConstantTensors GetConstantTensorsByRef () override
 Retrieve the handles to the constant values stored by the layer. More...
 
- Protected Member Functions inherited from LayerWithParameters< LstmDescriptor >
 LayerWithParameters (unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const LstmDescriptor &param, const char *name)
 
 ~LayerWithParameters ()=default
 
WorkloadInfo PrepInfoAndDesc (QueueDescriptor &descriptor) const
 Helper function to reduce duplication in *LayerCreateWorkload. More...
 
- Protected Member Functions inherited from Layer
virtual ~Layer ()=default
 
template<typename QueueDescriptor >
void CollectQueueDescriptorInputs (QueueDescriptor &descriptor, WorkloadInfo &info) const
 
template<typename QueueDescriptor >
void CollectQueueDescriptorOutputs (QueueDescriptor &descriptor, WorkloadInfo &info) const
 
template<typename QueueDescriptor >
WorkloadInfo PrepInfoAndDesc (QueueDescriptor &descriptor) const
 Helper function to reduce duplication in *LayerCreateWorkload. More...
 
template<typename LayerType , typename ... Params>
LayerTypeCloneBase (Graph &graph, Params &&... params) const
 
- Protected Member Functions inherited from IConnectableLayer
 ~IConnectableLayer ()
 Objects are not deletable via the handle. More...
 

Additional Inherited Members

- Public Types inherited from LayerWithParameters< LstmDescriptor >
using DescriptorType = LstmDescriptor
 
- Protected Types inherited from Layer
using ConstantTensors = std::vector< std::reference_wrapper< std::unique_ptr< ScopedCpuTensorHandle > >>
 
- Protected Attributes inherited from LayerWithParameters< LstmDescriptor >
LstmDescriptor m_Param
 The parameters for the layer (not including tensor-valued weights etc.). More...
 
- Protected Attributes inherited from Layer
std::vector< OutputHandlerm_OutputHandlers
 

Detailed Description

This layer represents a LSTM operation.

Definition at line 77 of file LstmLayer.hpp.

Constructor & Destructor Documentation

◆ LstmLayer()

LstmLayer ( const LstmDescriptor param,
const char *  name 
)
protected

Constructor to create a LstmLayer.

Parameters
[in]paramLstmDescriptor to configure the lstm operation.
[in]nameOptional name for the layer.

Definition at line 17 of file LstmLayer.cpp.

References armnn::Lstm.

18  : LayerWithParameters(3, 4, LayerType::Lstm, param, name)
19 {
20 }
LayerWithParameters(unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const LstmDescriptor &param, const char *name)

◆ ~LstmLayer()

~LstmLayer ( )
protecteddefault

Default destructor.

Member Function Documentation

◆ Accept()

void Accept ( ILayerVisitor visitor) const
overridevirtual

Apply a visitor to this layer.

Implements IConnectableLayer.

Definition at line 299 of file LstmLayer.cpp.

References Layer::GetName(), LayerWithParameters< LstmDescriptor >::GetParameters(), LstmLayer::m_BasicParameters, LstmInputParams::m_CellBias, LstmBasicParameters::m_CellBias, LstmOptLayerNormParameters::m_CellLayerNormWeights, LstmInputParams::m_CellLayerNormWeights, LstmOptPeepholeParameters::m_CellToForgetWeights, LstmInputParams::m_CellToForgetWeights, LstmOptCifgParameters::m_CellToInputWeights, LstmInputParams::m_CellToInputWeights, LstmInputParams::m_CellToOutputWeights, LstmOptPeepholeParameters::m_CellToOutputWeights, LstmLayer::m_CifgParameters, LstmInputParams::m_ForgetGateBias, LstmBasicParameters::m_ForgetGateBias, LstmOptLayerNormParameters::m_ForgetLayerNormWeights, LstmInputParams::m_ForgetLayerNormWeights, LstmOptCifgParameters::m_InputGateBias, LstmInputParams::m_InputGateBias, LstmOptLayerNormParameters::m_InputLayerNormWeights, LstmInputParams::m_InputLayerNormWeights, LstmInputParams::m_InputToCellWeights, LstmBasicParameters::m_InputToCellWeights, LstmInputParams::m_InputToForgetWeights, LstmBasicParameters::m_InputToForgetWeights, LstmOptCifgParameters::m_InputToInputWeights, LstmInputParams::m_InputToInputWeights, LstmInputParams::m_InputToOutputWeights, LstmBasicParameters::m_InputToOutputWeights, LstmLayer::m_LayerNormParameters, LstmInputParams::m_OutputGateBias, LstmBasicParameters::m_OutputGateBias, LstmOptLayerNormParameters::m_OutputLayerNormWeights, LstmInputParams::m_OutputLayerNormWeights, LstmLayer::m_PeepholeParameters, LstmOptProjectionParameters::m_ProjectionBias, LstmInputParams::m_ProjectionBias, LstmLayer::m_ProjectionParameters, LstmOptProjectionParameters::m_ProjectionWeights, LstmInputParams::m_ProjectionWeights, LstmInputParams::m_RecurrentToCellWeights, LstmBasicParameters::m_RecurrentToCellWeights, LstmInputParams::m_RecurrentToForgetWeights, LstmBasicParameters::m_RecurrentToForgetWeights, LstmOptCifgParameters::m_RecurrentToInputWeights, LstmInputParams::m_RecurrentToInputWeights, LstmInputParams::m_RecurrentToOutputWeights, LstmBasicParameters::m_RecurrentToOutputWeights, and ILayerVisitor::VisitLstmLayer().

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 }
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
LstmBasicParameters m_BasicParameters
Definition: LstmLayer.hpp:81
std::unique_ptr< ScopedCpuTensorHandle > m_InputToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:29
std::unique_ptr< ScopedCpuTensorHandle > m_CellToInputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:33
std::unique_ptr< ScopedCpuTensorHandle > m_CellLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:21
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:63
std::unique_ptr< ScopedCpuTensorHandle > m_OutputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:73
std::unique_ptr< ScopedCpuTensorHandle > m_InputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:17
std::unique_ptr< ScopedCpuTensorHandle > m_CellBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:71
std::unique_ptr< ScopedCpuTensorHandle > m_CellToForgetWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:49
std::unique_ptr< ScopedCpuTensorHandle > m_OutputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:23
LstmOptLayerNormParameters m_LayerNormParameters
Definition: LstmLayer.hpp:85
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:31
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
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
std::unique_ptr< ScopedCpuTensorHandle > m_InputToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:59
std::unique_ptr< ScopedCpuTensorHandle > m_CellToOutputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:51
std::unique_ptr< ScopedCpuTensorHandle > m_ProjectionWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:41
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::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

◆ Clone()

LstmLayer * Clone ( Graph graph) const
overridevirtual

Creates a dynamically-allocated copy of this layer.

Parameters
[in]graphThe graph into which this layer is being cloned.

Implements Layer.

Definition at line 75 of file LstmLayer.cpp.

References Layer::GetName(), LstmLayer::m_BasicParameters, LstmBasicParameters::m_CellBias, LstmOptLayerNormParameters::m_CellLayerNormWeights, LstmOptPeepholeParameters::m_CellToForgetWeights, LstmOptCifgParameters::m_CellToInputWeights, LstmOptPeepholeParameters::m_CellToOutputWeights, LstmLayer::m_CifgParameters, LstmBasicParameters::m_ForgetGateBias, LstmOptLayerNormParameters::m_ForgetLayerNormWeights, LstmOptCifgParameters::m_InputGateBias, LstmOptLayerNormParameters::m_InputLayerNormWeights, LstmBasicParameters::m_InputToCellWeights, LstmBasicParameters::m_InputToForgetWeights, LstmOptCifgParameters::m_InputToInputWeights, LstmBasicParameters::m_InputToOutputWeights, LstmLayer::m_LayerNormParameters, LstmBasicParameters::m_OutputGateBias, LstmOptLayerNormParameters::m_OutputLayerNormWeights, LayerWithParameters< LstmDescriptor >::m_Param, LstmLayer::m_PeepholeParameters, LstmOptProjectionParameters::m_ProjectionBias, LstmLayer::m_ProjectionParameters, LstmOptProjectionParameters::m_ProjectionWeights, LstmBasicParameters::m_RecurrentToCellWeights, LstmBasicParameters::m_RecurrentToForgetWeights, LstmOptCifgParameters::m_RecurrentToInputWeights, and LstmBasicParameters::m_RecurrentToOutputWeights.

76 {
77  auto layer = CloneBase<LstmLayer>(graph, m_Param, GetName());
78 
79  layer->m_BasicParameters.m_InputToForgetWeights = m_BasicParameters.m_InputToForgetWeights ?
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 }
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
LstmBasicParameters m_BasicParameters
Definition: LstmLayer.hpp:81
LstmDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).
std::unique_ptr< ScopedCpuTensorHandle > m_InputToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:29
std::unique_ptr< ScopedCpuTensorHandle > m_CellToInputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:33
std::unique_ptr< ScopedCpuTensorHandle > m_CellLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:21
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:63
std::unique_ptr< ScopedCpuTensorHandle > m_OutputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:73
std::unique_ptr< ScopedCpuTensorHandle > m_InputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:17
std::unique_ptr< ScopedCpuTensorHandle > m_CellBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:71
std::unique_ptr< ScopedCpuTensorHandle > m_CellToForgetWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:49
std::unique_ptr< ScopedCpuTensorHandle > m_OutputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:23
LstmOptLayerNormParameters m_LayerNormParameters
Definition: LstmLayer.hpp:85
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:31
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
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
std::unique_ptr< ScopedCpuTensorHandle > m_InputToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:59
std::unique_ptr< ScopedCpuTensorHandle > m_CellToOutputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:51
std::unique_ptr< ScopedCpuTensorHandle > m_ProjectionWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:41
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::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

◆ CreateWorkload()

std::unique_ptr< IWorkload > CreateWorkload ( const IWorkloadFactory factory) const
overridevirtual

Makes a workload for the LSTM type.

Parameters
[in]graphThe graph where this layer can be found.
[in]factoryThe workload factory which will create the workload.
Returns
A pointer to the created workload, or nullptr if not created.

Implements Layer.

Definition at line 22 of file LstmLayer.cpp.

References IWorkloadFactory::CreateLstm(), LstmLayer::m_BasicParameters, LstmBasicParameters::m_CellBias, LstmQueueDescriptor::m_CellBias, LstmOptLayerNormParameters::m_CellLayerNormWeights, LstmQueueDescriptor::m_CellLayerNormWeights, LstmOptPeepholeParameters::m_CellToForgetWeights, LstmQueueDescriptor::m_CellToForgetWeights, LstmOptCifgParameters::m_CellToInputWeights, LstmQueueDescriptor::m_CellToInputWeights, LstmOptPeepholeParameters::m_CellToOutputWeights, LstmQueueDescriptor::m_CellToOutputWeights, LstmDescriptor::m_CifgEnabled, LstmLayer::m_CifgParameters, LstmBasicParameters::m_ForgetGateBias, LstmQueueDescriptor::m_ForgetGateBias, LstmOptLayerNormParameters::m_ForgetLayerNormWeights, LstmQueueDescriptor::m_ForgetLayerNormWeights, LstmOptCifgParameters::m_InputGateBias, LstmQueueDescriptor::m_InputGateBias, LstmOptLayerNormParameters::m_InputLayerNormWeights, LstmQueueDescriptor::m_InputLayerNormWeights, LstmBasicParameters::m_InputToCellWeights, LstmQueueDescriptor::m_InputToCellWeights, LstmBasicParameters::m_InputToForgetWeights, LstmQueueDescriptor::m_InputToForgetWeights, LstmOptCifgParameters::m_InputToInputWeights, LstmQueueDescriptor::m_InputToInputWeights, LstmBasicParameters::m_InputToOutputWeights, LstmQueueDescriptor::m_InputToOutputWeights, LstmDescriptor::m_LayerNormEnabled, LstmLayer::m_LayerNormParameters, LstmBasicParameters::m_OutputGateBias, LstmQueueDescriptor::m_OutputGateBias, LstmOptLayerNormParameters::m_OutputLayerNormWeights, LstmQueueDescriptor::m_OutputLayerNormWeights, LayerWithParameters< LstmDescriptor >::m_Param, LstmDescriptor::m_PeepholeEnabled, LstmLayer::m_PeepholeParameters, LstmOptProjectionParameters::m_ProjectionBias, LstmQueueDescriptor::m_ProjectionBias, LstmDescriptor::m_ProjectionEnabled, LstmLayer::m_ProjectionParameters, LstmOptProjectionParameters::m_ProjectionWeights, LstmQueueDescriptor::m_ProjectionWeights, LstmBasicParameters::m_RecurrentToCellWeights, LstmQueueDescriptor::m_RecurrentToCellWeights, LstmBasicParameters::m_RecurrentToForgetWeights, LstmQueueDescriptor::m_RecurrentToForgetWeights, LstmOptCifgParameters::m_RecurrentToInputWeights, LstmQueueDescriptor::m_RecurrentToInputWeights, LstmBasicParameters::m_RecurrentToOutputWeights, LstmQueueDescriptor::m_RecurrentToOutputWeights, and LayerWithParameters< LstmDescriptor >::PrepInfoAndDesc().

23 {
24  LstmQueueDescriptor descriptor;
25 
26  // Basic parameters
27  descriptor.m_InputToForgetWeights = m_BasicParameters.m_InputToForgetWeights.get();
28  descriptor.m_InputToCellWeights = m_BasicParameters.m_InputToCellWeights.get();
29  descriptor.m_InputToOutputWeights = m_BasicParameters.m_InputToOutputWeights.get();
30  descriptor.m_RecurrentToForgetWeights = m_BasicParameters.m_RecurrentToForgetWeights.get();
31  descriptor.m_RecurrentToCellWeights = m_BasicParameters.m_RecurrentToCellWeights.get();
32  descriptor.m_RecurrentToOutputWeights = m_BasicParameters.m_RecurrentToOutputWeights.get();
33  descriptor.m_ForgetGateBias = m_BasicParameters.m_ForgetGateBias.get();
34  descriptor.m_CellBias = m_BasicParameters.m_CellBias.get();
35  descriptor.m_OutputGateBias = m_BasicParameters.m_OutputGateBias.get();
36 
37  // Cifg parameters
39  {
40  descriptor.m_InputToInputWeights = m_CifgParameters.m_InputToInputWeights.get();
41  descriptor.m_RecurrentToInputWeights = m_CifgParameters.m_RecurrentToInputWeights.get();
42  descriptor.m_CellToInputWeights = m_CifgParameters.m_CellToInputWeights.get();
43  descriptor.m_InputGateBias = m_CifgParameters.m_InputGateBias.get();
44  }
45 
46  // Projection parameters
48  {
49  descriptor.m_ProjectionWeights = m_ProjectionParameters.m_ProjectionWeights.get();
50  descriptor.m_ProjectionBias = m_ProjectionParameters.m_ProjectionBias.get();
51  }
52 
53  // Peephole parameters
55  {
56  descriptor.m_CellToForgetWeights = m_PeepholeParameters.m_CellToForgetWeights.get();
57  descriptor.m_CellToOutputWeights = m_PeepholeParameters.m_CellToOutputWeights.get();
58  }
59 
60  // Layer normalisation parameters
62  {
64  {
65  descriptor.m_InputLayerNormWeights = m_LayerNormParameters.m_InputLayerNormWeights.get();
66  }
67  descriptor.m_ForgetLayerNormWeights = m_LayerNormParameters.m_ForgetLayerNormWeights.get();
68  descriptor.m_CellLayerNormWeights = m_LayerNormParameters.m_CellLayerNormWeights.get();
69  descriptor.m_OutputLayerNormWeights = m_LayerNormParameters.m_OutputLayerNormWeights.get();
70  }
71 
72  return factory.CreateLstm(descriptor, PrepInfoAndDesc(descriptor));
73 }
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
LstmDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).
std::unique_ptr< ScopedCpuTensorHandle > m_InputToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:29
std::unique_ptr< ScopedCpuTensorHandle > m_CellToInputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:33
std::unique_ptr< ScopedCpuTensorHandle > m_CellLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:21
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:63
std::unique_ptr< ScopedCpuTensorHandle > m_OutputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:73
std::unique_ptr< ScopedCpuTensorHandle > m_InputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:17
std::unique_ptr< ScopedCpuTensorHandle > m_CellBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:71
std::unique_ptr< ScopedCpuTensorHandle > m_CellToForgetWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:49
std::unique_ptr< ScopedCpuTensorHandle > m_OutputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:23
bool m_PeepholeEnabled
Enable/disable peephole.
LstmOptLayerNormParameters m_LayerNormParameters
Definition: LstmLayer.hpp:85
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:31
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
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).
std::unique_ptr< ScopedCpuTensorHandle > m_InputToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:59
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *LayerCreateWorkload.
std::unique_ptr< ScopedCpuTensorHandle > m_CellToOutputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:51
bool m_LayerNormEnabled
Enable/disable layer normalization.
std::unique_ptr< ScopedCpuTensorHandle > m_ProjectionWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:41
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
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

◆ GetConstantTensorsByRef()

Layer::ConstantTensors GetConstantTensorsByRef ( )
overrideprotectedvirtual

Retrieve the handles to the constant values stored by the layer.

Returns
A vector of the constant tensors stored by this layer.

Reimplemented from Layer.

Definition at line 266 of file LstmLayer.cpp.

References LstmLayer::m_BasicParameters, LstmBasicParameters::m_CellBias, LstmOptLayerNormParameters::m_CellLayerNormWeights, LstmOptPeepholeParameters::m_CellToForgetWeights, LstmOptCifgParameters::m_CellToInputWeights, LstmOptPeepholeParameters::m_CellToOutputWeights, LstmLayer::m_CifgParameters, LstmBasicParameters::m_ForgetGateBias, LstmOptLayerNormParameters::m_ForgetLayerNormWeights, LstmOptCifgParameters::m_InputGateBias, LstmOptLayerNormParameters::m_InputLayerNormWeights, LstmBasicParameters::m_InputToCellWeights, LstmBasicParameters::m_InputToForgetWeights, LstmOptCifgParameters::m_InputToInputWeights, LstmBasicParameters::m_InputToOutputWeights, LstmLayer::m_LayerNormParameters, LstmBasicParameters::m_OutputGateBias, LstmOptLayerNormParameters::m_OutputLayerNormWeights, LstmLayer::m_PeepholeParameters, LstmOptProjectionParameters::m_ProjectionBias, LstmLayer::m_ProjectionParameters, LstmOptProjectionParameters::m_ProjectionWeights, LstmBasicParameters::m_RecurrentToCellWeights, LstmBasicParameters::m_RecurrentToForgetWeights, LstmOptCifgParameters::m_RecurrentToInputWeights, and LstmBasicParameters::m_RecurrentToOutputWeights.

267 {
277 
278  // Cifg parameters
283 
284  // Projection parameters
287 
288  // Peephole parameters
291 
292  // Layer normalisation parameters
297 }
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
LstmBasicParameters m_BasicParameters
Definition: LstmLayer.hpp:81
std::unique_ptr< ScopedCpuTensorHandle > m_InputToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:29
std::unique_ptr< ScopedCpuTensorHandle > m_CellToInputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:33
std::unique_ptr< ScopedCpuTensorHandle > m_CellLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:21
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:63
std::unique_ptr< ScopedCpuTensorHandle > m_OutputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:73
std::unique_ptr< ScopedCpuTensorHandle > m_InputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:17
std::unique_ptr< ScopedCpuTensorHandle > m_CellBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:71
std::unique_ptr< ScopedCpuTensorHandle > m_CellToForgetWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:49
std::unique_ptr< ScopedCpuTensorHandle > m_OutputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:23
LstmOptLayerNormParameters m_LayerNormParameters
Definition: LstmLayer.hpp:85
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToInputWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:31
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
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
std::unique_ptr< ScopedCpuTensorHandle > m_InputToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:59
std::unique_ptr< ScopedCpuTensorHandle > m_CellToOutputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:51
std::unique_ptr< ScopedCpuTensorHandle > m_ProjectionWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:41
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
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

◆ InferOutputShapes()

std::vector< TensorShape > InferOutputShapes ( const std::vector< TensorShape > &  inputShapes) const
overridevirtual

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.

Parameters
[in]inputShapesThe input shapes layer has.
Returns
A vector to the inferred output shape.

Reimplemented from Layer.

Definition at line 142 of file LstmLayer.cpp.

References LstmDescriptor::m_CifgEnabled, and LayerWithParameters< LstmDescriptor >::m_Param.

Referenced by LstmLayer::ValidateTensorShapesFromInputs().

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 }
LstmDescriptor m_Param
The parameters for the layer (not including tensor-valued weights etc.).
bool m_CifgEnabled
Enable/disable cifg (coupled input & forget gate).

◆ ValidateTensorShapesFromInputs()

void ValidateTensorShapesFromInputs ( )
overridevirtual

Check if the input tensor shape(s) will lead to a valid configuration of LstmLayer.

Implements Layer.

Definition at line 160 of file LstmLayer.cpp.

References CHECK_LOCATION, InputSlot::GetConnection(), Layer::GetInputSlot(), Layer::GetOutputSlot(), TensorInfo::GetShape(), IOutputSlot::GetTensorInfo(), OutputSlot::GetTensorInfo(), LstmLayer::InferOutputShapes(), LstmLayer::m_BasicParameters, LstmBasicParameters::m_CellBias, LstmOptLayerNormParameters::m_CellLayerNormWeights, LstmOptPeepholeParameters::m_CellToForgetWeights, LstmOptCifgParameters::m_CellToInputWeights, LstmOptPeepholeParameters::m_CellToOutputWeights, LstmDescriptor::m_CifgEnabled, LstmLayer::m_CifgParameters, LstmBasicParameters::m_ForgetGateBias, LstmOptLayerNormParameters::m_ForgetLayerNormWeights, LstmOptCifgParameters::m_InputGateBias, LstmOptLayerNormParameters::m_InputLayerNormWeights, LstmBasicParameters::m_InputToCellWeights, LstmBasicParameters::m_InputToForgetWeights, LstmOptCifgParameters::m_InputToInputWeights, LstmBasicParameters::m_InputToOutputWeights, LstmDescriptor::m_LayerNormEnabled, LstmLayer::m_LayerNormParameters, LstmBasicParameters::m_OutputGateBias, LstmOptLayerNormParameters::m_OutputLayerNormWeights, LayerWithParameters< LstmDescriptor >::m_Param, LstmDescriptor::m_PeepholeEnabled, LstmLayer::m_PeepholeParameters, LstmDescriptor::m_ProjectionEnabled, LstmLayer::m_ProjectionParameters, LstmOptProjectionParameters::m_ProjectionWeights, LstmBasicParameters::m_RecurrentToCellWeights, LstmBasicParameters::m_RecurrentToForgetWeights, LstmOptCifgParameters::m_RecurrentToInputWeights, LstmBasicParameters::m_RecurrentToOutputWeights, and Layer::VerifyLayerConnections().

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 }
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
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
std::unique_ptr< ScopedCpuTensorHandle > m_CellToInputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:33
std::unique_ptr< ScopedCpuTensorHandle > m_CellLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:21
std::unique_ptr< ScopedCpuTensorHandle > m_RecurrentToForgetWeights
A unique pointer to represent 2D weights tensor with dimensions [output_size, num_units].
Definition: LstmLayer.hpp:63
std::unique_ptr< ScopedCpuTensorHandle > m_OutputGateBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:73
std::unique_ptr< ScopedCpuTensorHandle > m_InputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:17
const IOutputSlot * GetConnection() const override
Definition: Layer.hpp:199
std::unique_ptr< ScopedCpuTensorHandle > m_CellBias
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:71
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
std::unique_ptr< ScopedCpuTensorHandle > m_OutputLayerNormWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:23
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
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
LstmOptProjectionParameters m_ProjectionParameters
Definition: LstmLayer.hpp:83
bool m_CifgEnabled
Enable/disable cifg (coupled input & forget gate).
std::unique_ptr< ScopedCpuTensorHandle > m_InputToCellWeights
A unique pointer to represent 2D weights tensor with dimensions [input_size, num_units].
Definition: LstmLayer.hpp:59
std::unique_ptr< ScopedCpuTensorHandle > m_CellToOutputWeights
A unique pointer to represent 1D weights tensor with dimensions [num_units].
Definition: LstmLayer.hpp:51
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
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
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 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

Member Data Documentation

◆ m_BasicParameters

◆ m_CifgParameters

◆ m_LayerNormParameters

◆ m_PeepholeParameters

◆ m_ProjectionParameters


The documentation for this class was generated from the following files: