ArmNN
 24.02
NeonElementwiseBinaryWorkload.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 #include "NeonWorkloadUtils.hpp"
8 
11 
14 
15 #include <arm_compute/runtime/NEON/functions/NEElementwiseOperations.h>
16 
17 namespace armnn
18 {
19 
21  const TensorInfo& input1,
22  const TensorInfo& output,
23  const ElementwiseBinaryDescriptor& descriptor,
24  const ActivationDescriptor* activationDescriptor)
25 {
26  const arm_compute::TensorInfo aclInput0 = armcomputetensorutils::BuildArmComputeTensorInfo(input0);
27  const arm_compute::TensorInfo aclInput1 = armcomputetensorutils::BuildArmComputeTensorInfo(input1);
28  const arm_compute::TensorInfo aclOutput = armcomputetensorutils::BuildArmComputeTensorInfo(output);
29 
30  const arm_compute::ActivationLayerInfo activationInfo = ConvertActivationDescriptorToAclActivationLayerInfo(
31  activationDescriptor);
32 
33  switch (descriptor.m_Operation)
34  {
36  return arm_compute::NEElementwisePower::validate(&aclInput0,
37  &aclInput1,
38  &aclOutput,
39  activationInfo);
41  return arm_compute::NEElementwiseSquaredDiff::validate(&aclInput0,
42  &aclInput1,
43  &aclOutput,
44  activationInfo);
45  default:
46  throw InvalidArgumentException("Unknown binary operator", CHECK_LOCATION());
47  }
48 }
49 
50 
52  const WorkloadInfo& info)
54 {
55  m_Data.ValidateInputsOutputs("NeonElementwiseBinaryWorkload", 2, 1);
56 
57  arm_compute::ITensor& input1 = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
58  arm_compute::ITensor& input2 = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[1])->GetTensor();
59  arm_compute::ITensor& output = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
60 
61  const arm_compute::ActivationLayerInfo activationInfo = ConvertAdditionalInfoToAclActivationLayerInfo(descriptor);
62 
63  ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "NeonElementwiseBinaryWorkload_configure");
64 
65  switch (descriptor.m_Parameters.m_Operation)
66  {
68  {
69  auto powerLayer = std::make_unique<arm_compute::NEElementwisePower>();
70  powerLayer->configure(&input1, &input2, &output, activationInfo);
71  m_ElementwiseBinaryLayer.reset(powerLayer.release());
72  break;
73  }
75  {
76  auto SqDiffLayer = std::make_unique<arm_compute::NEElementwiseSquaredDiff>();
77  SqDiffLayer->configure(&input1, &input2, &output, activationInfo);
78  m_ElementwiseBinaryLayer.reset(SqDiffLayer.release());
79  break;
80  }
81  default:
82  throw InvalidArgumentException("Unknown binary operator", CHECK_LOCATION());
83  }
84 }
85 
87 {
88  ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID("NeonElementwiseBinaryWorkload_Execute");
89  m_ElementwiseBinaryLayer->run();
90 }
91 
92 } //namespace armnn
armnn::Compute::Undefined
@ Undefined
armnn::ActivationDescriptor
An ActivationDescriptor for the ActivationLayer.
Definition: Descriptors.hpp:36
armnn::QueueDescriptor::ValidateInputsOutputs
void ValidateInputsOutputs(const std::string &descName, unsigned int numExpectedIn, unsigned int numExpectedOut) const
Definition: WorkloadData.cpp:446
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::NeonElementwiseBinaryWorkload::NeonElementwiseBinaryWorkload
NeonElementwiseBinaryWorkload(const ElementwiseBinaryQueueDescriptor &descriptor, const WorkloadInfo &info)
Definition: NeonElementwiseBinaryWorkload.cpp:51
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
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)
Definition: Profiling.hpp:220
armnn::WorkloadInfo
Contains information about TensorInfos of a layer.
Definition: WorkloadInfo.hpp:16
PolymorphicDowncast.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::QueueDescriptor::m_Outputs
std::vector< ITensorHandle * > m_Outputs
Definition: WorkloadData.hpp:27
TensorHandle.hpp
armnn::Status
Status
Definition: Types.hpp:42
armnn::BaseWorkload< ElementwiseBinaryQueueDescriptor >::m_Data
ElementwiseBinaryQueueDescriptor m_Data
Definition: Workload.hpp:89
NeonWorkloadUtils.hpp
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
NeonElementwiseBinaryWorkload.hpp
armnn::NeonElementwiseBinaryWorkloadValidate
arm_compute::Status NeonElementwiseBinaryWorkloadValidate(const TensorInfo &input0, const TensorInfo &input1, const TensorInfo &output, const ElementwiseBinaryDescriptor &descriptor, const ActivationDescriptor *activationDescriptor)
Definition: NeonElementwiseBinaryWorkload.cpp:20
armnn::NeonElementwiseBinaryWorkload::Execute
virtual void Execute() const override
Definition: NeonElementwiseBinaryWorkload.cpp:86
ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID
#define ARMNN_SCOPED_PROFILING_EVENT_NEON_NAME_GUID(label)
Creates a profiling event that uses GetGuid() and GetName() from the calling class.
Definition: NeonWorkloadUtils.hpp:32
armnn::NeonBaseWorkload
Definition: NeonBaseWorkload.hpp:13
armnn::QueueDescriptor::m_Inputs
std::vector< ITensorHandle * > m_Inputs
Definition: WorkloadData.hpp:26