ArmNN
 24.02
LayerWithParameters.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
7 #include "ConstantLayer.hpp"
8 #include <Layer.hpp>
9 
10 namespace armnn
11 {
12 
13 template <typename Parameters>
14 class LayerWithParameters : public Layer
15 {
16 public:
17  using DescriptorType = Parameters;
18 
19  const Parameters& GetParameters() const override { return m_Param; }
20 
21  /// Helper to serialize the layer parameters to string
22  /// (currently used in DotSerializer and company).
24  {
27  }
28 
29 protected:
30  LayerWithParameters(unsigned int numInputSlots,
31  unsigned int numOutputSlots,
32  LayerType type,
33  const Parameters& param,
34  const char* name)
35  : Layer(numInputSlots, numOutputSlots, type, name)
36  , m_Param(param)
37  {
38  }
39 
40  ~LayerWithParameters() = default;
41 
42  /// Helper function to reduce duplication in *Layer::CreateWorkload.
43  template <typename QueueDescriptor>
45  {
46  descriptor.m_Parameters = m_Param;
48  return Layer::PrepInfoAndDesc(descriptor);
49  }
50 
51  /// The parameters for the layer (not including tensor-valued weights etc.).
52  Parameters m_Param;
53 
54  void ExecuteStrategy(IStrategy& strategy) const override
55  {
56  strategy.ExecuteStrategy(this, GetParameters(), {}, GetName());
57  }
58 
60  {
62  for (unsigned int i = 0; i < GetNumInputSlots(); ++i)
63  {
65  {
66  auto &inputLayer = GetInputSlot(i).GetConnectedOutputSlot()->GetOwningLayer();
67  if (inputLayer.GetType() == armnn::LayerType::Constant)
68  {
69  auto &constantLayer = static_cast<ConstantLayer&>(inputLayer);
70 
71  tensors.push_back(constantLayer.m_LayerOutput);
72  }
73  }
74  }
75  return tensors;
76  }
77 };
78 
79 } // namespace
armnn::LayerWithParameters::SerializeLayerParameters
void SerializeLayerParameters(ParameterStringifyFunction &fn) const override
Helper to serialize the layer parameters to string (currently used in DotSerializer and company).
Definition: LayerWithParameters.hpp:23
armnn::QueueDescriptor::m_AllowExpandedDims
bool m_AllowExpandedDims
Definition: WorkloadData.hpp:52
armnn::LayerWithParameters::ExecuteStrategy
void ExecuteStrategy(IStrategy &strategy) const override
Apply a visitor to this layer.
Definition: LayerWithParameters.hpp:54
armnn::IStrategy
Definition: IStrategy.hpp:16
armnn::TensorInfo::IsConstant
bool IsConstant() const
Definition: Tensor.cpp:509
armnn::Layer::GetInputSlot
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Definition: Layer.hpp:337
armnn::LayerWithParameters::GetParameters
const Parameters & GetParameters() const override
If the layer has a descriptor return it.
Definition: LayerWithParameters.hpp:19
armnn::LayerWithParameters
Definition: LayerWithParameters.hpp:14
armnn::Layer::GetName
const char * GetName() const override
Returns the name of the layer.
Definition: Layer.hpp:332
armnn::Layer
Definition: Layer.hpp:230
armnn::IConnectableLayer::ImmutableConstantTensors
std::vector< std::reference_wrapper< const std::shared_ptr< ConstTensorHandle > >> ImmutableConstantTensors
Definition: INetwork.hpp:141
armnn::InputSlot::GetTensorInfo
const TensorInfo & GetTensorInfo() const override
Gets the TensorInfo for this InputSlot.
Definition: Layer.cpp:592
armnn::LayerWithParameters::GetConnectedConstantAsInputTensors
Layer::ImmutableConstantTensors GetConnectedConstantAsInputTensors() const
Definition: LayerWithParameters.hpp:59
armnn::Layer::SerializeLayerParameters
virtual void SerializeLayerParameters(ParameterStringifyFunction &fn) const
Helper to serialize the layer parameters to string.
Definition: Layer.cpp:518
armnn::OutputSlot::GetOwningLayer
Layer & GetOwningLayer() const
Definition: Layer.hpp:132
armnn::LayerWithParameters::m_Param
Parameters m_Param
The parameters for the layer (not including tensor-valued weights etc.).
Definition: LayerWithParameters.hpp:52
armnn::LayerWithParameters::PrepInfoAndDesc
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *Layer::CreateWorkload.
Definition: LayerWithParameters.hpp:44
armnn::WorkloadInfo
Contains information about TensorInfos of a layer.
Definition: WorkloadInfo.hpp:16
armnn::LayerWithParameters::~LayerWithParameters
~LayerWithParameters()=default
armnn::Layer::PrepInfoAndDesc
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *Layer::CreateWorkload.
Definition: Layer.hpp:409
armnn::QueueDescriptor
Definition: WorkloadData.hpp:24
armnn::ParameterStringifyFunction
std::function< void(const std::string &name, const std::string &value)> ParameterStringifyFunction
Definition: SerializeLayerParameters.hpp:14
armnn::StringifyLayerParameters::Serialize
static void Serialize(ParameterStringifyFunction &, const LayerParameter &)
Definition: SerializeLayerParameters.hpp:25
armnn::InputSlot::GetConnection
const IOutputSlot * GetConnection() const override
Definition: Layer.hpp:219
armnn::Layer::GetNumInputSlots
unsigned int GetNumInputSlots() const override
Returns the number of connectable input slots.
Definition: Layer.hpp:334
armnn::StridedSliceDescriptor
A StridedSliceDescriptor for the StridedSliceLayer.
Definition: Descriptors.hpp:1303
ConstantLayer.hpp
armnn::InputSlot::GetConnectedOutputSlot
const OutputSlot * GetConnectedOutputSlot() const
Definition: Layer.hpp:56
armnn::ConstantLayer
A layer that the constant data can be bound to.
Definition: ConstantLayer.hpp:15
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
Layer.hpp
armnn::Layer::GetAllowExpandedDims
bool GetAllowExpandedDims() const
Definition: Layer.hpp:256
armnn::LayerWithParameters::LayerWithParameters
LayerWithParameters(unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const Parameters &param, const char *name)
Definition: LayerWithParameters.hpp:30
armnn::LayerType
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below.
Definition: Types.hpp:491
armnn::IStrategy::ExecuteStrategy
virtual void ExecuteStrategy(const IConnectableLayer *layer, const armnn::BaseDescriptor &descriptor, const std::vector< armnn::ConstTensor > &constants, const char *name, const armnn::LayerBindingId id=0)=0
armnn::LayerType::Constant
@ Constant