telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. 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 | |
Sadik Armagan | e944475 | 2020-12-02 11:28:58 +0000 | [diff] [blame] | 28 | m_Layer.configure(clCompileContext, &input, &output, g_AclConvertPolicy, 0); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | void ClConvertFp32ToFp16Workload::Execute() const |
| 32 | { |
Keith Davis | bcd860a | 2021-08-05 14:20:33 +0100 | [diff] [blame] | 33 | ARMNN_SCOPED_PROFILING_EVENT_CL_GUID("ClConvertFp32ToFp16Workload_Execute", this->GetGuid()); |
Aron Virginas-Tar | a8e06ed | 2018-10-19 16:46:15 +0100 | [diff] [blame] | 34 | RunClFunction(m_Layer, CHECK_LOCATION()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 35 | } |
| 36 | |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 37 | arm_compute::Status ClConvertFp32ToFp16WorkloadValidate(const TensorInfo& input, const TensorInfo& output) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 38 | { |
| 39 | if (input.GetDataType() != DataType::Float32) |
| 40 | { |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 41 | return arm_compute::Status(arm_compute::ErrorCode::RUNTIME_ERROR, "Input should be Float32"); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 42 | } |
| 43 | if (output.GetDataType() != DataType::Float16) |
| 44 | { |
arovir01 | 085f0a4 | 2018-10-08 14:48:19 +0100 | [diff] [blame] | 45 | return arm_compute::Status(arm_compute::ErrorCode::RUNTIME_ERROR, "Output should be Float16"); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | const arm_compute::TensorInfo aclInputInfo = BuildArmComputeTensorInfo(input); |
| 49 | const arm_compute::TensorInfo aclOutputInfo = BuildArmComputeTensorInfo(output); |
| 50 | |
| 51 | const arm_compute::Status aclStatus = arm_compute::CLDepthConvertLayer::validate( |
| 52 | &aclInputInfo, &aclOutputInfo, g_AclConvertPolicy, 0); |
| 53 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 54 | return aclStatus; |
| 55 | } |
| 56 | |
| 57 | |
Matthew Bentham | 14e4669 | 2018-09-20 15:35:30 +0100 | [diff] [blame] | 58 | } //namespace armnn |