John Mcloughlin | 34c1c38 | 2023-05-17 15:08:36 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2023 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "NeonElementwiseBinaryWorkload.hpp" |
| 7 | #include "NeonWorkloadUtils.hpp" |
| 8 | |
| 9 | #include <aclCommon/ArmComputeTensorUtils.hpp> |
| 10 | #include <aclCommon/ArmComputeUtils.hpp> |
| 11 | |
| 12 | #include <armnn/utility/PolymorphicDowncast.hpp> |
| 13 | #include <armnn/backends/TensorHandle.hpp> |
| 14 | |
| 15 | #include <arm_compute/runtime/NEON/functions/NEElementwiseOperations.h> |
| 16 | |
| 17 | namespace armnn |
| 18 | { |
| 19 | |
| 20 | arm_compute::Status NeonElementwiseBinaryWorkloadValidate(const TensorInfo& input0, |
| 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 | { |
| 35 | case armnn::BinaryOperation::Power: |
| 36 | return arm_compute::NEElementwisePower::validate(&aclInput0, |
| 37 | &aclInput1, |
| 38 | &aclOutput, |
| 39 | activationInfo); |
| 40 | case armnn::BinaryOperation::SqDiff: |
| 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 | |
| 51 | NeonElementwiseBinaryWorkload::NeonElementwiseBinaryWorkload(const ElementwiseBinaryQueueDescriptor& descriptor, |
| 52 | const WorkloadInfo& info) |
| 53 | : NeonBaseWorkload<ElementwiseBinaryQueueDescriptor>(descriptor, 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 | { |
| 67 | case armnn::BinaryOperation::Power: |
| 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 | } |
| 74 | case armnn::BinaryOperation::SqDiff: |
| 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 | |
| 86 | void NeonElementwiseBinaryWorkload::Execute() const |
| 87 | { |
| 88 | ARMNN_SCOPED_PROFILING_EVENT_NEON_GUID("NeonElementwiseBinaryWorkload_Execute", this->GetGuid()); |
| 89 | m_ElementwiseBinaryLayer->run(); |
| 90 | } |
| 91 | |
| 92 | } //namespace armnn |