David Beck | 4a8692c | 2018-09-07 16:19:24 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
David Beck | 0a710c4 | 2018-09-11 15:21:14 +0100 | [diff] [blame] | 6 | #include "ClSubtractionWorkload.hpp" |
David Beck | 4a8692c | 2018-09-07 16:19:24 +0100 | [diff] [blame] | 7 | |
| 8 | #include "backends/ClTensorHandle.hpp" |
| 9 | #include "backends/CpuTensorHandle.hpp" |
| 10 | #include "backends/ArmComputeTensorUtils.hpp" |
| 11 | |
Matthew Bentham | 14e4669 | 2018-09-20 15:35:30 +0100 | [diff] [blame] | 12 | #include "ClWorkloadUtils.hpp" |
| 13 | |
David Beck | 4a8692c | 2018-09-07 16:19:24 +0100 | [diff] [blame] | 14 | namespace armnn |
| 15 | { |
| 16 | using namespace armcomputetensorutils; |
| 17 | |
| 18 | static constexpr arm_compute::ConvertPolicy g_AclConvertPolicy = arm_compute::ConvertPolicy::SATURATE; |
| 19 | |
| 20 | template <armnn::DataType... T> |
David Beck | 0a710c4 | 2018-09-11 15:21:14 +0100 | [diff] [blame] | 21 | ClSubtractionWorkload<T...>::ClSubtractionWorkload(const SubtractionQueueDescriptor& descriptor, |
David Beck | 4a8692c | 2018-09-07 16:19:24 +0100 | [diff] [blame] | 22 | const WorkloadInfo& info) |
| 23 | : TypedWorkload<SubtractionQueueDescriptor, T...>(descriptor, info) |
| 24 | { |
David Beck | 0a710c4 | 2018-09-11 15:21:14 +0100 | [diff] [blame] | 25 | this->m_Data.ValidateInputsOutputs("ClSubtractionWorkload", 2, 1); |
David Beck | 4a8692c | 2018-09-07 16:19:24 +0100 | [diff] [blame] | 26 | |
| 27 | arm_compute::ICLTensor& input0 = static_cast<IClTensorHandle*>(this->m_Data.m_Inputs[0])->GetTensor(); |
| 28 | arm_compute::ICLTensor& input1 = static_cast<IClTensorHandle*>(this->m_Data.m_Inputs[1])->GetTensor(); |
| 29 | arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(this->m_Data.m_Outputs[0])->GetTensor(); |
| 30 | m_Layer.configure(&input0, &input1, &output, g_AclConvertPolicy); |
| 31 | } |
| 32 | |
| 33 | template <armnn::DataType... T> |
David Beck | 0a710c4 | 2018-09-11 15:21:14 +0100 | [diff] [blame] | 34 | void ClSubtractionWorkload<T...>::Execute() const |
David Beck | 4a8692c | 2018-09-07 16:19:24 +0100 | [diff] [blame] | 35 | { |
David Beck | 0a710c4 | 2018-09-11 15:21:14 +0100 | [diff] [blame] | 36 | ARMNN_SCOPED_PROFILING_EVENT_CL("ClSubtractionWorkload_Execute"); |
David Beck | 4a8692c | 2018-09-07 16:19:24 +0100 | [diff] [blame] | 37 | m_Layer.run(); |
| 38 | } |
| 39 | |
| 40 | bool ClSubtractionValidate(const TensorInfo& input0, |
| 41 | const TensorInfo& input1, |
| 42 | const TensorInfo& output, |
| 43 | std::string* reasonIfUnsupported) |
| 44 | { |
| 45 | const arm_compute::TensorInfo aclInput0Info = BuildArmComputeTensorInfo(input0); |
| 46 | const arm_compute::TensorInfo aclInput1Info = BuildArmComputeTensorInfo(input1); |
| 47 | const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output); |
| 48 | |
| 49 | const arm_compute::Status aclStatus = arm_compute::CLArithmeticSubtraction::validate(&aclInput0Info, |
| 50 | &aclInput1Info, |
| 51 | &aclOutputInfo, |
| 52 | g_AclConvertPolicy); |
| 53 | |
| 54 | const bool supported = (aclStatus.error_code() == arm_compute::ErrorCode::OK); |
| 55 | if (!supported && reasonIfUnsupported) |
| 56 | { |
| 57 | *reasonIfUnsupported = aclStatus.error_description(); |
| 58 | } |
| 59 | |
| 60 | return supported; |
| 61 | } |
| 62 | |
| 63 | } //namespace armnn |
| 64 | |
David Beck | 0a710c4 | 2018-09-11 15:21:14 +0100 | [diff] [blame] | 65 | template class armnn::ClSubtractionWorkload<armnn::DataType::Float16, armnn::DataType::Float32>; |
| 66 | template class armnn::ClSubtractionWorkload<armnn::DataType::QuantisedAsymm8>; |