Release 18.08
[platform/upstream/armnn.git] / src / armnn / layers / LayerWithParameters.hpp
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // See LICENSE file in the project root for full license information.
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
18     const Parameters& GetParameters() const { return m_Param; }
19
20     /// Helper to serialize the layer parameters to string
21     /// (currently used in DotSerializer and company).
22     void SerializeLayerParameters(ParameterStringifyFunction & fn) const
23     {
24         StringifyLayerParameters<Parameters>::Serialize(fn, m_Param);
25     }
26
27 protected:
28     LayerWithParameters(unsigned int numInputSlots,
29                         unsigned int numOutputSlots,
30                         LayerType type,
31                         const Parameters& param,
32                         const char* name)
33     :   Layer(numInputSlots, numOutputSlots, type, name)
34     ,   m_Param(param)
35     {
36     }
37
38     ~LayerWithParameters() = default;
39
40     /// Helper function to reduce duplication in *Layer::CreateWorkload.
41     template <typename QueueDescriptor>
42     WorkloadInfo PrepInfoAndDesc(QueueDescriptor& descriptor, const Graph& graph) const
43     {
44         descriptor.m_Parameters = m_Param;
45         return Layer::PrepInfoAndDesc(descriptor, graph);
46     }
47
48     /// The parameters for the layer (not including tensor-valued weights etc.).
49     Parameters m_Param;
50 };
51
52 } // namespace