2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
6 #include "NeonNormalizationFloatWorkload.hpp"
7 #include <neon/NeonLayerSupport.hpp>
8 #include <aclCommon/ArmComputeUtils.hpp>
9 #include <aclCommon/ArmComputeTensorUtils.hpp>
11 using namespace armnn::armcomputetensorutils;
19 bool IsNeonNormalizationDescriptorSupported(const NormalizationDescriptor& parameters,
20 Optional<std::string&> reasonIfUnsupported)
22 if (parameters.m_NormMethodType != NormalizationAlgorithmMethod::LocalBrightness)
24 if (reasonIfUnsupported)
26 reasonIfUnsupported.value() = "Unsupported normalisation method type, only LocalBrightness is supported";
30 if (parameters.m_NormSize % 2 == 0)
32 if (reasonIfUnsupported)
34 reasonIfUnsupported.value() = "Normalization size must be an odd number.";
42 } // anonymous namespace
44 arm_compute::Status NeonNormalizationWorkloadValidate(const TensorInfo& input,
45 const TensorInfo& output,
46 const NormalizationDescriptor& descriptor)
48 const arm_compute::TensorInfo aclInput = BuildArmComputeTensorInfo(input, descriptor.m_DataLayout);
49 const arm_compute::TensorInfo aclOutput = BuildArmComputeTensorInfo(output, descriptor.m_DataLayout);
51 arm_compute::NormalizationLayerInfo normalizationInfo = BuildArmComputeNormalizationLayerInfo(descriptor);
53 return arm_compute::NENormalizationLayer::validate(&aclInput, &aclOutput, normalizationInfo);
56 NeonNormalizationFloatWorkload::NeonNormalizationFloatWorkload(const NormalizationQueueDescriptor& descriptor,
57 const WorkloadInfo& info,
58 std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager)
59 : FloatWorkload<NormalizationQueueDescriptor>(descriptor, info)
60 , m_NormalizationLayer(memoryManager)
62 m_Data.ValidateInputsOutputs("NeonNormalizationFloatWorkload", 1, 1);
63 std::string reasonIfUnsupported;
64 if (!IsNeonNormalizationDescriptorSupported(m_Data.m_Parameters, Optional<std::string&>(reasonIfUnsupported)))
66 throw UnimplementedException(reasonIfUnsupported);
69 // Input and output tensors have to have the same dimensionality.
70 if (info.m_InputTensorInfos[0].GetShape()[1] != info.m_OutputTensorInfos[0].GetShape()[1]
71 || info.m_InputTensorInfos[0].GetShape()[0] != info.m_OutputTensorInfos[0].GetShape()[0]
72 || info.m_InputTensorInfos[0].GetShape()[3] != info.m_OutputTensorInfos[0].GetShape()[3]
73 || info.m_InputTensorInfos[0].GetShape()[2] != info.m_OutputTensorInfos[0].GetShape()[2])
75 throw InvalidArgumentException("Normalization requires input and output tensors to have equal dimensionality.");
78 arm_compute::ITensor& input = boost::polymorphic_downcast<INeonTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
79 arm_compute::ITensor& output = boost::polymorphic_downcast<INeonTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
80 arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout);
81 input.info()->set_data_layout(aclDataLayout);
82 output.info()->set_data_layout(aclDataLayout);
84 const arm_compute::NormType normType =
85 ConvertNormalizationAlgorithmChannelToAclNormType(m_Data.m_Parameters.m_NormChannelType);
86 arm_compute::NormalizationLayerInfo normalizationInfo(normType,
87 m_Data.m_Parameters.m_NormSize,
88 m_Data.m_Parameters.m_Alpha,
89 m_Data.m_Parameters.m_Beta,
90 m_Data.m_Parameters.m_K,
93 m_NormalizationLayer.configure(&input, &output, normalizationInfo);
96 void NeonNormalizationFloatWorkload::Execute() const
98 ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonNormalizationFloatWorkload_Execute");
99 m_NormalizationLayer.run();