IVGCVSW-1900 : CL backend folder structure
[platform/upstream/armnn.git] / src / backends / cl / workloads / ClSubtractionWorkload.cpp
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5
6 #include "ClSubtractionWorkload.hpp"
7
8 #include <backends/cl/ClTensorHandle.hpp>
9 #include <backends/CpuTensorHandle.hpp>
10 #include <backends/aclCommon/ArmComputeTensorUtils.hpp>
11
12 #include "ClWorkloadUtils.hpp"
13
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>
21 ClSubtractionWorkload<T...>::ClSubtractionWorkload(const SubtractionQueueDescriptor& descriptor,
22                                                            const WorkloadInfo& info)
23     : TypedWorkload<SubtractionQueueDescriptor, T...>(descriptor, info)
24 {
25     this->m_Data.ValidateInputsOutputs("ClSubtractionWorkload", 2, 1);
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>
34 void ClSubtractionWorkload<T...>::Execute() const
35 {
36     ARMNN_SCOPED_PROFILING_EVENT_CL("ClSubtractionWorkload_Execute");
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
65 template class armnn::ClSubtractionWorkload<armnn::DataType::Float16, armnn::DataType::Float32>;
66 template class armnn::ClSubtractionWorkload<armnn::DataType::QuantisedAsymm8>;