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 "ClBatchNormalizationFloatWorkload.hpp" |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 7 | #include <backends/cl/ClTensorHandle.hpp> |
David Beck | 711fa31 | 2018-09-24 10:46:38 +0100 | [diff] [blame] | 8 | #include <backends/CpuTensorHandle.hpp> |
| 9 | #include <backends/aclCommon/ArmComputeTensorUtils.hpp> |
David Beck | ac42efd | 2018-09-26 17:41:13 +0100 | [diff] [blame] | 10 | #include <backends/cl/ClLayerSupport.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 11 | |
Matthew Bentham | 14e4669 | 2018-09-20 15:35:30 +0100 | [diff] [blame] | 12 | #include "ClWorkloadUtils.hpp" |
| 13 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 14 | namespace armnn |
| 15 | { |
| 16 | using namespace armcomputetensorutils; |
| 17 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 18 | arm_compute::Status ClBatchNormalizationValidate(const TensorInfo& input, |
| 19 | const TensorInfo& output, |
| 20 | const TensorInfo& mean, |
| 21 | const TensorInfo& var, |
| 22 | const TensorInfo& beta, |
| 23 | const TensorInfo& gamma, |
| 24 | const BatchNormalizationDescriptor &desc) |
| 25 | { |
Nikhil Raj | d134093 | 2018-10-18 14:27:50 +0100 | [diff] [blame] | 26 | const DataLayout dataLayout = desc.m_DataLayout.GetDataLayout(); |
| 27 | |
| 28 | const arm_compute::TensorInfo aclInputInfo = |
| 29 | armcomputetensorutils::BuildArmComputeTensorInfo(input, dataLayout); |
| 30 | const arm_compute::TensorInfo aclOutputInfo = |
| 31 | armcomputetensorutils::BuildArmComputeTensorInfo(output, dataLayout); |
| 32 | const arm_compute::TensorInfo aclMeanInfo = |
| 33 | armcomputetensorutils::BuildArmComputeTensorInfo(mean, dataLayout); |
| 34 | const arm_compute::TensorInfo aclVarInfo = |
| 35 | armcomputetensorutils::BuildArmComputeTensorInfo(var, dataLayout); |
| 36 | const arm_compute::TensorInfo aclBetaInfo = |
| 37 | armcomputetensorutils::BuildArmComputeTensorInfo(beta, dataLayout); |
| 38 | const arm_compute::TensorInfo aclGammaInfo = |
| 39 | armcomputetensorutils::BuildArmComputeTensorInfo(gamma, dataLayout); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 40 | |
| 41 | return arm_compute::CLBatchNormalizationLayer::validate(&aclInputInfo, |
| 42 | &aclOutputInfo, |
| 43 | &aclMeanInfo, |
| 44 | &aclVarInfo, |
| 45 | &aclBetaInfo, |
| 46 | &aclGammaInfo, |
| 47 | desc.m_Eps); |
| 48 | } |
| 49 | |
arovir01 | 9e53a35 | 2018-08-31 15:26:35 +0100 | [diff] [blame] | 50 | ClBatchNormalizationFloatWorkload::ClBatchNormalizationFloatWorkload( |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 51 | const BatchNormalizationQueueDescriptor& descriptor, const WorkloadInfo& info) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 52 | : FloatWorkload<BatchNormalizationQueueDescriptor>(descriptor, info) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 53 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 54 | m_Mean = std::make_unique<arm_compute::CLTensor>(); |
| 55 | BuildArmComputeTensor(*m_Mean, m_Data.m_Mean->GetTensorInfo()); |
| 56 | |
| 57 | m_Variance = std::make_unique<arm_compute::CLTensor>(); |
| 58 | BuildArmComputeTensor(*m_Variance, m_Data.m_Variance->GetTensorInfo()); |
| 59 | |
| 60 | m_Gamma = std::make_unique<arm_compute::CLTensor>(); |
| 61 | BuildArmComputeTensor(*m_Gamma, m_Data.m_Gamma->GetTensorInfo()); |
| 62 | |
| 63 | m_Beta = std::make_unique<arm_compute::CLTensor>(); |
| 64 | BuildArmComputeTensor(*m_Beta, m_Data.m_Beta->GetTensorInfo()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 65 | |
arovir01 | 9e53a35 | 2018-08-31 15:26:35 +0100 | [diff] [blame] | 66 | m_Data.ValidateInputsOutputs("ClBatchNormalizationFloatWorkload", 1, 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 67 | |
| 68 | arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); |
| 69 | arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 70 | |
Nikhil Raj | d134093 | 2018-10-18 14:27:50 +0100 | [diff] [blame] | 71 | arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout.GetDataLayout()); |
| 72 | input.info()->set_data_layout(aclDataLayout); |
| 73 | output.info()->set_data_layout(aclDataLayout); |
| 74 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 75 | m_Layer.configure(&input, |
| 76 | &output, |
| 77 | m_Mean.get(), |
| 78 | m_Variance.get(), |
| 79 | m_Beta.get(), |
| 80 | m_Gamma.get(), |
| 81 | m_Data.m_Parameters.m_Eps); |
| 82 | |
Matthew Bentham | 785df50 | 2018-09-21 10:29:58 +0100 | [diff] [blame] | 83 | InitializeArmComputeClTensorData(*m_Mean, m_Data.m_Mean); |
| 84 | InitializeArmComputeClTensorData(*m_Variance, m_Data.m_Variance); |
| 85 | InitializeArmComputeClTensorData(*m_Beta, m_Data.m_Beta); |
| 86 | InitializeArmComputeClTensorData(*m_Gamma, m_Data.m_Gamma); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 87 | |
| 88 | // Force Compute Library to perform the necessary copying and reshaping, after which |
| 89 | // delete all the input tensors that will no longer be needed |
| 90 | m_Layer.prepare(); |
| 91 | FreeUnusedTensors(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 92 | } |
| 93 | |
arovir01 | 9e53a35 | 2018-08-31 15:26:35 +0100 | [diff] [blame] | 94 | void ClBatchNormalizationFloatWorkload::Execute() const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 95 | { |
arovir01 | 9e53a35 | 2018-08-31 15:26:35 +0100 | [diff] [blame] | 96 | ARMNN_SCOPED_PROFILING_EVENT_CL("ClBatchNormalizationFloatWorkload_Execute"); |
Aron Virginas-Tar | a8e06ed | 2018-10-19 16:46:15 +0100 | [diff] [blame] | 97 | RunClFunction(m_Layer, CHECK_LOCATION()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 98 | } |
| 99 | |
arovir01 | 9e53a35 | 2018-08-31 15:26:35 +0100 | [diff] [blame] | 100 | void ClBatchNormalizationFloatWorkload::FreeUnusedTensors() |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 101 | { |
| 102 | FreeTensorIfUnused(m_Mean); |
| 103 | FreeTensorIfUnused(m_Variance); |
| 104 | FreeTensorIfUnused(m_Gamma); |
| 105 | FreeTensorIfUnused(m_Beta); |
| 106 | } |
| 107 | |
Matthew Bentham | 14e4669 | 2018-09-20 15:35:30 +0100 | [diff] [blame] | 108 | } //namespace armnn |