blob: 356df9a47091ebd08889a09857d29a0a90ac6ce9 [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
Mike Kelly7cbe7812023-07-25 17:37:33 +01002// Copyright © 2017-2023 Arm Ltd and Contributors. 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 "ClL2NormalizationFloatWorkload.hpp"
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +00007#include <cl/ClTensorHandle.hpp>
Colm Donelan0c479742021-12-10 12:43:54 +00008#include <armnn/backends/TensorHandle.hpp>
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +00009#include <aclCommon/ArmComputeUtils.hpp>
telsoa014fcda012018-03-09 14:13:49 +000010
Matthew Bentham14e46692018-09-20 15:35:30 +010011#include "ClWorkloadUtils.hpp"
12
telsoa014fcda012018-03-09 14:13:49 +000013namespace armnn
14{
15using namespace armcomputetensorutils;
16
telsoa01c577f2c2018-08-31 09:22:23 +010017arm_compute::Status ClL2NormalizationWorkloadValidate(const TensorInfo& input,
Matteo Martincighbcd3c852018-09-28 14:14:12 +010018 const TensorInfo& output,
19 const L2NormalizationDescriptor& descriptor)
telsoa01c577f2c2018-08-31 09:22:23 +010020{
Matthew Bentham8800c002018-11-19 13:19:28 +000021 const arm_compute::TensorInfo aclInput = BuildArmComputeTensorInfo(input, descriptor.m_DataLayout);
22 const arm_compute::TensorInfo aclOutput = BuildArmComputeTensorInfo(output, descriptor.m_DataLayout);
telsoa01c577f2c2018-08-31 09:22:23 +010023
Matteo Martincigh550fe362019-06-03 09:33:55 +010024 int axis = (descriptor.m_DataLayout == DataLayout::NCHW) ? 2 : 0;
telsoa01c577f2c2018-08-31 09:22:23 +010025
Ferran Balaguer05bf0542019-06-18 16:46:00 +010026 return arm_compute::CLL2NormalizeLayer::validate(&aclInput, &aclOutput, axis, descriptor.m_Eps);
telsoa01c577f2c2018-08-31 09:22:23 +010027}
28
arovir019e53a352018-08-31 15:26:35 +010029ClL2NormalizationFloatWorkload::ClL2NormalizationFloatWorkload(const L2NormalizationQueueDescriptor& descriptor,
Sadik Armagane9444752020-12-02 11:28:58 +000030 const WorkloadInfo& info,
31 const arm_compute::CLCompileContext& clCompileContext)
telsoa01c577f2c2018-08-31 09:22:23 +010032 : FloatWorkload<L2NormalizationQueueDescriptor>(descriptor, info)
telsoa014fcda012018-03-09 14:13:49 +000033{
Keith Davisbcd860a2021-08-05 14:20:33 +010034 // Report Profiling Details
35 ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClL2NormalizationFloatWorkload_Construct",
36 descriptor.m_Parameters,
37 info,
38 this->GetGuid());
39
arovir019e53a352018-08-31 15:26:35 +010040 m_Data.ValidateInputsOutputs("ClL2NormalizationFloatWorkload", 1, 1);
telsoa014fcda012018-03-09 14:13:49 +000041
42 arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
43 arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
Matteo Martincigh539b44d2018-10-01 09:26:39 +010044
Matthew Bentham8800c002018-11-19 13:19:28 +000045 arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout);
Matteo Martincigh539b44d2018-10-01 09:26:39 +010046 input.info()->set_data_layout(aclDataLayout);
47 output.info()->set_data_layout(aclDataLayout);
48
Matteo Martincigh550fe362019-06-03 09:33:55 +010049 int axis = (m_Data.m_Parameters.m_DataLayout == DataLayout::NCHW) ? 2 : 0;
FrancisMurtagh81f22322018-11-16 12:26:20 +000050
Kevin May9f6862d2021-10-22 15:42:28 +010051 {
Mike Kelly7cbe7812023-07-25 17:37:33 +010052 ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClL2NormalizationFloatWorkload_configure");
Kevin May9f6862d2021-10-22 15:42:28 +010053 m_Layer.configure(clCompileContext, &input, &output, axis, m_Data.m_Parameters.m_Eps);
54 }
telsoa014fcda012018-03-09 14:13:49 +000055}
56
arovir019e53a352018-08-31 15:26:35 +010057void ClL2NormalizationFloatWorkload::Execute() const
telsoa014fcda012018-03-09 14:13:49 +000058{
Mike Kelly7cbe7812023-07-25 17:37:33 +010059 ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClL2NormalizationFloatWorkload_Execute");
Aron Virginas-Tara8e06ed2018-10-19 16:46:15 +010060 RunClFunction(m_Layer, CHECK_LOCATION());
telsoa014fcda012018-03-09 14:13:49 +000061}
62
David Monahanec819992022-02-10 14:47:13 +000063void ClL2NormalizationFloatWorkload::ReplaceInputTensorHandle(ITensorHandle* tensorHandle, unsigned int slot)
64{
65 ITensorHandle* backupHandle = this->m_Data.m_Inputs[slot];
66 this->m_Data.m_Inputs[slot] = tensorHandle;
67 try
68 {
69 Reconfigure();
70 }
71 catch(armnn::UnimplementedException& e)
72 {
73 // Cannot reconfigure, revert the slot back and throw the exception.
74 this->m_Data.m_Inputs[slot] = backupHandle;
75 throw e;
76 }
77}
78
79// Replace output tensor handle with the given TensorHandle
80void ClL2NormalizationFloatWorkload::ReplaceOutputTensorHandle(ITensorHandle* tensorHandle, unsigned int slot)
81{
82 ITensorHandle* backupHandle = this->m_Data.m_Inputs[slot];
83 this->m_Data.m_Inputs[slot] = tensorHandle;
84 try
85 {
86 Reconfigure();
87 }
88 catch(armnn::UnimplementedException& e)
89 {
90 // Cannot reconfigure, revert the slot back and throw the exception.
91 this->m_Data.m_Inputs[slot] = backupHandle;
92 throw e;
93 }
94}
95
96void ClL2NormalizationFloatWorkload::Reconfigure()
97{
98 throw armnn::UnimplementedException("Reconfigure not implemented for this workload");
99}
100
telsoa014fcda012018-03-09 14:13:49 +0000101} //namespace armnn