ArmNN
 24.08
ClNormalizationFloatWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017-2018,2020-2023 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 #include <cl/ClTensorHandle.hpp>
9 #include <cl/ClLayerSupport.hpp>
12 #include "ClWorkloadUtils.hpp"
13 
14 using namespace armnn::armcomputetensorutils;
15 
16 namespace armnn
17 {
18 
20  const TensorInfo& output,
21  const NormalizationDescriptor& descriptor)
22 {
23  const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input, descriptor.m_DataLayout);
24  const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output, descriptor.m_DataLayout);
25 
26  arm_compute::NormalizationLayerInfo layerInfo = BuildArmComputeNormalizationLayerInfo(descriptor);
27 
28  return arm_compute::CLNormalizationLayer::validate(&aclInputInfo, &aclOutputInfo, layerInfo);
29 }
30 
32  const WorkloadInfo& info,
33  const arm_compute::CLCompileContext& clCompileContext)
35 {
36  // Report Profiling Details
37  ARMNN_REPORT_PROFILING_WORKLOAD_DESC("ClNormalizationWorkload_Construct",
38  descriptor.m_Parameters,
39  info,
40  this->GetGuid());
41 
42  m_Data.ValidateInputsOutputs("ClNormalizationFloatWorkload", 1, 1);
43 
44  arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
45  arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
46 
47  arm_compute::DataLayout aclDataLayout = ConvertDataLayout(m_Data.m_Parameters.m_DataLayout);
48  input.info()->set_data_layout(aclDataLayout);
49  output.info()->set_data_layout(aclDataLayout);
50 
51  arm_compute::NormalizationLayerInfo normalizationInfo = BuildArmComputeNormalizationLayerInfo(m_Data.m_Parameters);
52 
53  {
54  ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClNormalizationFloatWorkload_configure");
55  m_NormalizationLayer.configure(clCompileContext, &input, &output, normalizationInfo);
56  }
57 };
58 
60 {
61  ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClNormalizationFloatWorkload_Execute");
62  RunClFunction(m_NormalizationLayer, CHECK_LOCATION());
63 }
64 
66 {
67  ITensorHandle* backupHandle = this->m_Data.m_Inputs[slot];
68  this->m_Data.m_Inputs[slot] = tensorHandle;
69  try
70  {
71  Reconfigure();
72  }
74  {
75  // Cannot reconfigure, revert the slot back and throw the exception.
76  this->m_Data.m_Inputs[slot] = backupHandle;
77  throw e;
78  }
79 }
80 
81 // Replace output tensor handle with the given TensorHandle
83 {
84  ITensorHandle* backupHandle = this->m_Data.m_Inputs[slot];
85  this->m_Data.m_Inputs[slot] = tensorHandle;
86  try
87  {
88  Reconfigure();
89  }
91  {
92  // Cannot reconfigure, revert the slot back and throw the exception.
93  this->m_Data.m_Inputs[slot] = backupHandle;
94  throw e;
95  }
96 }
97 
98 void ClNormalizationFloatWorkload::Reconfigure()
99 {
100  throw armnn::UnimplementedException("Reconfigure not implemented for this workload");
101 }
102 
103 } //namespace armnn
armnn::NormalizationQueueDescriptor
Definition: WorkloadData.hpp:252
armnn::DataLayout
DataLayout
Definition: Types.hpp:62
armnn::QueueDescriptor::ValidateInputsOutputs
void ValidateInputsOutputs(const std::string &descName, unsigned int numExpectedIn, unsigned int numExpectedOut) const
Definition: WorkloadData.cpp:447
armnn::ClNormalizationFloatWorkload::ReplaceInputTensorHandle
void ReplaceInputTensorHandle(ITensorHandle *tensorHandle, unsigned int slot) override
Definition: ClNormalizationFloatWorkload.cpp:65
armnn::TensorInfo
Definition: Tensor.hpp:152
ClNormalizationFloatWorkload.hpp
ClLayerSupport.hpp
armnn::NormalizationDescriptor
A NormalizationDescriptor for the NormalizationLayer.
Definition: Descriptors.hpp:769
CHECK_LOCATION
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
armnn::ITensorHandle
Definition: ITensorHandle.hpp:16
armnn::TypedWorkload
Definition: Workload.hpp:101
armnn::QueueDescriptorWithParameters::m_Parameters
LayerDescriptor m_Parameters
Definition: WorkloadData.hpp:66
ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID
#define ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID(label)
Creates a profiling event that uses GetGuid() and GetName() from the calling class.
Definition: ClWorkloadUtils.hpp:36
armnn::WorkloadInfo
Contains information about TensorInfos of a layer.
Definition: WorkloadInfo.hpp:16
ClWorkloadUtils.hpp
armnn::ClNormalizationFloatWorkload::Execute
void Execute() const override
Definition: ClNormalizationFloatWorkload.cpp:59
armnn::NormalizationDescriptor::m_DataLayout
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
Definition: Descriptors.hpp:805
ArmComputeUtils.hpp
armnn::ClNormalizationFloatWorkload::ReplaceOutputTensorHandle
void ReplaceOutputTensorHandle(ITensorHandle *tensorHandle, unsigned int slot) override
Definition: ClNormalizationFloatWorkload.cpp:82
armnn::BoostLogSeverityMapping::info
@ info
armnn::QueueDescriptor::m_Outputs
std::vector< ITensorHandle * > m_Outputs
Definition: WorkloadData.hpp:27
armnn::ClNormalizationWorkloadValidate
arm_compute::Status ClNormalizationWorkloadValidate(const TensorInfo &input, const TensorInfo &output, const NormalizationDescriptor &descriptor)
Definition: ClNormalizationFloatWorkload.cpp:19
ARMNN_REPORT_PROFILING_WORKLOAD_DESC
#define ARMNN_REPORT_PROFILING_WORKLOAD_DESC(name, desc, infos, guid)
Definition: Profiling.hpp:227
armnn::IClTensorHandle
Definition: IClTensorHandle.hpp:13
TensorHandle.hpp
armnn::Status
Status
Definition: Types.hpp:42
ClTensorHandle.hpp
armnn::BaseWorkload::m_Data
QueueDescriptor m_Data
Definition: Workload.hpp:89
armnn::RunClFunction
void RunClFunction(arm_compute::IFunction &function, const CheckLocation &location)
Definition: ClWorkloadUtils.hpp:167
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
ArmComputeTensorUtils.hpp
armnn::UnimplementedException
Definition: Exceptions.hpp:98
armnn::ClNormalizationFloatWorkload::ClNormalizationFloatWorkload
ClNormalizationFloatWorkload(const NormalizationQueueDescriptor &descriptor, const WorkloadInfo &info, const arm_compute::CLCompileContext &clCompileContext)
Definition: ClNormalizationFloatWorkload.cpp:31
armnn::QueueDescriptor::m_Inputs
std::vector< ITensorHandle * > m_Inputs
Definition: WorkloadData.hpp:26