telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | |
Conor Kennedy | b99480b | 2019-03-08 08:24:41 +0000 | [diff] [blame] | 6 | #include "NeonMultiplicationWorkload.hpp" |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 7 | |
Matthew Bentham | d80a712 | 2019-01-08 17:52:37 +0000 | [diff] [blame] | 8 | #include "NeonWorkloadUtils.hpp" |
| 9 | |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 10 | #include <aclCommon/ArmComputeUtils.hpp> |
| 11 | |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 12 | #include <armnn/utility/PolymorphicDowncast.hpp> |
| 13 | |
Matthew Bentham | d80a712 | 2019-01-08 17:52:37 +0000 | [diff] [blame] | 14 | #include <arm_compute/runtime/NEON/functions/NEPixelWiseMultiplication.h> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 15 | |
| 16 | namespace armnn |
| 17 | { |
| 18 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 19 | arm_compute::Status NeonMultiplicationWorkloadValidate(const TensorInfo& input0, |
| 20 | const TensorInfo& input1, |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 21 | const TensorInfo& output, |
| 22 | const ActivationDescriptor* activationDescriptor) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 23 | { |
| 24 | const arm_compute::TensorInfo aclInput1 = armcomputetensorutils::BuildArmComputeTensorInfo(input0); |
| 25 | const arm_compute::TensorInfo aclInput2 = armcomputetensorutils::BuildArmComputeTensorInfo(input1); |
| 26 | const arm_compute::TensorInfo aclOutput = armcomputetensorutils::BuildArmComputeTensorInfo(output); |
| 27 | |
Teresa Charlin | a2a512c | 2020-09-29 08:38:47 +0100 | [diff] [blame] | 28 | auto convertPolicy = (IsQuantizedType(input0.GetDataType()) || IsQuantizedType(input1.GetDataType())) ? |
| 29 | arm_compute::ConvertPolicy::SATURATE : |
| 30 | arm_compute::ConvertPolicy::WRAP; |
| 31 | |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 32 | const arm_compute::ActivationLayerInfo activationInfo = ConvertActivationDescriptorToAclActivationLayerInfo( |
| 33 | activationDescriptor); |
| 34 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 35 | // At the time of writing, configure() will fail if a rounding policy other than TO_ZERO is supplied to it, |
| 36 | // when providing a scale of 1.0 for F32 tensors, even though the provided rounding policy appears to be |
| 37 | // ignored for F32 tensors. |
| 38 | return arm_compute::NEPixelWiseMultiplication::validate(&aclInput1, |
| 39 | &aclInput2, |
| 40 | &aclOutput, |
| 41 | 1.0f, |
Teresa Charlin | a2a512c | 2020-09-29 08:38:47 +0100 | [diff] [blame] | 42 | convertPolicy, |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 43 | arm_compute::RoundingPolicy::TO_ZERO, |
| 44 | activationInfo); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 45 | } |
| 46 | |
Conor Kennedy | b99480b | 2019-03-08 08:24:41 +0000 | [diff] [blame] | 47 | NeonMultiplicationWorkload::NeonMultiplicationWorkload(const MultiplicationQueueDescriptor& descriptor, |
| 48 | const WorkloadInfo& info) |
| 49 | : BaseWorkload<MultiplicationQueueDescriptor>(descriptor, info) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 50 | { |
Conor Kennedy | b99480b | 2019-03-08 08:24:41 +0000 | [diff] [blame] | 51 | m_Data.ValidateInputsOutputs("NeonMultiplicationWorkload", 2, 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 52 | |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 53 | arm_compute::ITensor& input1 = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); |
| 54 | arm_compute::ITensor& input2 = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[1])->GetTensor(); |
| 55 | arm_compute::ITensor& output = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 56 | |
Teresa Charlin | a2a512c | 2020-09-29 08:38:47 +0100 | [diff] [blame] | 57 | auto convertPolicy = (IsQuantizedType(info.m_InputTensorInfos[0].GetDataType()) || |
| 58 | IsQuantizedType(info.m_InputTensorInfos[1].GetDataType())) ? |
| 59 | arm_compute::ConvertPolicy::SATURATE : |
| 60 | arm_compute::ConvertPolicy::WRAP; |
| 61 | |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 62 | const arm_compute::ActivationLayerInfo activationInfo = ConvertAdditionalInfoToAclActivationLayerInfo(descriptor); |
| 63 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 64 | // At the time of writing, configure() will fail if a rounding policy other than TO_ZERO is supplied to it, |
| 65 | // when providing a scale of 1.0 for F32 tensors, even though the provided rounding policy appears to be |
| 66 | // ignored for F32 tensors. |
Matthew Bentham | d80a712 | 2019-01-08 17:52:37 +0000 | [diff] [blame] | 67 | auto layer = std::make_unique<arm_compute::NEPixelWiseMultiplication>(); |
| 68 | layer->configure(&input1, |
| 69 | &input2, |
| 70 | &output, |
| 71 | 1.0f, |
Teresa Charlin | a2a512c | 2020-09-29 08:38:47 +0100 | [diff] [blame] | 72 | convertPolicy, |
Mike Kelly | 07810fc | 2020-11-12 10:58:48 +0000 | [diff] [blame] | 73 | arm_compute::RoundingPolicy::TO_ZERO, |
| 74 | activationInfo); |
Matthew Bentham | d80a712 | 2019-01-08 17:52:37 +0000 | [diff] [blame] | 75 | m_PixelWiseMultiplication.reset(layer.release()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Conor Kennedy | b99480b | 2019-03-08 08:24:41 +0000 | [diff] [blame] | 78 | void NeonMultiplicationWorkload::Execute() const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 79 | { |
Keith Davis | 2d0679f | 2021-08-05 11:35:00 +0100 | [diff] [blame] | 80 | ARMNN_SCOPED_PROFILING_EVENT_NEON_GUID("NeonMultiplicationWorkload_Execute", this->GetGuid()); |
Matthew Bentham | d80a712 | 2019-01-08 17:52:37 +0000 | [diff] [blame] | 81 | m_PixelWiseMultiplication->run(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | } //namespace armnn |