2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
6 #include "NeonBatchNormalizationFloatWorkload.hpp"
7 #include <backends/CpuTensorHandle.hpp>
8 #include <backends/aclCommon/ArmComputeTensorUtils.hpp>
9 #include <armnn/ArmNN.hpp>
13 using namespace armcomputetensorutils;
16 arm_compute::Status NeonBatchNormalizationValidate(const TensorInfo& input,
17 const TensorInfo& output,
18 const TensorInfo& mean,
19 const TensorInfo& var,
20 const TensorInfo& beta,
21 const TensorInfo& gamma,
22 const BatchNormalizationDescriptor& descriptor)
24 const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input);
25 const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output);
26 const arm_compute::TensorInfo aclMeanInfo = BuildArmComputeTensorInfo(mean);
27 const arm_compute::TensorInfo aclVarInfo = BuildArmComputeTensorInfo(var);
28 const arm_compute::TensorInfo aclBetaInfo = BuildArmComputeTensorInfo(beta);
29 const arm_compute::TensorInfo aclGammaInfo = BuildArmComputeTensorInfo(gamma);
31 return arm_compute::NEBatchNormalizationLayer::validate(&aclInputInfo,
40 NeonBatchNormalizationFloatWorkload::NeonBatchNormalizationFloatWorkload(
41 const BatchNormalizationQueueDescriptor& descriptor, const WorkloadInfo& info)
42 : FloatWorkload<BatchNormalizationQueueDescriptor>(descriptor, info)
44 m_Data.ValidateInputsOutputs("NeonBatchNormalizationFloatWorkload", 1, 1);
46 arm_compute::ITensor& input = boost::polymorphic_downcast<INeonTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
47 arm_compute::ITensor& output = boost::polymorphic_downcast<INeonTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
49 m_Mean = std::make_unique<arm_compute::Tensor>();
50 BuildArmComputeTensor(*m_Mean, m_Data.m_Mean->GetTensorInfo());
52 m_Variance = std::make_unique<arm_compute::Tensor>();
53 BuildArmComputeTensor(*m_Variance, m_Data.m_Variance->GetTensorInfo());
55 m_Gamma = std::make_unique<arm_compute::Tensor>();
56 BuildArmComputeTensor(*m_Gamma, m_Data.m_Gamma->GetTensorInfo());
58 m_Beta = std::make_unique<arm_compute::Tensor>();
59 BuildArmComputeTensor(*m_Beta, m_Data.m_Beta->GetTensorInfo());
61 m_Layer.configure(&input,
67 m_Data.m_Parameters.m_Eps);
69 InitializeArmComputeTensorData(*m_Mean, m_Data.m_Mean);
70 InitializeArmComputeTensorData(*m_Variance, m_Data.m_Variance);
71 InitializeArmComputeTensorData(*m_Gamma, m_Data.m_Gamma);
72 InitializeArmComputeTensorData(*m_Beta, m_Data.m_Beta);
74 // Force Compute Library to perform the necessary copying and reshaping, after which
75 // delete all the input tensors that will no longer be needed
80 void NeonBatchNormalizationFloatWorkload::Execute() const
82 ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonBatchNormalizationFloatWorkload_Execute");
86 void NeonBatchNormalizationFloatWorkload::FreeUnusedTensors()
88 FreeTensorIfUnused(m_Mean);
89 FreeTensorIfUnused(m_Variance);
90 FreeTensorIfUnused(m_Gamma);
91 FreeTensorIfUnused(m_Beta);