blob: e4ed195922f5fd83cd8ecb2806f75d5baf5c2866 [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5
Conor Kennedyb99480b2019-03-08 08:24:41 +00006#include "NeonMultiplicationWorkload.hpp"
telsoa014fcda012018-03-09 14:13:49 +00007
Matthew Benthamd80a7122019-01-08 17:52:37 +00008#include "NeonWorkloadUtils.hpp"
9
Mike Kelly07810fc2020-11-12 10:58:48 +000010#include <aclCommon/ArmComputeUtils.hpp>
11
Jan Eilersbb446e52020-04-02 13:56:54 +010012#include <armnn/utility/PolymorphicDowncast.hpp>
13
Matthew Benthamd80a7122019-01-08 17:52:37 +000014#include <arm_compute/runtime/NEON/functions/NEPixelWiseMultiplication.h>
telsoa014fcda012018-03-09 14:13:49 +000015
16namespace armnn
17{
18
telsoa01c577f2c2018-08-31 09:22:23 +010019arm_compute::Status NeonMultiplicationWorkloadValidate(const TensorInfo& input0,
20 const TensorInfo& input1,
Mike Kelly07810fc2020-11-12 10:58:48 +000021 const TensorInfo& output,
22 const ActivationDescriptor* activationDescriptor)
telsoa01c577f2c2018-08-31 09:22:23 +010023{
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 Charlina2a512c2020-09-29 08:38:47 +010028 auto convertPolicy = (IsQuantizedType(input0.GetDataType()) || IsQuantizedType(input1.GetDataType())) ?
29 arm_compute::ConvertPolicy::SATURATE :
30 arm_compute::ConvertPolicy::WRAP;
31
Mike Kelly07810fc2020-11-12 10:58:48 +000032 const arm_compute::ActivationLayerInfo activationInfo = ConvertActivationDescriptorToAclActivationLayerInfo(
33 activationDescriptor);
34
telsoa01c577f2c2018-08-31 09:22:23 +010035 // 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 Charlina2a512c2020-09-29 08:38:47 +010042 convertPolicy,
Mike Kelly07810fc2020-11-12 10:58:48 +000043 arm_compute::RoundingPolicy::TO_ZERO,
44 activationInfo);
telsoa01c577f2c2018-08-31 09:22:23 +010045}
46
Conor Kennedyb99480b2019-03-08 08:24:41 +000047NeonMultiplicationWorkload::NeonMultiplicationWorkload(const MultiplicationQueueDescriptor& descriptor,
48 const WorkloadInfo& info)
49 : BaseWorkload<MultiplicationQueueDescriptor>(descriptor, info)
telsoa014fcda012018-03-09 14:13:49 +000050{
Conor Kennedyb99480b2019-03-08 08:24:41 +000051 m_Data.ValidateInputsOutputs("NeonMultiplicationWorkload", 2, 1);
telsoa014fcda012018-03-09 14:13:49 +000052
Jan Eilersbb446e52020-04-02 13:56:54 +010053 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();
telsoa014fcda012018-03-09 14:13:49 +000056
Teresa Charlina2a512c2020-09-29 08:38:47 +010057 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 Kelly07810fc2020-11-12 10:58:48 +000062 const arm_compute::ActivationLayerInfo activationInfo = ConvertAdditionalInfoToAclActivationLayerInfo(descriptor);
63
telsoa014fcda012018-03-09 14:13:49 +000064 // 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 Benthamd80a7122019-01-08 17:52:37 +000067 auto layer = std::make_unique<arm_compute::NEPixelWiseMultiplication>();
68 layer->configure(&input1,
69 &input2,
70 &output,
71 1.0f,
Teresa Charlina2a512c2020-09-29 08:38:47 +010072 convertPolicy,
Mike Kelly07810fc2020-11-12 10:58:48 +000073 arm_compute::RoundingPolicy::TO_ZERO,
74 activationInfo);
Matthew Benthamd80a7122019-01-08 17:52:37 +000075 m_PixelWiseMultiplication.reset(layer.release());
telsoa014fcda012018-03-09 14:13:49 +000076}
77
Conor Kennedyb99480b2019-03-08 08:24:41 +000078void NeonMultiplicationWorkload::Execute() const
telsoa014fcda012018-03-09 14:13:49 +000079{
Conor Kennedyb99480b2019-03-08 08:24:41 +000080 ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonMultiplicationWorkload_Execute");
Matthew Benthamd80a7122019-01-08 17:52:37 +000081 m_PixelWiseMultiplication->run();
telsoa014fcda012018-03-09 14:13:49 +000082}
83
84} //namespace armnn