Laurent Carlier | 749294b | 2020-06-01 09:03:17 +0100 | [diff] [blame] | 1 | // |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 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 "RefConvertFp32ToFp16Workload.hpp" |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 7 | #include "RefWorkloadUtils.hpp" |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 8 | #include "Profiling.hpp" |
| 9 | |
Matteo Martincigh | e011d20 | 2019-11-28 11:35:47 +0000 | [diff] [blame] | 10 | #include <armnnUtils/FloatingPointConverter.hpp> |
| 11 | |
| 12 | #include <Half.hpp> |
arovir01 | 616e775 | 2018-10-01 17:08:59 +0100 | [diff] [blame] | 13 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 14 | namespace armnn |
| 15 | { |
| 16 | |
| 17 | void RefConvertFp32ToFp16Workload::Execute() const |
| 18 | { |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 19 | Execute(m_Data.m_Inputs, m_Data.m_Outputs); |
| 20 | } |
| 21 | |
| 22 | void RefConvertFp32ToFp16Workload::ExecuteAsync(WorkingMemDescriptor &workingMemDescriptor) |
| 23 | { |
| 24 | Execute(workingMemDescriptor.m_Inputs, workingMemDescriptor.m_Outputs); |
| 25 | } |
| 26 | |
| 27 | void RefConvertFp32ToFp16Workload::Execute(std::vector<ITensorHandle*> inputs, |
| 28 | std::vector<ITensorHandle*> outputs) const |
| 29 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 30 | ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefConvertFp32ToFp16Workload_Execute"); |
| 31 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 32 | const float* const input = reinterpret_cast<const float*>(inputs[0]->Map()); |
| 33 | Half* const output = reinterpret_cast<Half*>(outputs[0]->Map()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 34 | |
| 35 | // convert Fp32 input to Fp16 output |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 36 | unsigned int numElements = GetTensorInfo(inputs[0]).GetNumElements(); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 37 | armnnUtils::FloatingPointConverter::ConvertFloat32To16(input, numElements, output); |
| 38 | } |
| 39 | |
| 40 | } //namespace armnn |