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 | |
Matthew Bentham | e2ec330 | 2018-10-01 11:32:48 +0100 | [diff] [blame] | 6 | #include "ClMultiplicationWorkload.hpp" |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 7 | #include <cl/ClTensorHandle.hpp> |
| 8 | #include <backendsCommon/CpuTensorHandle.hpp> |
Matthew Bentham | 14e4669 | 2018-09-20 15:35:30 +0100 | [diff] [blame] | 9 | #include "ClWorkloadUtils.hpp" |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 10 | |
| 11 | namespace armnn |
| 12 | { |
| 13 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 14 | arm_compute::Status ClMultiplicationWorkloadValidate(const TensorInfo& input0, |
| 15 | const TensorInfo& input1, |
| 16 | const TensorInfo& output) |
| 17 | { |
| 18 | const arm_compute::TensorInfo aclInput1 = armcomputetensorutils::BuildArmComputeTensorInfo(input0); |
| 19 | const arm_compute::TensorInfo aclInput2 = armcomputetensorutils::BuildArmComputeTensorInfo(input1); |
| 20 | const arm_compute::TensorInfo aclOutput = armcomputetensorutils::BuildArmComputeTensorInfo(output); |
| 21 | |
Teresa Charlin | a2a512c | 2020-09-29 08:38:47 +0100 | [diff] [blame^] | 22 | auto convertPolicy = (IsQuantizedType(input0.GetDataType()) || IsQuantizedType(input1.GetDataType())) ? |
| 23 | arm_compute::ConvertPolicy::SATURATE : |
| 24 | arm_compute::ConvertPolicy::WRAP; |
| 25 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 26 | // At the time of writing, configure() will fail if a rounding policy other than TO_ZERO is supplied to it, |
| 27 | // when providing a scale of 1.0 for F32 tensors, even though the provided rounding policy appears to be |
| 28 | // ignored for F32 tensors. |
| 29 | return arm_compute::CLPixelWiseMultiplication::validate(&aclInput1, |
| 30 | &aclInput2, |
| 31 | &aclOutput, |
| 32 | 1.0f, |
Teresa Charlin | a2a512c | 2020-09-29 08:38:47 +0100 | [diff] [blame^] | 33 | convertPolicy, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 34 | arm_compute::RoundingPolicy::TO_ZERO); |
| 35 | } |
| 36 | |
| 37 | |
Matthew Bentham | e2ec330 | 2018-10-01 11:32:48 +0100 | [diff] [blame] | 38 | ClMultiplicationWorkload::ClMultiplicationWorkload(const MultiplicationQueueDescriptor& descriptor, |
| 39 | const WorkloadInfo& info) |
| 40 | : BaseWorkload<MultiplicationQueueDescriptor>(descriptor, info) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 41 | { |
Matthew Bentham | e2ec330 | 2018-10-01 11:32:48 +0100 | [diff] [blame] | 42 | m_Data.ValidateInputsOutputs("ClMultiplicationWorkload", 2, 1); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 43 | |
| 44 | arm_compute::ICLTensor& input0 = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); |
| 45 | arm_compute::ICLTensor& input1 = static_cast<IClTensorHandle*>(m_Data.m_Inputs[1])->GetTensor(); |
| 46 | arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor(); |
Teresa Charlin | a2a512c | 2020-09-29 08:38:47 +0100 | [diff] [blame^] | 47 | |
| 48 | auto convertPolicy = (IsQuantizedType(info.m_InputTensorInfos[0].GetDataType()) || |
| 49 | IsQuantizedType(info.m_InputTensorInfos[1].GetDataType())) ? |
| 50 | arm_compute::ConvertPolicy::SATURATE : |
| 51 | arm_compute::ConvertPolicy::WRAP; |
| 52 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 53 | // Construct |
| 54 | m_PixelWiseMultiplication.configure(&input0, |
| 55 | &input1, |
| 56 | &output, |
| 57 | 1.0f, |
Teresa Charlin | a2a512c | 2020-09-29 08:38:47 +0100 | [diff] [blame^] | 58 | convertPolicy, |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 59 | arm_compute::RoundingPolicy::TO_NEAREST_EVEN); |
| 60 | } |
| 61 | |
Matthew Bentham | e2ec330 | 2018-10-01 11:32:48 +0100 | [diff] [blame] | 62 | void ClMultiplicationWorkload::Execute() const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 63 | { |
Matthew Bentham | e2ec330 | 2018-10-01 11:32:48 +0100 | [diff] [blame] | 64 | ARMNN_SCOPED_PROFILING_EVENT_CL("ClMultiplicationWorkload_Execute"); |
Aron Virginas-Tar | a8e06ed | 2018-10-19 16:46:15 +0100 | [diff] [blame] | 65 | RunClFunction(m_PixelWiseMultiplication, CHECK_LOCATION()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | } //namespace armnn |