2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
6 #include "NeonNormalizationFloatWorkload.hpp"
7 #include <backends/neon/NeonLayerSupport.hpp>
8 #include <backends/aclCommon/ArmComputeUtils.hpp>
9 #include <backends/aclCommon/ArmComputeTensorUtils.hpp>
11 using namespace armnn::armcomputetensorutils;
16 arm_compute::Status NeonNormalizationWorkloadValidate(const TensorInfo& input,
17 const TensorInfo& output,
18 const NormalizationDescriptor& descriptor)
20 const arm_compute::TensorInfo aclInput = BuildArmComputeTensorInfo(input, descriptor.m_DataLayout);
21 const arm_compute::TensorInfo aclOutput = BuildArmComputeTensorInfo(output, descriptor.m_DataLayout);
23 arm_compute::NormalizationLayerInfo normalizationInfo = BuildArmComputeNormalizationLayerInfo(descriptor);
25 return arm_compute::NENormalizationLayer::validate(&aclInput, &aclOutput, normalizationInfo);
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)
34 m_Data.ValidateInputsOutputs("NeonNormalizationFloatWorkload", 1, 1);
35 std::string reasonIfUnsupported;
36 if (!IsNeonNormalizationDescParamsSupported(&reasonIfUnsupported, m_Data.m_Parameters))
38 throw UnimplementedException(reasonIfUnsupported);
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])
47 throw InvalidArgumentException("Normalization requires input and output tensors to have equal dimensionality.");
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();
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,
62 m_NormalizationLayer.configure(&input, &output, normalizationInfo);
65 void NeonNormalizationFloatWorkload::Execute() const
67 ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonNormalizationFloatWorkload_Execute");
68 m_NormalizationLayer.run();