blob: 9cc9745ea3d7390f3dd11b38d3543c399a7c70c1 [file] [log] [blame]
Kevin Mayce5045a2019-10-02 14:07:47 +01001//
Declan-ARM7c75e332024-03-12 16:40:25 +00002// Copyright © 2019-2024 Arm Ltd and Contributors. All rights reserved.
Kevin Mayce5045a2019-10-02 14:07:47 +01003// SPDX-License-Identifier: MIT
4//
5#include "InstanceNormalizationLayer.hpp"
6
7#include "LayerCloneBase.hpp"
8
9#include <armnn/TypesUtils.hpp>
Colm Donelan0c479742021-12-10 12:43:54 +000010#include <armnn/backends/WorkloadData.hpp>
11#include <armnn/backends/WorkloadFactory.hpp>
Kevin Mayce5045a2019-10-02 14:07:47 +010012
13namespace armnn
14{
15
16InstanceNormalizationLayer::InstanceNormalizationLayer(const InstanceNormalizationDescriptor& param, const char* name)
17 : LayerWithParameters(1, 1, LayerType::InstanceNormalization, param, name)
18{
19}
20
Derek Lamberti94a88d22019-12-10 21:12:59 +000021std::unique_ptr<IWorkload> InstanceNormalizationLayer::CreateWorkload(const IWorkloadFactory& factory) const
Kevin Mayce5045a2019-10-02 14:07:47 +010022{
23 InstanceNormalizationQueueDescriptor descriptor;
Keith Davisdf04d232020-10-23 17:20:05 +010024 SetAdditionalInfo(descriptor);
25
Teresa Charlin611c7fb2022-01-07 09:47:29 +000026 return factory.CreateWorkload(LayerType::InstanceNormalization, descriptor, PrepInfoAndDesc(descriptor));
Kevin Mayce5045a2019-10-02 14:07:47 +010027}
28
29InstanceNormalizationLayer* InstanceNormalizationLayer::Clone(Graph& graph) const
30{
31 return CloneBase<InstanceNormalizationLayer>(graph, m_Param, GetName());
32}
33
Finn Williamsf24effa2020-07-03 10:12:03 +010034void InstanceNormalizationLayer::ValidateTensorShapesFromInputs()
Kevin Mayce5045a2019-10-02 14:07:47 +010035{
36 VerifyLayerConnections(1, CHECK_LOCATION());
37
Finn Williams87d0bda2020-07-03 10:12:03 +010038 const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape();
39
Finn Williamsf24effa2020-07-03 10:12:03 +010040 VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod);
Finn Williams87d0bda2020-07-03 10:12:03 +010041
Mike Kellya9ac6ba2023-06-30 15:18:26 +010042 auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() });
Kevin Mayce5045a2019-10-02 14:07:47 +010043
Declan-ARM7c75e332024-03-12 16:40:25 +000044 if (inferredShapes.size() != 1)
45 {
46 throw armnn::LayerValidationException("inferredShapes has "
47 + std::to_string(inferredShapes.size()) +
48 " elements - should only have 1.");
49 }
Kevin Mayce5045a2019-10-02 14:07:47 +010050
Finn Williamsf24effa2020-07-03 10:12:03 +010051 ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "InstanceNormalizationLayer");
Kevin Mayce5045a2019-10-02 14:07:47 +010052}
53
Nikhil Raj4d2eec02022-05-30 11:08:52 +010054void InstanceNormalizationLayer::ExecuteStrategy(IStrategy& strategy) const
Kevin Mayce5045a2019-10-02 14:07:47 +010055{
Nikhil Raj4d2eec02022-05-30 11:08:52 +010056 strategy.ExecuteStrategy(this, GetParameters(), {}, GetName());
Kevin Mayce5045a2019-10-02 14:07:47 +010057}
Kevin Mayce5045a2019-10-02 14:07:47 +010058
59} // namespace armnn