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 | |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 10 | #include <armnn/utility/PolymorphicDowncast.hpp> |
| 11 | |
Matthew Bentham | d80a712 | 2019-01-08 17:52:37 +0000 | [diff] [blame] | 12 | #include <arm_compute/runtime/NEON/functions/NEPixelWiseMultiplication.h> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 13 | |
| 14 | namespace armnn |
| 15 | { |
| 16 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 17 | arm_compute::Status NeonMultiplicationWorkloadValidate(const TensorInfo& input0, |
| 18 | const TensorInfo& input1, |
| 19 | const TensorInfo& output) |
| 20 | { |
| 21 | const arm_compute::TensorInfo aclInput1 = armcomputetensorutils::BuildArmComputeTensorInfo(input0); |
| 22 | const arm_compute::TensorInfo aclInput2 = armcomputetensorutils::BuildArmComputeTensorInfo(input1); |
| 23 | const arm_compute::TensorInfo aclOutput = armcomputetensorutils::BuildArmComputeTensorInfo(output); |
| 24 | |
Teresa Charlin | a2a512c | 2020-09-29 08:38:47 +0100 | [diff] [blame^] | 25 | auto convertPolicy = (IsQuantizedType(input0.GetDataType()) || IsQuantizedType(input1.GetDataType())) ? |
| 26 | arm_compute::ConvertPolicy::SATURATE : |
| 27 | arm_compute::ConvertPolicy::WRAP; |
| 28 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 29 | // At the time of writing, configure() will fail if a rounding policy other than TO_ZERO is supplied to it, |
| 30 | // when providing a scale of 1.0 for F32 tensors, even though the provided rounding policy appears to be |
| 31 | // ignored for F32 tensors. |
| 32 | return arm_compute::NEPixelWiseMultiplication::validate(&aclInput1, |
| 33 | &aclInput2, |
| 34 | &aclOutput, |
| 35 | 1.0f, |
Teresa Charlin | a2a512c | 2020-09-29 08:38:47 +0100 | [diff] [blame^] | 36 | convertPolicy, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 37 | arm_compute::RoundingPolicy::TO_ZERO); |
| 38 | } |
| 39 | |
Conor Kennedy | b99480b | 2019-03-08 08:24:41 +0000 | [diff] [blame] | 40 | NeonMultiplicationWorkload::NeonMultiplicationWorkload(const MultiplicationQueueDescriptor& descriptor, |
| 41 | const WorkloadInfo& info) |
| 42 | : BaseWorkload<MultiplicationQueueDescriptor>(descriptor, info) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 43 | { |
Conor Kennedy | b99480b | 2019-03-08 08:24:41 +0000 | [diff] [blame] | 44 | m_Data.ValidateInputsOutputs("NeonMultiplicationWorkload", 2, 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 45 | |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 46 | arm_compute::ITensor& input1 = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); |
| 47 | arm_compute::ITensor& input2 = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Inputs[1])->GetTensor(); |
| 48 | arm_compute::ITensor& output = PolymorphicDowncast<IAclTensorHandle*>(m_Data.m_Outputs[0])->GetTensor(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 49 | |
Teresa Charlin | a2a512c | 2020-09-29 08:38:47 +0100 | [diff] [blame^] | 50 | auto convertPolicy = (IsQuantizedType(info.m_InputTensorInfos[0].GetDataType()) || |
| 51 | IsQuantizedType(info.m_InputTensorInfos[1].GetDataType())) ? |
| 52 | arm_compute::ConvertPolicy::SATURATE : |
| 53 | arm_compute::ConvertPolicy::WRAP; |
| 54 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 55 | // At the time of writing, configure() will fail if a rounding policy other than TO_ZERO is supplied to it, |
| 56 | // when providing a scale of 1.0 for F32 tensors, even though the provided rounding policy appears to be |
| 57 | // ignored for F32 tensors. |
Matthew Bentham | d80a712 | 2019-01-08 17:52:37 +0000 | [diff] [blame] | 58 | auto layer = std::make_unique<arm_compute::NEPixelWiseMultiplication>(); |
| 59 | layer->configure(&input1, |
| 60 | &input2, |
| 61 | &output, |
| 62 | 1.0f, |
Teresa Charlin | a2a512c | 2020-09-29 08:38:47 +0100 | [diff] [blame^] | 63 | convertPolicy, |
Matthew Bentham | d80a712 | 2019-01-08 17:52:37 +0000 | [diff] [blame] | 64 | arm_compute::RoundingPolicy::TO_ZERO); |
| 65 | m_PixelWiseMultiplication.reset(layer.release()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Conor Kennedy | b99480b | 2019-03-08 08:24:41 +0000 | [diff] [blame] | 68 | void NeonMultiplicationWorkload::Execute() const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 69 | { |
Conor Kennedy | b99480b | 2019-03-08 08:24:41 +0000 | [diff] [blame] | 70 | ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonMultiplicationWorkload_Execute"); |
Matthew Bentham | d80a712 | 2019-01-08 17:52:37 +0000 | [diff] [blame] | 71 | m_PixelWiseMultiplication->run(); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | } //namespace armnn |