blob: c595e20a1f53ed8ef0f691fb1e1d9ae07ede33f4 [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5
arovir019e53a352018-08-31 15:26:35 +01006#include "ClBatchNormalizationFloatWorkload.hpp"
Matthew Bentham14e46692018-09-20 15:35:30 +01007#include "ClWorkloadUtils.hpp"
8
Mike Kelly07810fc2020-11-12 10:58:48 +00009#include <aclCommon/ArmComputeTensorUtils.hpp>
10#include <aclCommon/ArmComputeUtils.hpp>
Mike Kelly0d4ed392020-11-13 15:26:41 +000011#include <backendsCommon/CpuTensorHandle.hpp>
Mike Kelly07810fc2020-11-12 10:58:48 +000012#include <cl/ClLayerSupport.hpp>
Mike Kelly0d4ed392020-11-13 15:26:41 +000013#include <cl/ClTensorHandle.hpp>
Mike Kelly07810fc2020-11-12 10:58:48 +000014
telsoa014fcda012018-03-09 14:13:49 +000015namespace armnn
16{
17using namespace armcomputetensorutils;
18
telsoa01c577f2c2018-08-31 09:22:23 +010019arm_compute::Status ClBatchNormalizationValidate(const TensorInfo& input,
20 const TensorInfo& output,
21 const TensorInfo& mean,
22 const TensorInfo& var,
23 const TensorInfo& beta,
24 const TensorInfo& gamma,
Mike Kelly07810fc2020-11-12 10:58:48 +000025 const BatchNormalizationDescriptor& desc,
26 const ActivationDescriptor* activationDescriptor)
telsoa01c577f2c2018-08-31 09:22:23 +010027{
Nikhil Rajd1340932018-10-18 14:27:50 +010028 const arm_compute::TensorInfo aclInputInfo =
Matthew Bentham8800c002018-11-19 13:19:28 +000029 armcomputetensorutils::BuildArmComputeTensorInfo(input, desc.m_DataLayout);
Nikhil Rajd1340932018-10-18 14:27:50 +010030 const arm_compute::TensorInfo aclOutputInfo =
Matthew Bentham8800c002018-11-19 13:19:28 +000031 armcomputetensorutils::BuildArmComputeTensorInfo(output, desc.m_DataLayout);
Nikhil Rajd1340932018-10-18 14:27:50 +010032 const arm_compute::TensorInfo aclMeanInfo =
Matthew Bentham8800c002018-11-19 13:19:28 +000033 armcomputetensorutils::BuildArmComputeTensorInfo(mean, desc.m_DataLayout);
Nikhil Rajd1340932018-10-18 14:27:50 +010034 const arm_compute::TensorInfo aclVarInfo =
Matthew Bentham8800c002018-11-19 13:19:28 +000035 armcomputetensorutils::BuildArmComputeTensorInfo(var, desc.m_DataLayout);
Nikhil Rajd1340932018-10-18 14:27:50 +010036 const arm_compute::TensorInfo aclBetaInfo =
Matthew Bentham8800c002018-11-19 13:19:28 +000037 armcomputetensorutils::BuildArmComputeTensorInfo(beta, desc.m_DataLayout);
Nikhil Rajd1340932018-10-18 14:27:50 +010038 const arm_compute::TensorInfo aclGammaInfo =
Matthew Bentham8800c002018-11-19 13:19:28 +000039 armcomputetensorutils::BuildArmComputeTensorInfo(gamma, desc.m_DataLayout);
telsoa01c577f2c2018-08-31 09:22:23 +010040
Mike Kelly07810fc2020-11-12 10:58:48 +000041 const arm_compute::ActivationLayerInfo activationInfo = ConvertActivationDescriptorToAclActivationLayerInfo(
42 activationDescriptor);
43
telsoa01c577f2c2018-08-31 09:22:23 +010044 return arm_compute::CLBatchNormalizationLayer::validate(&aclInputInfo,
45 &aclOutputInfo,
46 &aclMeanInfo,
47 &aclVarInfo,
48 &aclBetaInfo,
49 &aclGammaInfo,
Mike Kelly07810fc2020-11-12 10:58:48 +000050 desc.m_Eps,
51 activationInfo);
telsoa01c577f2c2018-08-31 09:22:23 +010052}
53
arovir019e53a352018-08-31 15:26:35 +010054ClBatchNormalizationFloatWorkload::ClBatchNormalizationFloatWorkload(
telsoa014fcda012018-03-09 14:13:49 +000055 const BatchNormalizationQueueDescriptor& descriptor, const WorkloadInfo& info)
telsoa01c577f2c2018-08-31 09:22:23 +010056 : FloatWorkload<BatchNormalizationQueueDescriptor>(descriptor, info)
telsoa014fcda012018-03-09 14:13:49 +000057{
telsoa01c577f2c2018-08-31 09:22:23 +010058 m_Mean = std::make_unique<arm_compute::CLTensor>();
59 BuildArmComputeTensor(*m_Mean, m_Data.m_Mean->GetTensorInfo());
60
61 m_Variance = std::make_unique<arm_compute::CLTensor>();
62 BuildArmComputeTensor(*m_Variance, m_Data.m_Variance->GetTensorInfo());
63
64 m_Gamma = std::make_unique<arm_compute::CLTensor>();
65 BuildArmComputeTensor(*m_Gamma, m_Data.m_Gamma->GetTensorInfo());
66
67 m_Beta = std::make_unique<arm_compute::CLTensor>();
68 BuildArmComputeTensor(*m_Beta, m_Data.m_Beta->GetTensorInfo());
telsoa014fcda012018-03-09 14:13:49 +000069
arovir019e53a352018-08-31 15:26:35 +010070 m_Data.ValidateInputsOutputs("ClBatchNormalizationFloatWorkload", 1, 1);
telsoa014fcda012018-03-09 14:13:49 +000071
72 arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
73 arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
telsoa014fcda012018-03-09 14:13:49 +000074
Matthew Bentham8800c002018-11-19 13:19:28 +000075 arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout);
Nikhil Rajd1340932018-10-18 14:27:50 +010076 input.info()->set_data_layout(aclDataLayout);
77 output.info()->set_data_layout(aclDataLayout);
78
Mike Kelly07810fc2020-11-12 10:58:48 +000079 const arm_compute::ActivationLayerInfo activationInfo = ConvertAdditionalInfoToAclActivationLayerInfo(descriptor);
80
telsoa01c577f2c2018-08-31 09:22:23 +010081 m_Layer.configure(&input,
82 &output,
83 m_Mean.get(),
84 m_Variance.get(),
85 m_Beta.get(),
86 m_Gamma.get(),
Mike Kelly07810fc2020-11-12 10:58:48 +000087 m_Data.m_Parameters.m_Eps,
88 activationInfo);
telsoa01c577f2c2018-08-31 09:22:23 +010089
Matthew Bentham785df502018-09-21 10:29:58 +010090 InitializeArmComputeClTensorData(*m_Mean, m_Data.m_Mean);
91 InitializeArmComputeClTensorData(*m_Variance, m_Data.m_Variance);
92 InitializeArmComputeClTensorData(*m_Beta, m_Data.m_Beta);
93 InitializeArmComputeClTensorData(*m_Gamma, m_Data.m_Gamma);
telsoa01c577f2c2018-08-31 09:22:23 +010094
95 // Force Compute Library to perform the necessary copying and reshaping, after which
96 // delete all the input tensors that will no longer be needed
97 m_Layer.prepare();
98 FreeUnusedTensors();
telsoa014fcda012018-03-09 14:13:49 +000099}
100
arovir019e53a352018-08-31 15:26:35 +0100101void ClBatchNormalizationFloatWorkload::Execute() const
telsoa014fcda012018-03-09 14:13:49 +0000102{
arovir019e53a352018-08-31 15:26:35 +0100103 ARMNN_SCOPED_PROFILING_EVENT_CL("ClBatchNormalizationFloatWorkload_Execute");
Aron Virginas-Tara8e06ed2018-10-19 16:46:15 +0100104 RunClFunction(m_Layer, CHECK_LOCATION());
telsoa014fcda012018-03-09 14:13:49 +0000105}
106
arovir019e53a352018-08-31 15:26:35 +0100107void ClBatchNormalizationFloatWorkload::FreeUnusedTensors()
telsoa01c577f2c2018-08-31 09:22:23 +0100108{
109 FreeTensorIfUnused(m_Mean);
110 FreeTensorIfUnused(m_Variance);
111 FreeTensorIfUnused(m_Gamma);
112 FreeTensorIfUnused(m_Beta);
113}
114
Matthew Bentham14e46692018-09-20 15:35:30 +0100115} //namespace armnn