IVGCVSW-1919 - data layout parameter for Normalization
[platform/upstream/armnn.git] / src / backends / neon / workloads / NeonNormalizationFloatWorkload.cpp
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5
6 #include "NeonNormalizationFloatWorkload.hpp"
7 #include <backends/neon/NeonLayerSupport.hpp>
8 #include <backends/aclCommon/ArmComputeUtils.hpp>
9 #include <backends/aclCommon/ArmComputeTensorUtils.hpp>
10
11 using namespace armnn::armcomputetensorutils;
12
13 namespace armnn
14 {
15
16 arm_compute::Status NeonNormalizationWorkloadValidate(const TensorInfo& input,
17                                                       const TensorInfo& output,
18                                                       const NormalizationDescriptor& descriptor)
19 {
20     const arm_compute::TensorInfo aclInput = BuildArmComputeTensorInfo(input, descriptor.m_DataLayout);
21     const arm_compute::TensorInfo aclOutput = BuildArmComputeTensorInfo(output, descriptor.m_DataLayout);
22
23     arm_compute::NormalizationLayerInfo normalizationInfo = BuildArmComputeNormalizationLayerInfo(descriptor);
24
25     return arm_compute::NENormalizationLayer::validate(&aclInput, &aclOutput, normalizationInfo);
26 }
27
28 NeonNormalizationFloatWorkload::NeonNormalizationFloatWorkload(const NormalizationQueueDescriptor& descriptor,
29                                                    const WorkloadInfo& info,
30                                                    std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager)
31     : FloatWorkload<NormalizationQueueDescriptor>(descriptor, info)
32     , m_NormalizationLayer(memoryManager)
33 {
34     m_Data.ValidateInputsOutputs("NeonNormalizationFloatWorkload", 1, 1);
35     std::string reasonIfUnsupported;
36     if (!IsNeonNormalizationDescParamsSupported(&reasonIfUnsupported, m_Data.m_Parameters))
37     {
38         throw UnimplementedException(reasonIfUnsupported);
39     }
40
41     // Input and output tensors have to have the same dimensionality.
42     if (info.m_InputTensorInfos[0].GetShape()[1] != info.m_OutputTensorInfos[0].GetShape()[1]
43         || info.m_InputTensorInfos[0].GetShape()[0] != info.m_OutputTensorInfos[0].GetShape()[0]
44         || info.m_InputTensorInfos[0].GetShape()[3] != info.m_OutputTensorInfos[0].GetShape()[3]
45         || info.m_InputTensorInfos[0].GetShape()[2] != info.m_OutputTensorInfos[0].GetShape()[2])
46     {
47         throw InvalidArgumentException("Normalization requires input and output tensors to have equal dimensionality.");
48     }
49
50     arm_compute::ITensor& input = boost::polymorphic_downcast<INeonTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
51     arm_compute::ITensor& output = boost::polymorphic_downcast<INeonTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
52
53     const arm_compute::NormType normType =
54         ConvertNormalizationAlgorithmChannelToAclNormType(m_Data.m_Parameters.m_NormChannelType);
55     arm_compute::NormalizationLayerInfo normalizationInfo(normType,
56                                                           m_Data.m_Parameters.m_NormSize,
57                                                           m_Data.m_Parameters.m_Alpha,
58                                                           m_Data.m_Parameters.m_Beta,
59                                                           m_Data.m_Parameters.m_K,
60                                                           false);
61
62     m_NormalizationLayer.configure(&input, &output, normalizationInfo);
63 }
64
65 void NeonNormalizationFloatWorkload::Execute() const
66 {
67     ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonNormalizationFloatWorkload_Execute");
68     m_NormalizationLayer.run();
69 }
70
71 } //namespace armnn