IVGCVSW-1946: Remove armnn/src from the include paths
[platform/upstream/armnn.git] / src / backends / neon / workloads / NeonConvertFp32ToFp16Workload.cpp
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5
6 #include "NeonConvertFp32ToFp16Workload.hpp"
7
8 #include <Half.hpp>
9 #include <FloatingPointConverter.hpp>
10 #include <Profiling.hpp>
11 #include <backendsCommon/WorkloadUtils.hpp>
12
13 namespace armnn
14 {
15
16 NeonConvertFp32ToFp16Workload::NeonConvertFp32ToFp16Workload(const ConvertFp32ToFp16QueueDescriptor& descriptor,
17                                                              const WorkloadInfo& info)
18     : Float32ToFloat16Workload<ConvertFp32ToFp16QueueDescriptor>(descriptor, info)
19 {
20     this->m_Data.ValidateInputsOutputs("NeonConvertFp32ToFp16Workload", 1, 1);
21     GatherTensorHandlePairs(descriptor, m_TensorHandlePairs);
22 }
23
24 void NeonConvertFp32ToFp16Workload::Execute() const
25 {
26     ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonConvertFp32ToFp16Workload_Execute");
27
28     auto convertFunc = [](uint8_t* dst, const uint8_t* src, size_t size)
29         {
30             auto input = reinterpret_cast<const float*>(src);
31             auto output = reinterpret_cast<Half*>(dst);
32             size_t numElements = size/2; // 2 bytes per fp16
33             armnnUtils::FloatingPointConverter::ConvertFloat32To16(input, numElements, output);
34         };
35
36     for (const auto& pair : m_TensorHandlePairs)
37     {
38         CopyTensorContentsGeneric(pair.first, pair.second, convertFunc);
39     }
40 }
41
42 } //namespace armnn