blob: d4110df0ae51332ece00a811dd2c5019efb96479 [file] [log] [blame]
telsoa01c577f2c2018-08-31 09:22:23 +01001//
Teresa Charlin588cbdf2022-01-19 15:55:37 +00002// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa01c577f2c2018-08-31 09:22:23 +01004//
5
6#include "ClConvertFp16ToFp32Workload.hpp"
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +00007#include <cl/ClTensorHandle.hpp>
telsoa01c577f2c2018-08-31 09:22:23 +01008
Matthew Bentham14e46692018-09-20 15:35:30 +01009#include "ClWorkloadUtils.hpp"
10
telsoa01c577f2c2018-08-31 09:22:23 +010011namespace armnn
12{
13using namespace armcomputetensorutils;
14
15static constexpr arm_compute::ConvertPolicy g_AclConvertPolicy = arm_compute::ConvertPolicy::SATURATE;
16
17ClConvertFp16ToFp32Workload::ClConvertFp16ToFp32Workload(
Sadik Armagane9444752020-12-02 11:28:58 +000018 const ConvertFp16ToFp32QueueDescriptor& descriptor,
19 const WorkloadInfo& info,
20 const arm_compute::CLCompileContext& clCompileContext) :
telsoa01c577f2c2018-08-31 09:22:23 +010021 Float16ToFloat32Workload<ConvertFp16ToFp32QueueDescriptor>(descriptor, info)
22{
23 this->m_Data.ValidateInputsOutputs("ClConvertFp16ToFp32Workload", 1, 1);
24
25 arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(this->m_Data.m_Inputs[0])->GetTensor();
26 arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(this->m_Data.m_Outputs[0])->GetTensor();
27
Kevin May9f6862d2021-10-22 15:42:28 +010028 {
29 ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "ClConvertFp16ToFp32Workload_configure");
30 m_Layer.configure(clCompileContext, &input, &output, g_AclConvertPolicy, 0);
31 }
telsoa01c577f2c2018-08-31 09:22:23 +010032}
33
34void ClConvertFp16ToFp32Workload::Execute() const
35{
Keith Davisbcd860a2021-08-05 14:20:33 +010036 ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClConvertFp16ToFp32Workload_Execute", this->GetGuid());
Aron Virginas-Tara8e06ed2018-10-19 16:46:15 +010037 RunClFunction(m_Layer, CHECK_LOCATION());
telsoa01c577f2c2018-08-31 09:22:23 +010038}
39
arovir01085f0a42018-10-08 14:48:19 +010040arm_compute::Status ClConvertFp16ToFp32WorkloadValidate(const TensorInfo& input, const TensorInfo& output)
telsoa01c577f2c2018-08-31 09:22:23 +010041{
42 if (input.GetDataType() != DataType::Float16)
43 {
arovir01085f0a42018-10-08 14:48:19 +010044 return arm_compute::Status(arm_compute::ErrorCode::RUNTIME_ERROR, "Input should be Float16");
telsoa01c577f2c2018-08-31 09:22:23 +010045 }
46 if (output.GetDataType() != DataType::Float32)
47 {
arovir01085f0a42018-10-08 14:48:19 +010048 return arm_compute::Status(arm_compute::ErrorCode::RUNTIME_ERROR, "Output should be Float32");
telsoa01c577f2c2018-08-31 09:22:23 +010049 }
50
51 const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input);
52 const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output);
53
54 const arm_compute::Status aclStatus = arm_compute::CLDepthConvertLayer::validate(
55 &aclInputInfo, &aclOutputInfo, g_AclConvertPolicy, 0);
56
telsoa01c577f2c2018-08-31 09:22:23 +010057 return aclStatus;
58}
59
David Monahanec819992022-02-10 14:47:13 +000060void ClConvertFp16ToFp32Workload::ReplaceInputTensorHandle(ITensorHandle* tensorHandle, unsigned int slot)
61{
62 ITensorHandle* backupHandle = this->m_Data.m_Inputs[slot];
63 this->m_Data.m_Inputs[slot] = tensorHandle;
64 try
65 {
66 Reconfigure();
67 }
68 catch(armnn::UnimplementedException& e)
69 {
70 // Cannot reconfigure, revert the slot back and throw the exception.
71 this->m_Data.m_Inputs[slot] = backupHandle;
72 throw e;
73 }
74}
75
76// Replace output tensor handle with the given TensorHandle
77void ClConvertFp16ToFp32Workload::ReplaceOutputTensorHandle(ITensorHandle* tensorHandle, unsigned int slot)
78{
79 ITensorHandle* backupHandle = this->m_Data.m_Inputs[slot];
80 this->m_Data.m_Inputs[slot] = tensorHandle;
81 try
82 {
83 Reconfigure();
84 }
85 catch(armnn::UnimplementedException& e)
86 {
87 // Cannot reconfigure, revert the slot back and throw the exception.
88 this->m_Data.m_Inputs[slot] = backupHandle;
89 throw e;
90 }
91}
92
93void ClConvertFp16ToFp32Workload::Reconfigure()
94{
95 throw armnn::UnimplementedException("Reconfigure not implemented for this workload");
96}
telsoa01c577f2c2018-08-31 09:22:23 +010097
98} //namespace armnn