telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1 | // |
Teresa Charlin | 588cbdf | 2022-01-19 15:55:37 +0000 | [diff] [blame] | 2 | // Copyright © 2017 Arm Ltd and Contributors. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 4 | // |
| 5 | |
| 6 | #include "ClConvertFp16ToFp32Workload.hpp" |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 7 | #include <cl/ClTensorHandle.hpp> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 8 | |
Matthew Bentham | 14e4669 | 2018-09-20 15:35:30 +0100 | [diff] [blame] | 9 | #include "ClWorkloadUtils.hpp" |
| 10 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 11 | namespace armnn |
| 12 | { |
| 13 | using namespace armcomputetensorutils; |
| 14 | |
| 15 | static constexpr arm_compute::ConvertPolicy g_AclConvertPolicy = arm_compute::ConvertPolicy::SATURATE; |
| 16 | |
| 17 | ClConvertFp16ToFp32Workload::ClConvertFp16ToFp32Workload( |
Sadik Armagan | e944475 | 2020-12-02 11:28:58 +0000 | [diff] [blame] | 18 | const ConvertFp16ToFp32QueueDescriptor& descriptor, |
| 19 | const WorkloadInfo& info, |
| 20 | const arm_compute::CLCompileContext& clCompileContext) : |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 21 | 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 | |
Jim Flynn | 5e7335b | 2022-02-14 11:22:29 +0000 | [diff] [blame] | 28 | // Create Proxy tensor and set the initial tensor handle to it |
| 29 | m_InputProxy = std::make_unique<ICLTensorProxy>(&input); |
| 30 | m_OutputProxy = std::make_unique<ICLTensorProxy>(&output); |
| 31 | |
Kevin May | 9f6862d | 2021-10-22 15:42:28 +0100 | [diff] [blame] | 32 | { |
| 33 | ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "ClConvertFp16ToFp32Workload_configure"); |
Jim Flynn | 5e7335b | 2022-02-14 11:22:29 +0000 | [diff] [blame] | 34 | m_Layer.configure(clCompileContext, m_InputProxy.get(), m_OutputProxy.get(), g_AclConvertPolicy, 0); |
Kevin May | 9f6862d | 2021-10-22 15:42:28 +0100 | [diff] [blame] | 35 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | void ClConvertFp16ToFp32Workload::Execute() const |
| 39 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 40 | ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClConvertFp16ToFp32Workload_Execute", this->GetGuid()); |
Aron Virginas-Tar | a8e06ed | 2018-10-19 16:46:15 +0100 | [diff] [blame] | 41 | RunClFunction(m_Layer, CHECK_LOCATION()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 42 | } |
| 43 | |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 44 | arm_compute::Status ClConvertFp16ToFp32WorkloadValidate(const TensorInfo& input, const TensorInfo& output) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 45 | { |
| 46 | if (input.GetDataType() != DataType::Float16) |
| 47 | { |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 48 | return arm_compute::Status(arm_compute::ErrorCode::RUNTIME_ERROR, "Input should be Float16"); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 49 | } |
| 50 | if (output.GetDataType() != DataType::Float32) |
| 51 | { |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 52 | return arm_compute::Status(arm_compute::ErrorCode::RUNTIME_ERROR, "Output should be Float32"); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input); |
| 56 | const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output); |
| 57 | |
| 58 | const arm_compute::Status aclStatus = arm_compute::CLDepthConvertLayer::validate( |
| 59 | &aclInputInfo, &aclOutputInfo, g_AclConvertPolicy, 0); |
| 60 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 61 | return aclStatus; |
| 62 | } |
| 63 | |
David Monahan | ec81999 | 2022-02-10 14:47:13 +0000 | [diff] [blame] | 64 | void ClConvertFp16ToFp32Workload::ReplaceInputTensorHandle(ITensorHandle* tensorHandle, unsigned int slot) |
| 65 | { |
| 66 | ITensorHandle* backupHandle = this->m_Data.m_Inputs[slot]; |
| 67 | this->m_Data.m_Inputs[slot] = tensorHandle; |
| 68 | try |
| 69 | { |
| 70 | Reconfigure(); |
| 71 | } |
| 72 | catch(armnn::UnimplementedException& e) |
| 73 | { |
| 74 | // Cannot reconfigure, revert the slot back and throw the exception. |
| 75 | this->m_Data.m_Inputs[slot] = backupHandle; |
| 76 | throw e; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | // Replace output tensor handle with the given TensorHandle |
| 81 | void ClConvertFp16ToFp32Workload::ReplaceOutputTensorHandle(ITensorHandle* tensorHandle, unsigned int slot) |
| 82 | { |
Cathal Corbett | a3f4fba | 2022-03-21 09:27:08 +0000 | [diff] [blame] | 83 | ITensorHandle* backupHandle = this->m_Data.m_Outputs[slot]; |
| 84 | this->m_Data.m_Outputs[slot] = tensorHandle; |
David Monahan | ec81999 | 2022-02-10 14:47:13 +0000 | [diff] [blame] | 85 | try |
| 86 | { |
| 87 | Reconfigure(); |
| 88 | } |
| 89 | catch(armnn::UnimplementedException& e) |
| 90 | { |
| 91 | // Cannot reconfigure, revert the slot back and throw the exception. |
Cathal Corbett | a3f4fba | 2022-03-21 09:27:08 +0000 | [diff] [blame] | 92 | this->m_Data.m_Outputs[slot] = backupHandle; |
David Monahan | ec81999 | 2022-02-10 14:47:13 +0000 | [diff] [blame] | 93 | throw e; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | void ClConvertFp16ToFp32Workload::Reconfigure() |
| 98 | { |
Jim Flynn | 5e7335b | 2022-02-14 11:22:29 +0000 | [diff] [blame] | 99 | arm_compute::ICLTensor& input = static_cast<IClTensorHandle*>(m_Data.m_Inputs[0])->GetTensor(); |
| 100 | arm_compute::ICLTensor& output = static_cast<IClTensorHandle*>(m_Data.m_Outputs[0])->GetTensor(); |
| 101 | m_InputProxy->set(&input); |
| 102 | m_OutputProxy->set(&output); |
David Monahan | ec81999 | 2022-02-10 14:47:13 +0000 | [diff] [blame] | 103 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 104 | |
| 105 | } //namespace armnn |