blob: 2ac16c5f5fc9e621b514c89a5b7b53c310727c2e [file] [log] [blame]
surmeh013537c2c2018-05-18 16:31:43 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
surmeh013537c2c2018-05-18 16:31:43 +01004//
5#pragma once
6
7#include <Layer.hpp>
8
9namespace armnn
10{
11
12template <typename Parameters>
13class LayerWithParameters : public Layer
14{
15public:
16 using DescriptorType = Parameters;
17
Jim Flynne4665962022-01-31 16:08:53 +000018 const Parameters& GetParameters() const override { return m_Param; }
surmeh013537c2c2018-05-18 16:31:43 +010019
20 /// Helper to serialize the layer parameters to string
telsoa01c577f2c2018-08-31 09:22:23 +010021 /// (currently used in DotSerializer and company).
Andre Ghattas23ae2ea2019-08-07 12:18:38 +010022 void SerializeLayerParameters(ParameterStringifyFunction& fn) const override
surmeh013537c2c2018-05-18 16:31:43 +010023 {
24 StringifyLayerParameters<Parameters>::Serialize(fn, m_Param);
Andre Ghattas23ae2ea2019-08-07 12:18:38 +010025 Layer::SerializeLayerParameters(fn);
surmeh013537c2c2018-05-18 16:31:43 +010026 }
27
28protected:
29 LayerWithParameters(unsigned int numInputSlots,
30 unsigned int numOutputSlots,
31 LayerType type,
Derek Lamberti0cff1632018-09-18 16:02:25 +010032 const Parameters& param,
33 const char* name)
34 : Layer(numInputSlots, numOutputSlots, type, name)
35 , m_Param(param)
36 {
37 }
38
surmeh013537c2c2018-05-18 16:31:43 +010039 ~LayerWithParameters() = default;
40
telsoa01c577f2c2018-08-31 09:22:23 +010041 /// Helper function to reduce duplication in *Layer::CreateWorkload.
surmeh013537c2c2018-05-18 16:31:43 +010042 template <typename QueueDescriptor>
Derek Lamberti94a88d22019-12-10 21:12:59 +000043 WorkloadInfo PrepInfoAndDesc(QueueDescriptor& descriptor) const
surmeh013537c2c2018-05-18 16:31:43 +010044 {
45 descriptor.m_Parameters = m_Param;
Derek Lamberti94a88d22019-12-10 21:12:59 +000046 return Layer::PrepInfoAndDesc(descriptor);
surmeh013537c2c2018-05-18 16:31:43 +010047 }
48
telsoa01c577f2c2018-08-31 09:22:23 +010049 /// The parameters for the layer (not including tensor-valued weights etc.).
surmeh013537c2c2018-05-18 16:31:43 +010050 Parameters m_Param;
Finn Williamsb454c5c2021-02-09 15:56:23 +000051
52 void ExecuteStrategy(IStrategy& strategy) const override
53 {
54 strategy.ExecuteStrategy(this, GetParameters(), {}, GetName());
55 }
surmeh013537c2c2018-05-18 16:31:43 +010056};
57
58} // namespace