telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | |
arovir01 | 9e53a35 | 2018-08-31 15:26:35 +0100 | [diff] [blame] | 6 | #include "NeonNormalizationFloatWorkload.hpp" |
Matthew Bentham | d80a712 | 2019-01-08 17:52:37 +0000 | [diff] [blame] | 7 | |
| 8 | #include "NeonWorkloadUtils.hpp" |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 9 | #include <aclCommon/ArmComputeUtils.hpp> |
| 10 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 11 | #include <armnn/utility/PolymorphicDowncast.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 12 | |
Matthew Bentham | d80a712 | 2019-01-08 17:52:37 +0000 | [diff] [blame] | 13 | #include <arm_compute/runtime/NEON/functions/NENormalizationLayer.h> |
| 14 | |
narpra01 | 33cea4d | 2018-09-27 16:46:14 +0100 | [diff] [blame] | 15 | using namespace armnn::armcomputetensorutils; |
| 16 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 17 | namespace armnn |
| 18 | { |
| 19 | |
Aron Virginas-Tar | fc82431 | 2018-10-15 15:00:13 +0100 | [diff] [blame] | 20 | namespace |
| 21 | { |
Keith Davis | 2d0679f | 2021-08-05 11:35:00 +0100 | [diff] [blame] | 22 | using ACLMemManagerOnDemand = std::shared_ptr<arm_compute::MemoryManagerOnDemand>; |
Aron Virginas-Tar | fc82431 | 2018-10-15 15:00:13 +0100 | [diff] [blame] | 23 | |
| 24 | bool IsNeonNormalizationDescriptorSupported(const NormalizationDescriptor& parameters, |
| 25 | Optional<std::string&> reasonIfUnsupported) |
| 26 | { |
| 27 | if (parameters.m_NormMethodType != NormalizationAlgorithmMethod::LocalBrightness) |
| 28 | { |
| 29 | if (reasonIfUnsupported) |
| 30 | { |
| 31 | reasonIfUnsupported.value() = "Unsupported normalisation method type, only LocalBrightness is supported"; |
| 32 | } |
| 33 | return false; |
| 34 | } |
| 35 | if (parameters.m_NormSize % 2 == 0) |
| 36 | { |
| 37 | if (reasonIfUnsupported) |
| 38 | { |
| 39 | reasonIfUnsupported.value() = "Normalization size must be an odd number."; |
| 40 | } |
| 41 | return false; |
| 42 | } |
| 43 | |
| 44 | return true; |
| 45 | } |
| 46 | |
| 47 | } // anonymous namespace |
| 48 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 49 | arm_compute::Status NeonNormalizationWorkloadValidate(const TensorInfo& input, |
| 50 | const TensorInfo& output, |
| 51 | const NormalizationDescriptor& descriptor) |
| 52 | { |
narpra01 | 33cea4d | 2018-09-27 16:46:14 +0100 | [diff] [blame] | 53 | const arm_compute::TensorInfo aclInput = BuildArmComputeTensorInfo(input, descriptor.m_DataLayout); |
| 54 | const arm_compute::TensorInfo aclOutput = BuildArmComputeTensorInfo(output, descriptor.m_DataLayout); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 55 | |
narpra01 | 33cea4d | 2018-09-27 16:46:14 +0100 | [diff] [blame] | 56 | arm_compute::NormalizationLayerInfo normalizationInfo = BuildArmComputeNormalizationLayerInfo(descriptor); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 57 | |
| 58 | return arm_compute::NENormalizationLayer::validate(&aclInput, &aclOutput, normalizationInfo); |
| 59 | } |
| 60 | |
arovir01 | 9e53a35 | 2018-08-31 15:26:35 +0100 | [diff] [blame] | 61 | NeonNormalizationFloatWorkload::NeonNormalizationFloatWorkload(const NormalizationQueueDescriptor& descriptor, |
Keith Davis | 2d0679f | 2021-08-05 11:35:00 +0100 | [diff] [blame] | 62 | const WorkloadInfo& info, |
| 63 | ACLMemManagerOnDemand& memoryManager) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 64 | : FloatWorkload<NormalizationQueueDescriptor>(descriptor, info) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 65 | { |
Keith Davis | 2d0679f | 2021-08-05 11:35:00 +0100 | [diff] [blame] | 66 | // Report Profiling Details |
| 67 | ARMNN_REPORT_PROFILING_WORKLOAD_DESC("NeonNormalizationWorkload_Construct", |
| 68 | descriptor.m_Parameters, |
| 69 | info, |
| 70 | this->GetGuid()); |
| 71 | |
arovir01 | 9e53a35 | 2018-08-31 15:26:35 +0100 | [diff] [blame] | 72 | m_Data.ValidateInputsOutputs("NeonNormalizationFloatWorkload", 1, 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 73 | std::string reasonIfUnsupported; |
Aron Virginas-Tar | fc82431 | 2018-10-15 15:00:13 +0100 | [diff] [blame] | 74 | if (!IsNeonNormalizationDescriptorSupported(m_Data.m_Parameters, Optional<std::string&>(reasonIfUnsupported))) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 75 | { |
| 76 | throw UnimplementedException(reasonIfUnsupported); |
| 77 | } |
| 78 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 79 | // Input and output tensors have to have the same dimensionality. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 80 | if (info.m_InputTensorInfos[0].GetShape()[1] != info.m_OutputTensorInfos[0].GetShape()[1] |
| 81 | || info.m_InputTensorInfos[0].GetShape()[0] != info.m_OutputTensorInfos[0].GetShape()[0] |
| 82 | || info.m_InputTensorInfos[0].GetShape()[3] != info.m_OutputTensorInfos[0].GetShape()[3] |
| 83 | || info.m_InputTensorInfos[0].GetShape()[2] != info.m_OutputTensorInfos[0].GetShape()[2]) |
| 84 | { |
| 85 | throw InvalidArgumentException("Normalization requires input and output tensors to have equal dimensionality."); |
| 86 | } |
| 87 | |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 88 | arm_compute::ITensor& input = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); |
| 89 | arm_compute::ITensor& output = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor(); |
narpra01 | 55a97bc | 2018-10-02 14:35:53 +0100 | [diff] [blame] | 90 | arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout); |
| 91 | input.info()->set_data_layout(aclDataLayout); |
| 92 | output.info()->set_data_layout(aclDataLayout); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 93 | |
| 94 | const arm_compute::NormType normType = |
| 95 | ConvertNormalizationAlgorithmChannelToAclNormType(m_Data.m_Parameters.m_NormChannelType); |
| 96 | arm_compute::NormalizationLayerInfo normalizationInfo(normType, |
| 97 | m_Data.m_Parameters.m_NormSize, |
| 98 | m_Data.m_Parameters.m_Alpha, |
| 99 | m_Data.m_Parameters.m_Beta, |
| 100 | m_Data.m_Parameters.m_K, |
| 101 | false); |
Matthew Bentham | d80a712 | 2019-01-08 17:52:37 +0000 | [diff] [blame] | 102 | auto layer = std::make_unique<arm_compute::NENormalizationLayer>(memoryManager); |
| 103 | layer->configure(&input, &output, normalizationInfo); |
| 104 | m_NormalizationLayer.reset(layer.release()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 105 | } |
| 106 | |
arovir01 | 9e53a35 | 2018-08-31 15:26:35 +0100 | [diff] [blame] | 107 | void NeonNormalizationFloatWorkload::Execute() const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 108 | { |
Keith Davis | 2d0679f | 2021-08-05 11:35:00 +0100 | [diff] [blame] | 109 | ARMNN_SCOPED_PROFILING_EVENT_NEON_GUID("NeonNormalizationFloatWorkload_Execute", this->GetGuid()); |
Matthew Bentham | d80a712 | 2019-01-08 17:52:37 +0000 | [diff] [blame] | 110 | m_NormalizationLayer->run(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | } //namespace armnn |