blob: 3c7c84a950837655ccb3929e0a55ed29d2558654 [file] [log] [blame]
Laurent Carlier749294b2020-06-01 09:03:17 +01001//
Mike Kelly7cbe7812023-07-25 17:37:33 +01002// Copyright © 2017-2023 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 "RefConvertFp32ToFp16Workload.hpp"
telsoa01c577f2c2018-08-31 09:22:23 +01007#include "RefWorkloadUtils.hpp"
telsoa01c577f2c2018-08-31 09:22:23 +01008#include "Profiling.hpp"
9
Matteo Martincighe011d202019-11-28 11:35:47 +000010#include <armnnUtils/FloatingPointConverter.hpp>
11
12#include <Half.hpp>
arovir01616e7752018-10-01 17:08:59 +010013
telsoa01c577f2c2018-08-31 09:22:23 +010014namespace armnn
15{
16
17void RefConvertFp32ToFp16Workload::Execute() const
18{
Finn Williamsb8181f72021-04-07 10:23:21 +010019 Execute(m_Data.m_Inputs, m_Data.m_Outputs);
20}
21
Matthew Sloyan2d213a72022-06-30 17:13:04 +010022void RefConvertFp32ToFp16Workload::ExecuteAsync(ExecutionData& executionData)
Finn Williamsb8181f72021-04-07 10:23:21 +010023{
Matthew Sloyan2d213a72022-06-30 17:13:04 +010024 WorkingMemDescriptor* workingMemDescriptor = static_cast<WorkingMemDescriptor*>(executionData.m_Data);
25 Execute(workingMemDescriptor->m_Inputs, workingMemDescriptor->m_Outputs);
Finn Williamsb8181f72021-04-07 10:23:21 +010026}
27
28void RefConvertFp32ToFp16Workload::Execute(std::vector<ITensorHandle*> inputs,
29 std::vector<ITensorHandle*> outputs) const
30{
Mike Kelly7cbe7812023-07-25 17:37:33 +010031 ARMNN_SCOPED_PROFILING_EVENT_REF_NAME_GUID("RefConvertFp32ToFp16Workload_Execute");
telsoa01c577f2c2018-08-31 09:22:23 +010032
Finn Williamsb8181f72021-04-07 10:23:21 +010033 const float* const input = reinterpret_cast<const float*>(inputs[0]->Map());
34 Half* const output = reinterpret_cast<Half*>(outputs[0]->Map());
telsoa01c577f2c2018-08-31 09:22:23 +010035
36 // convert Fp32 input to Fp16 output
Finn Williamsb8181f72021-04-07 10:23:21 +010037 unsigned int numElements = GetTensorInfo(inputs[0]).GetNumElements();
telsoa01c577f2c2018-08-31 09:22:23 +010038 armnnUtils::FloatingPointConverter::ConvertFloat32To16(input, numElements, output);
39}
40
41} //namespace armnn