Release 18.08
[platform/upstream/armnn.git] / src / armnn / layers / L2NormalizationLayer.cpp
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // See LICENSE file in the project root for full license information.
4 //
5 #include "L2NormalizationLayer.hpp"
6
7 #include "LayerCloneBase.hpp"
8
9 #include <armnn/TypesUtils.hpp>
10 #include <backends/WorkloadData.hpp>
11 #include <backends/WorkloadFactory.hpp>
12
13 namespace armnn
14 {
15
16 L2NormalizationLayer::L2NormalizationLayer(const char* name)
17     : Layer(1, 1, LayerType::L2Normalization, name)
18 {
19 }
20
21 std::unique_ptr<IWorkload> L2NormalizationLayer::CreateWorkload(const Graph& graph,
22     const IWorkloadFactory& factory) const
23 {
24     L2NormalizationQueueDescriptor descriptor;
25     return factory.CreateL2Normalization(descriptor, PrepInfoAndDesc(descriptor, graph));
26 }
27
28 L2NormalizationLayer* L2NormalizationLayer::Clone(Graph& graph) const
29 {
30     return CloneBase<L2NormalizationLayer>(graph, GetName());
31 }
32
33 void L2NormalizationLayer::ValidateTensorShapesFromInputs()
34 {
35     VerifyLayerConnections(1, CHECK_LOCATION());
36
37     auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetConnection()->GetTensorInfo().GetShape() });
38
39     BOOST_ASSERT(inferredShapes.size() == 1);
40
41     ConditionalThrowIfNotEqual<LayerValidationException>(
42         "L2NormalizationLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
43         GetOutputSlot(0).GetTensorInfo().GetShape(),
44         inferredShapes[0]);
45 }
46
47 } // namespace armnn