blob: 31e9d022cc0c014bcb6c13efb4f04f40c133d2bd [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
Matthew Benthame2ec3302018-10-01 11:32:48 +01006#include "ClMultiplicationWorkload.hpp"
Mike Kelly07810fc2020-11-12 10:58:48 +00007
8#include <aclCommon/ArmComputeUtils.hpp>
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +00009#include <backendsCommon/CpuTensorHandle.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)
Matthew Benthame2ec3302018-10-01 11:32:48 +010050 : BaseWorkload<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
telsoa014fcda012018-03-09 14:13:49 +000065 // Construct
Sadik Armagane9444752020-12-02 11:28:58 +000066 m_PixelWiseMultiplication.configure(clCompileContext,
67 &input0,
telsoa014fcda012018-03-09 14:13:49 +000068 &input1,
69 &output,
70 1.0f,
Teresa Charlina2a512c2020-09-29 08:38:47 +010071 convertPolicy,
Mike Kelly07810fc2020-11-12 10:58:48 +000072 arm_compute::RoundingPolicy::TO_NEAREST_EVEN,
73 activationInfo);
telsoa014fcda012018-03-09 14:13:49 +000074}
75
Matthew Benthame2ec3302018-10-01 11:32:48 +010076void ClMultiplicationWorkload::Execute() const
telsoa014fcda012018-03-09 14:13:49 +000077{
Matthew Benthame2ec3302018-10-01 11:32:48 +010078 ARMNN_SCOPED_PROFILING_EVENT_CL("ClMultiplicationWorkload_Execute");
Aron Virginas-Tara8e06ed2018-10-19 16:46:15 +010079 RunClFunction(m_PixelWiseMultiplication, CHECK_LOCATION());
telsoa014fcda012018-03-09 14:13:49 +000080}
81
82} //namespace armnn