blob: 68942e2a01bc012b3719455fa26dd5cae1280e51 [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 <cl/ClTensorHandle.hpp>
10
11#include <backendsCommon/CpuTensorHandle.hpp>
12
13#include <aclCommon/ArmComputeTensorUtils.hpp>
14#include <aclCommon/ArmComputeUtils.hpp>
15
16#include <cl/ClLayerSupport.hpp>
17
telsoa014fcda012018-03-09 14:13:49 +000018namespace armnn
19{
20using namespace armcomputetensorutils;
21
telsoa01c577f2c2018-08-31 09:22:23 +010022arm_compute::Status ClBatchNormalizationValidate(const TensorInfo& input,
23 const TensorInfo& output,
24 const TensorInfo& mean,
25 const TensorInfo& var,
26 const TensorInfo& beta,
27 const TensorInfo& gamma,
Mike Kelly07810fc2020-11-12 10:58:48 +000028 const BatchNormalizationDescriptor& desc,
29 const ActivationDescriptor* activationDescriptor)
telsoa01c577f2c2018-08-31 09:22:23 +010030{
Nikhil Rajd1340932018-10-18 14:27:50 +010031 const arm_compute::TensorInfo aclInputInfo =
Matthew Bentham8800c002018-11-19 13:19:28 +000032 armcomputetensorutils::BuildArmComputeTensorInfo(input, desc.m_DataLayout);
Nikhil Rajd1340932018-10-18 14:27:50 +010033 const arm_compute::TensorInfo aclOutputInfo =
Matthew Bentham8800c002018-11-19 13:19:28 +000034 armcomputetensorutils::BuildArmComputeTensorInfo(output, desc.m_DataLayout);
Nikhil Rajd1340932018-10-18 14:27:50 +010035 const arm_compute::TensorInfo aclMeanInfo =
Matthew Bentham8800c002018-11-19 13:19:28 +000036 armcomputetensorutils::BuildArmComputeTensorInfo(mean, desc.m_DataLayout);
Nikhil Rajd1340932018-10-18 14:27:50 +010037 const arm_compute::TensorInfo aclVarInfo =
Matthew Bentham8800c002018-11-19 13:19:28 +000038 armcomputetensorutils::BuildArmComputeTensorInfo(var, desc.m_DataLayout);
Nikhil Rajd1340932018-10-18 14:27:50 +010039 const arm_compute::TensorInfo aclBetaInfo =
Matthew Bentham8800c002018-11-19 13:19:28 +000040 armcomputetensorutils::BuildArmComputeTensorInfo(beta, desc.m_DataLayout);
Nikhil Rajd1340932018-10-18 14:27:50 +010041 const arm_compute::TensorInfo aclGammaInfo =
Matthew Bentham8800c002018-11-19 13:19:28 +000042 armcomputetensorutils::BuildArmComputeTensorInfo(gamma, desc.m_DataLayout);
telsoa01c577f2c2018-08-31 09:22:23 +010043
Mike Kelly07810fc2020-11-12 10:58:48 +000044 const arm_compute::ActivationLayerInfo activationInfo = ConvertActivationDescriptorToAclActivationLayerInfo(
45 activationDescriptor);
46
telsoa01c577f2c2018-08-31 09:22:23 +010047 return arm_compute::CLBatchNormalizationLayer::validate(&aclInputInfo,
48 &aclOutputInfo,
49 &aclMeanInfo,
50 &aclVarInfo,
51 &aclBetaInfo,
52 &aclGammaInfo,
Mike Kelly07810fc2020-11-12 10:58:48 +000053 desc.m_Eps,
54 activationInfo);
telsoa01c577f2c2018-08-31 09:22:23 +010055}
56
arovir019e53a352018-08-31 15:26:35 +010057ClBatchNormalizationFloatWorkload::ClBatchNormalizationFloatWorkload(
telsoa014fcda012018-03-09 14:13:49 +000058 const BatchNormalizationQueueDescriptor& descriptor, const WorkloadInfo& info)
telsoa01c577f2c2018-08-31 09:22:23 +010059 : FloatWorkload<BatchNormalizationQueueDescriptor>(descriptor, info)
telsoa014fcda012018-03-09 14:13:49 +000060{
telsoa01c577f2c2018-08-31 09:22:23 +010061 m_Mean = std::make_unique<arm_compute::CLTensor>();
62 BuildArmComputeTensor(*m_Mean, m_Data.m_Mean->GetTensorInfo());
63
64 m_Variance = std::make_unique<arm_compute::CLTensor>();
65 BuildArmComputeTensor(*m_Variance, m_Data.m_Variance->GetTensorInfo());
66
67 m_Gamma = std::make_unique<arm_compute::CLTensor>();
68 BuildArmComputeTensor(*m_Gamma, m_Data.m_Gamma->GetTensorInfo());
69
70 m_Beta = std::make_unique<arm_compute::CLTensor>();
71 BuildArmComputeTensor(*m_Beta, m_Data.m_Beta->GetTensorInfo());
telsoa014fcda012018-03-09 14:13:49 +000072
arovir019e53a352018-08-31 15:26:35 +010073 m_Data.ValidateInputsOutputs("ClBatchNormalizationFloatWorkload", 1, 1);
telsoa014fcda012018-03-09 14:13:49 +000074
75 arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
76 arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
telsoa014fcda012018-03-09 14:13:49 +000077
Matthew Bentham8800c002018-11-19 13:19:28 +000078 arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout);
Nikhil Rajd1340932018-10-18 14:27:50 +010079 input.info()->set_data_layout(aclDataLayout);
80 output.info()->set_data_layout(aclDataLayout);
81
Mike Kelly07810fc2020-11-12 10:58:48 +000082 const arm_compute::ActivationLayerInfo activationInfo = ConvertAdditionalInfoToAclActivationLayerInfo(descriptor);
83
telsoa01c577f2c2018-08-31 09:22:23 +010084 m_Layer.configure(&input,
85 &output,
86 m_Mean.get(),
87 m_Variance.get(),
88 m_Beta.get(),
89 m_Gamma.get(),
Mike Kelly07810fc2020-11-12 10:58:48 +000090 m_Data.m_Parameters.m_Eps,
91 activationInfo);
telsoa01c577f2c2018-08-31 09:22:23 +010092
Matthew Bentham785df502018-09-21 10:29:58 +010093 InitializeArmComputeClTensorData(*m_Mean, m_Data.m_Mean);
94 InitializeArmComputeClTensorData(*m_Variance, m_Data.m_Variance);
95 InitializeArmComputeClTensorData(*m_Beta, m_Data.m_Beta);
96 InitializeArmComputeClTensorData(*m_Gamma, m_Data.m_Gamma);
telsoa01c577f2c2018-08-31 09:22:23 +010097
98 // Force Compute Library to perform the necessary copying and reshaping, after which
99 // delete all the input tensors that will no longer be needed
100 m_Layer.prepare();
101 FreeUnusedTensors();
telsoa014fcda012018-03-09 14:13:49 +0000102}
103
arovir019e53a352018-08-31 15:26:35 +0100104void ClBatchNormalizationFloatWorkload::Execute() const
telsoa014fcda012018-03-09 14:13:49 +0000105{
arovir019e53a352018-08-31 15:26:35 +0100106 ARMNN_SCOPED_PROFILING_EVENT_CL("ClBatchNormalizationFloatWorkload_Execute");
Aron Virginas-Tara8e06ed2018-10-19 16:46:15 +0100107 RunClFunction(m_Layer, CHECK_LOCATION());
telsoa014fcda012018-03-09 14:13:49 +0000108}
109
arovir019e53a352018-08-31 15:26:35 +0100110void ClBatchNormalizationFloatWorkload::FreeUnusedTensors()
telsoa01c577f2c2018-08-31 09:22:23 +0100111{
112 FreeTensorIfUnused(m_Mean);
113 FreeTensorIfUnused(m_Variance);
114 FreeTensorIfUnused(m_Gamma);
115 FreeTensorIfUnused(m_Beta);
116}
117
Matthew Bentham14e46692018-09-20 15:35:30 +0100118} //namespace armnn