ArmNN
 25.02
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
#define ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID(label)
Creates a profiling event that uses GetGuid() and GetName() from the calling class.
#define CHECK_LOCATION()
Definition: Exceptions.hpp:203
QueueDescriptor m_Data
Definition: Workload.hpp:74
ClElementwiseBinaryWorkload(const ElementwiseBinaryQueueDescriptor &descriptor, const WorkloadInfo &info, const arm_compute::CLCompileContext &clCompileContext)
Copyright (c) 2021 ARM Limited and Contributors.
arm_compute::Status ClElementwiseBinaryValidate(const TensorInfo &input0, const TensorInfo &input1, const TensorInfo &output, const ElementwiseBinaryDescriptor &descriptor, const ActivationDescriptor *activationDescriptor)
Status
enumeration
Definition: Types.hpp:43
arm_compute::ActivationLayerInfo ConvertAdditionalInfoToAclActivationLayerInfo(const QueueDescriptor &queueDescriptor)
arm_compute::ActivationLayerInfo ConvertActivationDescriptorToAclActivationLayerInfo(const ActivationDescriptor &actDesc)
An ActivationDescriptor for the ActivationLayer.
Definition: Descriptors.hpp:37
A ElementwiseBinaryDescriptor for the ElementwiseBinaryLayer.
BinaryOperation m_Operation
Specifies the elementwiseBinary operation to execute.
std::vector< ITensorHandle * > m_Inputs
std::vector< ITensorHandle * > m_Outputs
void ValidateInputsOutputs(const std::string &descName, unsigned int numExpectedIn, unsigned int numExpectedOut) const
Contains information about TensorInfos of a layer.