ArmNN
 24.08
ClElementwiseBinaryWorkload.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 
8 #include <cl/ClTensorHandle.hpp>
12 
13 #include "ClWorkloadUtils.hpp"
14 
15 namespace armnn
16 {
17 using namespace armcomputetensorutils;
18 
20  const WorkloadInfo& info,
21  const arm_compute::CLCompileContext& clCompileContext)
23 {
24  this->m_Data.ValidateInputsOutputs("ClElementwiseBinaryWorkload", 2, 1);
25 
26  arm_compute::ICLTensor &input0 = static_cast<IClTensorHandle *>(this->m_Data.m_Inputs[0])->GetTensor();
27  arm_compute::ICLTensor &input1 = static_cast<IClTensorHandle *>(this->m_Data.m_Inputs[1])->GetTensor();
28  arm_compute::ICLTensor &output = static_cast<IClTensorHandle *>(this->m_Data.m_Outputs[0])->GetTensor();
29 
30  const arm_compute::ActivationLayerInfo activationInfo = ConvertAdditionalInfoToAclActivationLayerInfo(descriptor);
31  {
32  ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClElementwiseBinaryWorkload_configure");
33 
34  switch (descriptor.m_Parameters.m_Operation)
35  {
37  {
38  auto powerLayer = std::make_unique<arm_compute::CLElementwisePower>();
39  powerLayer->configure(clCompileContext, &input0, &input1, &output, activationInfo);
40  m_ElementwiseBinaryLayer.reset(powerLayer.release());
41  break;
42  }
44  {
45  auto SqDiffLayer = std::make_unique<arm_compute::CLElementwiseSquaredDiff>();
46  SqDiffLayer->configure(clCompileContext, &input0, &input1, &output, activationInfo);
47  m_ElementwiseBinaryLayer.reset(SqDiffLayer.release());
48  break;
49  }
50  default:
51  throw InvalidArgumentException("Unknown binary operator", CHECK_LOCATION());
52  }
53  }
54 }
56 {
57  if (m_ElementwiseBinaryLayer)
58  {
59  ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClElementwiseBinaryWorkload_Execute");
60  m_ElementwiseBinaryLayer->run();
61  }
62 }
63 
65  const TensorInfo& input1,
66  const TensorInfo& output,
67  const ElementwiseBinaryDescriptor& descriptor,
68  const ActivationDescriptor* activationDescriptor)
69 {
70  const arm_compute::TensorInfo aclInput0Info = BuildArmComputeTensorInfo(input0);
71  const arm_compute::TensorInfo aclInput1Info = BuildArmComputeTensorInfo(input1);
72  const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output);
73 
74  const arm_compute::ActivationLayerInfo activationInfo = ConvertActivationDescriptorToAclActivationLayerInfo(
75  activationDescriptor);
76 
77  switch (descriptor.m_Operation)
78  {
80  return arm_compute::CLElementwisePower::validate(&aclInput0Info,
81  &aclInput1Info,
82  &aclOutputInfo,
83  activationInfo);
85  return arm_compute::CLElementwiseSquaredDiff::validate(&aclInput0Info,
86  &aclInput1Info,
87  &aclOutputInfo,
88  activationInfo);
89  default:
90  throw InvalidArgumentException("Unknown binary operator", CHECK_LOCATION());
91  }
92 }
93 
94 } //namespace armnn
armnn::ActivationDescriptor
An ActivationDescriptor for the ActivationLayer.
Definition: Descriptors.hpp:36
ClElementwiseBinaryWorkload.hpp
armnn::QueueDescriptor::ValidateInputsOutputs
void ValidateInputsOutputs(const std::string &descName, unsigned int numExpectedIn, unsigned int numExpectedOut) const
Definition: WorkloadData.cpp:447
armnn::ConvertAdditionalInfoToAclActivationLayerInfo
arm_compute::ActivationLayerInfo ConvertAdditionalInfoToAclActivationLayerInfo(const QueueDescriptor &queueDescriptor)
Definition: ArmComputeUtils.hpp:105
armnn::TensorInfo
Definition: Tensor.hpp:152
CHECK_LOCATION
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
armnn::ClBaseWorkload
Definition: ClBaseWorkload.hpp:13
armnn::ClElementwiseBinaryValidate
arm_compute::Status ClElementwiseBinaryValidate(const TensorInfo &input0, const TensorInfo &input1, const TensorInfo &output, const ElementwiseBinaryDescriptor &descriptor, const ActivationDescriptor *activationDescriptor)
Definition: ClElementwiseBinaryWorkload.cpp:64
armnn::ElementwiseBinaryDescriptor
A ElementwiseBinaryDescriptor for the ElementwiseBinaryLayer.
Definition: Descriptors.hpp:109
armnn::ElementwiseBinaryQueueDescriptor
Definition: WorkloadData.hpp:671
armnn::BinaryOperation::SqDiff
@ SqDiff
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
armnn::ClElementwiseBinaryWorkload::ClElementwiseBinaryWorkload
ClElementwiseBinaryWorkload(const ElementwiseBinaryQueueDescriptor &descriptor, const WorkloadInfo &info, const arm_compute::CLCompileContext &clCompileContext)
Definition: ClElementwiseBinaryWorkload.cpp:19
ClWorkloadUtils.hpp
armnn::InvalidArgumentException
Definition: Exceptions.hpp:80
ArmComputeUtils.hpp
armnn::ConvertActivationDescriptorToAclActivationLayerInfo
arm_compute::ActivationLayerInfo ConvertActivationDescriptorToAclActivationLayerInfo(const ActivationDescriptor &actDesc)
Definition: ArmComputeUtils.hpp:87
armnn::BoostLogSeverityMapping::info
@ info
armnn::BinaryOperation::Power
@ Power
armnn::ClElementwiseBinaryWorkload::Execute
void Execute() const override
Definition: ClElementwiseBinaryWorkload.cpp:55
armnn::QueueDescriptor::m_Outputs
std::vector< ITensorHandle * > m_Outputs
Definition: WorkloadData.hpp:27
armnn::IClTensorHandle
Definition: IClTensorHandle.hpp:13
TensorHandle.hpp
armnn::Status
Status
Definition: Types.hpp:42
ClTensorHandle.hpp
armnn::BaseWorkload< ElementwiseBinaryQueueDescriptor >::m_Data
ElementwiseBinaryQueueDescriptor m_Data
Definition: Workload.hpp:89
armnn::ElementwiseBinaryDescriptor::m_Operation
BinaryOperation m_Operation
Specifies the elementwiseBinary operation to execute.
Definition: Descriptors.hpp:125
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
ArmComputeTensorUtils.hpp
armnn::QueueDescriptor::m_Inputs
std::vector< ITensorHandle * > m_Inputs
Definition: WorkloadData.hpp:26