ArmNN
 22.08
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  {
61  Layer::ConstantTensors tensors;
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  if (tensors.empty())
76  {
77  const std::string warningMessage{"GetConnectedConstantAsInputTensors() called on Layer with no "
78  "connected Constants as Input Tensors."};
79  ARMNN_LOG(warning) << warningMessage;
80  }
81  return tensors;
82  }
83 };
84 
85 
86 
87 
88 } // namespace
A layer that the constant data can be bound to.
bool IsConstant() const
Definition: Tensor.cpp:509
void ExecuteStrategy(IStrategy &strategy) const override
Apply a visitor to this layer.
LayerWithParameters(unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const Parameters &param, const char *name)
Parameters m_Param
The parameters for the layer (not including tensor-valued weights etc.).
unsigned int GetNumInputSlots() const override
Returns the number of connectable input slots.
Definition: Layer.hpp:321
Layer & GetOwningLayer() const
Definition: Layer.hpp:119
#define ARMNN_LOG(severity)
Definition: Logging.hpp:205
void SerializeLayerParameters(ParameterStringifyFunction &fn) const override
Helper to serialize the layer parameters to string (currently used in DotSerializer and company)...
Copyright (c) 2021 ARM Limited and Contributors.
const Parameters & GetParameters() const override
If the layer has a descriptor return it.
const IOutputSlot * GetConnection() const override
Definition: Layer.hpp:206
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Definition: Layer.hpp:324
std::vector< std::reference_wrapper< std::shared_ptr< ConstTensorHandle > >> ConstantTensors
Definition: INetwork.hpp:114
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *LayerCreateWorkload.
Definition: Layer.hpp:396
const OutputSlot * GetConnectedOutputSlot() const
Definition: Layer.hpp:56
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
A Pooling3dDescriptor for the Pooling3dLayer.
Layer::ConstantTensors GetConnectedConstantAsInputTensors()
bool GetAllowExpandedDims() const
Definition: Layer.hpp:243
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *LayerCreateWorkload.
virtual void SerializeLayerParameters(ParameterStringifyFunction &fn) const
Helper to serialize the layer parameters to string.
Definition: Layer.cpp:505
virtual const TensorInfo & GetTensorInfo() const =0
Contains information about TensorInfos of a layer.
const char * GetName() const override
Returns the name of the layer.
Definition: Layer.hpp:319
std::function< void(const std::string &name, const std::string &value)> ParameterStringifyFunction
static void Serialize(ParameterStringifyFunction &, const LayerParameter &)
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below...
Definition: Types.hpp:468