blob: 6f78b8eaccae842d5a144a3019b72e90d5190178 [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
Jan Eilersbb446e52020-04-02 13:56:54 +010010#include <armnn/utility/PolymorphicDowncast.hpp>
11
Matthew Benthamd80a7122019-01-08 17:52:37 +000012#include <arm_compute/runtime/NEON/functions/NEPixelWiseMultiplication.h>
telsoa014fcda012018-03-09 14:13:49 +000013
14namespace armnn
15{
16
telsoa01c577f2c2018-08-31 09:22:23 +010017arm_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 Charlina2a512c2020-09-29 08:38:47 +010025 auto convertPolicy = (IsQuantizedType(input0.GetDataType()) || IsQuantizedType(input1.GetDataType())) ?
26 arm_compute::ConvertPolicy::SATURATE :
27 arm_compute::ConvertPolicy::WRAP;
28
telsoa01c577f2c2018-08-31 09:22:23 +010029 // 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 Charlina2a512c2020-09-29 08:38:47 +010036 convertPolicy,
telsoa01c577f2c2018-08-31 09:22:23 +010037 arm_compute::RoundingPolicy::TO_ZERO);
38}
39
Conor Kennedyb99480b2019-03-08 08:24:41 +000040NeonMultiplicationWorkload::NeonMultiplicationWorkload(const MultiplicationQueueDescriptor& descriptor,
41 const WorkloadInfo& info)
42 : BaseWorkload<MultiplicationQueueDescriptor>(descriptor, info)
telsoa014fcda012018-03-09 14:13:49 +000043{
Conor Kennedyb99480b2019-03-08 08:24:41 +000044 m_Data.ValidateInputsOutputs("NeonMultiplicationWorkload", 2, 1);
telsoa014fcda012018-03-09 14:13:49 +000045
Jan Eilersbb446e52020-04-02 13:56:54 +010046 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();
telsoa014fcda012018-03-09 14:13:49 +000049
Teresa Charlina2a512c2020-09-29 08:38:47 +010050 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
telsoa014fcda012018-03-09 14:13:49 +000055 // 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 Benthamd80a7122019-01-08 17:52:37 +000058 auto layer = std::make_unique<arm_compute::NEPixelWiseMultiplication>();
59 layer->configure(&input1,
60 &input2,
61 &output,
62 1.0f,
Teresa Charlina2a512c2020-09-29 08:38:47 +010063 convertPolicy,
Matthew Benthamd80a7122019-01-08 17:52:37 +000064 arm_compute::RoundingPolicy::TO_ZERO);
65 m_PixelWiseMultiplication.reset(layer.release());
telsoa014fcda012018-03-09 14:13:49 +000066}
67
Conor Kennedyb99480b2019-03-08 08:24:41 +000068void NeonMultiplicationWorkload::Execute() const
telsoa014fcda012018-03-09 14:13:49 +000069{
Conor Kennedyb99480b2019-03-08 08:24:41 +000070 ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonMultiplicationWorkload_Execute");
Matthew Benthamd80a7122019-01-08 17:52:37 +000071 m_PixelWiseMultiplication->run();
telsoa014fcda012018-03-09 14:13:49 +000072}
73
74} //namespace armnn