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 "ClConvertFp32ToFp16Workload.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 | ClConvertFp32ToFp16Workload::ClConvertFp32ToFp16Workload( |
Sadik Armagan | e944475 | 2020-12-02 11:28:58 +0000 | [diff] [blame] | 18 | const ConvertFp32ToFp16QueueDescriptor& descriptor, |
| 19 | const WorkloadInfo& info, |
| 20 | const arm_compute::CLCompileContext& clCompileContext) : |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 21 | Float32ToFloat16Workload<ConvertFp32ToFp16QueueDescriptor>(descriptor, info) |
| 22 | { |
| 23 | this->m_Data.ValidateInputsOutputs("ClConvertFp32ToFp16Workload", 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 May | 9f6862d | 2021-10-22 15:42:28 +0100 | [diff] [blame] | 28 | { |
| 29 | ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "ClConvertFp32ToFp16Workload_configure"); |
| 30 | m_Layer.configure(clCompileContext, &input, &output, g_AclConvertPolicy, 0); |
| 31 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | void ClConvertFp32ToFp16Workload::Execute() const |
| 35 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 36 | ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClConvertFp32ToFp16Workload_Execute", this->GetGuid()); |
Aron Virginas-Tar | a8e06ed | 2018-10-19 16:46:15 +0100 | [diff] [blame] | 37 | RunClFunction(m_Layer, CHECK_LOCATION()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 38 | } |
| 39 | |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 40 | arm_compute::Status ClConvertFp32ToFp16WorkloadValidate(const TensorInfo& input, const TensorInfo& output) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 41 | { |
| 42 | if (input.GetDataType() != DataType::Float32) |
| 43 | { |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 44 | return arm_compute::Status(arm_compute::ErrorCode::RUNTIME_ERROR, "Input should be Float32"); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 45 | } |
| 46 | if (output.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, "Output should be Float16"); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 49 | } |
| 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 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 57 | return aclStatus; |
| 58 | } |
| 59 | |
David Monahan | ec81999 | 2022-02-10 14:47:13 +0000 | [diff] [blame] | 60 | void ClConvertFp32ToFp16Workload::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 |
| 77 | void ClConvertFp32ToFp16Workload::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 | |
| 93 | void ClConvertFp32ToFp16Workload::Reconfigure() |
| 94 | { |
| 95 | throw armnn::UnimplementedException("Reconfigure not implemented for this workload"); |
| 96 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 97 | |
Matthew Bentham | 14e4669 | 2018-09-20 15:35:30 +0100 | [diff] [blame] | 98 | } //namespace armnn |