Kevin May | ce5045a | 2019-10-02 14:07:47 +0100 | [diff] [blame] | 1 | // |
Declan-ARM | 7c75e33 | 2024-03-12 16:40:25 +0000 | [diff] [blame^] | 2 | // Copyright © 2019-2024 Arm Ltd and Contributors. All rights reserved. |
Kevin May | ce5045a | 2019-10-02 14:07:47 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | #include "InstanceNormalizationLayer.hpp" |
| 6 | |
| 7 | #include "LayerCloneBase.hpp" |
| 8 | |
| 9 | #include <armnn/TypesUtils.hpp> |
Colm Donelan | 0c47974 | 2021-12-10 12:43:54 +0000 | [diff] [blame] | 10 | #include <armnn/backends/WorkloadData.hpp> |
| 11 | #include <armnn/backends/WorkloadFactory.hpp> |
Kevin May | ce5045a | 2019-10-02 14:07:47 +0100 | [diff] [blame] | 12 | |
| 13 | namespace armnn |
| 14 | { |
| 15 | |
| 16 | InstanceNormalizationLayer::InstanceNormalizationLayer(const InstanceNormalizationDescriptor& param, const char* name) |
| 17 | : LayerWithParameters(1, 1, LayerType::InstanceNormalization, param, name) |
| 18 | { |
| 19 | } |
| 20 | |
Derek Lamberti | 94a88d2 | 2019-12-10 21:12:59 +0000 | [diff] [blame] | 21 | std::unique_ptr<IWorkload> InstanceNormalizationLayer::CreateWorkload(const IWorkloadFactory& factory) const |
Kevin May | ce5045a | 2019-10-02 14:07:47 +0100 | [diff] [blame] | 22 | { |
| 23 | InstanceNormalizationQueueDescriptor descriptor; |
Keith Davis | df04d23 | 2020-10-23 17:20:05 +0100 | [diff] [blame] | 24 | SetAdditionalInfo(descriptor); |
| 25 | |
Teresa Charlin | 611c7fb | 2022-01-07 09:47:29 +0000 | [diff] [blame] | 26 | return factory.CreateWorkload(LayerType::InstanceNormalization, descriptor, PrepInfoAndDesc(descriptor)); |
Kevin May | ce5045a | 2019-10-02 14:07:47 +0100 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | InstanceNormalizationLayer* InstanceNormalizationLayer::Clone(Graph& graph) const |
| 30 | { |
| 31 | return CloneBase<InstanceNormalizationLayer>(graph, m_Param, GetName()); |
| 32 | } |
| 33 | |
Finn Williams | f24effa | 2020-07-03 10:12:03 +0100 | [diff] [blame] | 34 | void InstanceNormalizationLayer::ValidateTensorShapesFromInputs() |
Kevin May | ce5045a | 2019-10-02 14:07:47 +0100 | [diff] [blame] | 35 | { |
| 36 | VerifyLayerConnections(1, CHECK_LOCATION()); |
| 37 | |
Finn Williams | 87d0bda | 2020-07-03 10:12:03 +0100 | [diff] [blame] | 38 | const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape(); |
| 39 | |
Finn Williams | f24effa | 2020-07-03 10:12:03 +0100 | [diff] [blame] | 40 | VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod); |
Finn Williams | 87d0bda | 2020-07-03 10:12:03 +0100 | [diff] [blame] | 41 | |
Mike Kelly | a9ac6ba | 2023-06-30 15:18:26 +0100 | [diff] [blame] | 42 | auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); |
Kevin May | ce5045a | 2019-10-02 14:07:47 +0100 | [diff] [blame] | 43 | |
Declan-ARM | 7c75e33 | 2024-03-12 16:40:25 +0000 | [diff] [blame^] | 44 | 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 May | ce5045a | 2019-10-02 14:07:47 +0100 | [diff] [blame] | 50 | |
Finn Williams | f24effa | 2020-07-03 10:12:03 +0100 | [diff] [blame] | 51 | ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "InstanceNormalizationLayer"); |
Kevin May | ce5045a | 2019-10-02 14:07:47 +0100 | [diff] [blame] | 52 | } |
| 53 | |
Nikhil Raj | 4d2eec0 | 2022-05-30 11:08:52 +0100 | [diff] [blame] | 54 | void InstanceNormalizationLayer::ExecuteStrategy(IStrategy& strategy) const |
Kevin May | ce5045a | 2019-10-02 14:07:47 +0100 | [diff] [blame] | 55 | { |
Nikhil Raj | 4d2eec0 | 2022-05-30 11:08:52 +0100 | [diff] [blame] | 56 | strategy.ExecuteStrategy(this, GetParameters(), {}, GetName()); |
Kevin May | ce5045a | 2019-10-02 14:07:47 +0100 | [diff] [blame] | 57 | } |
Kevin May | ce5045a | 2019-10-02 14:07:47 +0100 | [diff] [blame] | 58 | |
| 59 | } // namespace armnn |