blob: ce6c785329c3aa6a24df6b8d465add2d6106095e [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 "NeonConvertFp16ToFp32Workload.hpp"
Matteo Martincighe011d202019-11-28 11:35:47 +00007
8#include <armnnUtils/FloatingPointConverter.hpp>
telsoa01c577f2c2018-08-31 09:22:23 +01009
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +000010#include <Half.hpp>
Matteo Martincighe011d202019-11-28 11:35:47 +000011
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +000012#include <backendsCommon/WorkloadUtils.hpp>
telsoa01c577f2c2018-08-31 09:22:23 +010013
14namespace armnn
15{
16
17NeonConvertFp16ToFp32Workload::NeonConvertFp16ToFp32Workload(const ConvertFp16ToFp32QueueDescriptor& descriptor,
18 const WorkloadInfo& info)
19 : Float16ToFloat32Workload<ConvertFp16ToFp32QueueDescriptor>(descriptor, info)
20{
21 this->m_Data.ValidateInputsOutputs("NeonConvertFp16ToFp32Workload", 1, 1);
22 GatherTensorHandlePairs(descriptor, m_TensorHandlePairs);
23}
24
25void NeonConvertFp16ToFp32Workload::Execute() const
26{
Keith Davis2d0679f2021-08-05 11:35:00 +010027 ARMNN_SCOPED_PROFILING_EVENT_NEON_GUID("NeonConvertFp16ToFp32Workload_Execute", this->GetGuid());
telsoa01c577f2c2018-08-31 09:22:23 +010028
29 auto convertFunc = [](uint8_t* dst, const uint8_t* src, size_t size)
30 {
31 auto input = reinterpret_cast<const Half*>(src);
32 auto output = reinterpret_cast<float*>(dst);
33 size_t numElements = size/2; // 2 bytes per fp16
34 armnnUtils::FloatingPointConverter::ConvertFloat16To32(input, numElements, output);
35 };
36
37 for (const auto& pair : m_TensorHandlePairs)
38 {
39 CopyTensorContentsGeneric(pair.first, pair.second, convertFunc);
40 }
41}
42
David Monahanec819992022-02-10 14:47:13 +000043void NeonConvertFp16ToFp32Workload::ReplaceInputTensorHandle(ITensorHandle* tensorHandle, unsigned int slot)
44{
45 ITensorHandle* backupHandle = this->m_Data.m_Inputs[slot];
46 this->m_Data.m_Inputs[slot] = tensorHandle;
47 try
48 {
49 Reconfigure();
50 }
51 catch(armnn::UnimplementedException& e)
52 {
53 // Cannot reconfigure, revert the slot back and throw the exception.
54 this->m_Data.m_Inputs[slot] = backupHandle;
55 throw e;
56 }
57}
58
59// Replace output tensor handle with the given TensorHandle
60void NeonConvertFp16ToFp32Workload::ReplaceOutputTensorHandle(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
76void NeonConvertFp16ToFp32Workload::Reconfigure()
77{
78 throw armnn::UnimplementedException("Reconfigure not implemented for this workload");
79}
80
telsoa01c577f2c2018-08-31 09:22:23 +010081} //namespace armnn