surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 4 | // |
| 5 | #pragma once |
| 6 | |
| 7 | #include <Layer.hpp> |
| 8 | |
| 9 | namespace armnn |
| 10 | { |
| 11 | |
| 12 | template <typename Parameters> |
| 13 | class LayerWithParameters : public Layer |
| 14 | { |
| 15 | public: |
| 16 | using DescriptorType = Parameters; |
| 17 | |
Jim Flynn | e466596 | 2022-01-31 16:08:53 +0000 | [diff] [blame^] | 18 | const Parameters& GetParameters() const override { return m_Param; } |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 19 | |
| 20 | /// Helper to serialize the layer parameters to string |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 21 | /// (currently used in DotSerializer and company). |
Andre Ghattas | 23ae2ea | 2019-08-07 12:18:38 +0100 | [diff] [blame] | 22 | void SerializeLayerParameters(ParameterStringifyFunction& fn) const override |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 23 | { |
| 24 | StringifyLayerParameters<Parameters>::Serialize(fn, m_Param); |
Andre Ghattas | 23ae2ea | 2019-08-07 12:18:38 +0100 | [diff] [blame] | 25 | Layer::SerializeLayerParameters(fn); |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | protected: |
| 29 | LayerWithParameters(unsigned int numInputSlots, |
| 30 | unsigned int numOutputSlots, |
| 31 | LayerType type, |
Derek Lamberti | 0cff163 | 2018-09-18 16:02:25 +0100 | [diff] [blame] | 32 | const Parameters& param, |
| 33 | const char* name) |
| 34 | : Layer(numInputSlots, numOutputSlots, type, name) |
| 35 | , m_Param(param) |
| 36 | { |
| 37 | } |
| 38 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 39 | ~LayerWithParameters() = default; |
| 40 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 41 | /// Helper function to reduce duplication in *Layer::CreateWorkload. |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 42 | template <typename QueueDescriptor> |
Derek Lamberti | 94a88d2 | 2019-12-10 21:12:59 +0000 | [diff] [blame] | 43 | WorkloadInfo PrepInfoAndDesc(QueueDescriptor& descriptor) const |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 44 | { |
| 45 | descriptor.m_Parameters = m_Param; |
Derek Lamberti | 94a88d2 | 2019-12-10 21:12:59 +0000 | [diff] [blame] | 46 | return Layer::PrepInfoAndDesc(descriptor); |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 47 | } |
| 48 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 49 | /// The parameters for the layer (not including tensor-valued weights etc.). |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 50 | Parameters m_Param; |
Finn Williams | b454c5c | 2021-02-09 15:56:23 +0000 | [diff] [blame] | 51 | |
| 52 | void ExecuteStrategy(IStrategy& strategy) const override |
| 53 | { |
| 54 | strategy.ExecuteStrategy(this, GetParameters(), {}, GetName()); |
| 55 | } |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | } // namespace |