blob: be13458d89a436db8baf05142116ed7e2def0f85 [file] [log] [blame]
Laurent Carlier749294b2020-06-01 09:03:17 +01001//
telsoa01c577f2c2018-08-31 09:22:23 +01002// Copyright © 2017 Arm Ltd. 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
22void RefConvertFp32ToFp16Workload::ExecuteAsync(WorkingMemDescriptor &workingMemDescriptor)
23{
24 Execute(workingMemDescriptor.m_Inputs, workingMemDescriptor.m_Outputs);
25}
26
27void RefConvertFp32ToFp16Workload::Execute(std::vector<ITensorHandle*> inputs,
28 std::vector<ITensorHandle*> outputs) const
29{
telsoa01c577f2c2018-08-31 09:22:23 +010030 ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefConvertFp32ToFp16Workload_Execute");
31
Finn Williamsb8181f72021-04-07 10:23:21 +010032 const float* const input = reinterpret_cast<const float*>(inputs[0]->Map());
33 Half* const output = reinterpret_cast<Half*>(outputs[0]->Map());
telsoa01c577f2c2018-08-31 09:22:23 +010034
35 // convert Fp32 input to Fp16 output
Finn Williamsb8181f72021-04-07 10:23:21 +010036 unsigned int numElements = GetTensorInfo(inputs[0]).GetNumElements();
telsoa01c577f2c2018-08-31 09:22:23 +010037 armnnUtils::FloatingPointConverter::ConvertFloat32To16(input, numElements, output);
38}
39
40} //namespace armnn