ArmNN
 25.11
Loading...
Searching...
No Matches
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
10namespace armnn
11{
12
13template <typename Parameters>
15{
16public:
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).
28
29protected:
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
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 {
64 if (GetInputSlot(i).GetConnection() && GetInputSlot(i).GetTensorInfo().IsConstant())
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
A layer that the constant data can be bound to.
std::vector< std::reference_wrapper< const std::shared_ptr< ConstTensorHandle > > > ImmutableConstantTensors
Definition INetwork.hpp:141
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
const OutputSlot * GetConnectedOutputSlot() const
Definition Layer.hpp:56
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Definition Layer.hpp:337
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *LayerCreateWorkload.
Definition Layer.hpp:409
Layer(unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const char *name)
Definition Layer.cpp:260
unsigned int GetNumInputSlots() const override
Returns the number of connectable input slots.
Definition Layer.hpp:334
virtual void SerializeLayerParameters(ParameterStringifyFunction &fn) const
Helper to serialize the layer parameters to string.
Definition Layer.cpp:540
const char * GetName() const override
Returns the name of the layer.
Definition Layer.hpp:332
bool GetAllowExpandedDims() const
Definition Layer.hpp:256
LayerWithParameters(unsigned int numInputSlots, unsigned int numOutputSlots, LayerType type, const Parameters &param, const char *name)
void SerializeLayerParameters(ParameterStringifyFunction &fn) const override
Helper to serialize the layer parameters to string (currently used in DotSerializer and company).
WorkloadInfo PrepInfoAndDesc(QueueDescriptor &descriptor) const
Helper function to reduce duplication in *LayerCreateWorkload.
void ExecuteStrategy(IStrategy &strategy) const override
Apply a visitor to this layer.
const Parameters & GetParameters() const override
If the layer has a descriptor return it.
Parameters m_Param
The parameters for the layer (not including tensor-valued weights etc.).
Layer::ImmutableConstantTensors GetConnectedConstantAsInputTensors() const
Layer & GetOwningLayer() const
Definition Layer.hpp:132
Copyright (c) 2021 ARM Limited and Contributors.
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below.
Definition Types.hpp:494
std::function< void(const std::string &name, const std::string &value)> ParameterStringifyFunction
armnn::TensorInfo GetTensorInfo(unsigned int numberOfBatches, unsigned int numberOfChannels, unsigned int height, unsigned int width, const armnn::DataLayout dataLayout, const armnn::DataType dataType)
static void Serialize(ParameterStringifyFunction &, const LayerParameter &)
Contains information about TensorInfos of a layer.