blob: 63eee4a946951503088c4d9476cbbcba39500182 [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
Mike Kelly7cbe7812023-07-25 17:37:33 +01002// Copyright © 2017-2018,2020-2023 Arm Ltd and Contributors. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5
Matthew Benthame2ec3302018-10-01 11:32:48 +01006#include "ClMultiplicationWorkload.hpp"
Mike Kelly07810fc2020-11-12 10:58:48 +00007
8#include <aclCommon/ArmComputeUtils.hpp>
Colm Donelan0c479742021-12-10 12:43:54 +00009#include <armnn/backends/TensorHandle.hpp>
Mike Kelly07810fc2020-11-12 10:58:48 +000010
11#include <cl/ClTensorHandle.hpp>
12
Matthew Bentham14e46692018-09-20 15:35:30 +010013#include "ClWorkloadUtils.hpp"
telsoa014fcda012018-03-09 14:13:49 +000014
15namespace armnn
16{
17
telsoa01c577f2c2018-08-31 09:22:23 +010018arm_compute::Status ClMultiplicationWorkloadValidate(const TensorInfo& input0,
19 const TensorInfo& input1,
Mike Kelly07810fc2020-11-12 10:58:48 +000020 const TensorInfo& output,
21 const ActivationDescriptor* activationDescriptor)
telsoa01c577f2c2018-08-31 09:22:23 +010022{
23 const arm_compute::TensorInfo aclInput1 = armcomputetensorutils::BuildArmComputeTensorInfo(input0);
24 const arm_compute::TensorInfo aclInput2 = armcomputetensorutils::BuildArmComputeTensorInfo(input1);
25 const arm_compute::TensorInfo aclOutput = armcomputetensorutils::BuildArmComputeTensorInfo(output);
26
Teresa Charlina2a512c2020-09-29 08:38:47 +010027 auto convertPolicy = (IsQuantizedType(input0.GetDataType()) || IsQuantizedType(input1.GetDataType())) ?
28 arm_compute::ConvertPolicy::SATURATE :
29 arm_compute::ConvertPolicy::WRAP;
30
Mike Kelly07810fc2020-11-12 10:58:48 +000031 const arm_compute::ActivationLayerInfo activationInfo = ConvertActivationDescriptorToAclActivationLayerInfo(
32 activationDescriptor);
33
telsoa01c577f2c2018-08-31 09:22:23 +010034 // At the time of writing, configure() will fail if a rounding policy other than TO_ZERO is supplied to it,
35 // when providing a scale of 1.0 for F32 tensors, even though the provided rounding policy appears to be
36 // ignored for F32 tensors.
37 return arm_compute::CLPixelWiseMultiplication::validate(&aclInput1,
38 &aclInput2,
39 &aclOutput,
40 1.0f,
Teresa Charlina2a512c2020-09-29 08:38:47 +010041 convertPolicy,
Mike Kelly07810fc2020-11-12 10:58:48 +000042 arm_compute::RoundingPolicy::TO_ZERO,
43 activationInfo);
telsoa01c577f2c2018-08-31 09:22:23 +010044}
45
46
Matthew Benthame2ec3302018-10-01 11:32:48 +010047ClMultiplicationWorkload::ClMultiplicationWorkload(const MultiplicationQueueDescriptor& descriptor,
Sadik Armagane9444752020-12-02 11:28:58 +000048 const WorkloadInfo& info,
49 const arm_compute::CLCompileContext& clCompileContext)
Teresa Charlin588cbdf2022-01-19 15:55:37 +000050 : ClBaseWorkload<MultiplicationQueueDescriptor>(descriptor, info)
telsoa014fcda012018-03-09 14:13:49 +000051{
Matthew Benthame2ec3302018-10-01 11:32:48 +010052 m_Data.ValidateInputsOutputs("ClMultiplicationWorkload", 2, 1);
telsoa014fcda012018-03-09 14:13:49 +000053
54 arm_compute::ICLTensor& input0 = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor();
55 arm_compute::ICLTensor& input1 = static_cast<IClTensorHandle*>(m_Data.m_Inputs[1])->GetTensor();
56 arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor();
Teresa Charlina2a512c2020-09-29 08:38:47 +010057
58 auto convertPolicy = (IsQuantizedType(info.m_InputTensorInfos[0].GetDataType()) ||
59 IsQuantizedType(info.m_InputTensorInfos[1].GetDataType())) ?
60 arm_compute::ConvertPolicy::SATURATE :
61 arm_compute::ConvertPolicy::WRAP;
62
Mike Kelly07810fc2020-11-12 10:58:48 +000063 const arm_compute::ActivationLayerInfo activationInfo = ConvertAdditionalInfoToAclActivationLayerInfo(descriptor);
64
Kevin May9f6862d2021-10-22 15:42:28 +010065 {
Mike Kelly7cbe7812023-07-25 17:37:33 +010066 ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClMultiplicationWorkload_configure");
Kevin May9f6862d2021-10-22 15:42:28 +010067 // Construct
68 m_PixelWiseMultiplication.configure(clCompileContext,
69 &input0,
70 &input1,
71 &output,
72 1.0f,
73 convertPolicy,
74 arm_compute::RoundingPolicy::TO_NEAREST_EVEN,
75 activationInfo);
76 }
telsoa014fcda012018-03-09 14:13:49 +000077}
78
Matthew Benthame2ec3302018-10-01 11:32:48 +010079void ClMultiplicationWorkload::Execute() const
telsoa014fcda012018-03-09 14:13:49 +000080{
Mike Kelly7cbe7812023-07-25 17:37:33 +010081 ARMNN_SCOPED_PROFILING_EVENT_CL_NAME_GUID("ClMultiplicationWorkload_Execute");
Aron Virginas-Tara8e06ed2018-10-19 16:46:15 +010082 RunClFunction(m_PixelWiseMultiplication, CHECK_LOCATION());
telsoa014fcda012018-03-09 14:13:49 +000083}
84
85} //namespace armnn