Narumol Prangnawarat | 250d392 | 2020-03-30 16:11:04 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2020 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "NeonConvertFp32ToBf16Workload.hpp" |
| 7 | |
| 8 | #include <BFloat16.hpp> |
| 9 | #include <Profiling.hpp> |
| 10 | |
| 11 | #include <armnnUtils/FloatingPointConverter.hpp> |
| 12 | |
| 13 | #include <backendsCommon/WorkloadUtils.hpp> |
| 14 | |
| 15 | namespace armnn |
| 16 | { |
| 17 | |
| 18 | NeonConvertFp32ToBf16Workload::NeonConvertFp32ToBf16Workload(const ConvertFp32ToBf16QueueDescriptor& descriptor, |
| 19 | const WorkloadInfo& info) |
| 20 | : Float32ToBFloat16Workload<ConvertFp32ToBf16QueueDescriptor>(descriptor, info) |
| 21 | { |
| 22 | this->m_Data.ValidateInputsOutputs("NeonConvertFp32ToBf16Workload", 1, 1); |
| 23 | GatherTensorHandlePairs(descriptor, m_TensorHandlePairs); |
| 24 | } |
| 25 | |
| 26 | void NeonConvertFp32ToBf16Workload::Execute() const |
| 27 | { |
| 28 | ARMNN_SCOPED_PROFILING_EVENT_NEON("NeonConvertFp32ToBf16Workload_Execute"); |
| 29 | |
| 30 | auto convertFunc = [](uint8_t* dst, const uint8_t* src, size_t size) |
| 31 | { |
| 32 | auto input = reinterpret_cast<const float*>(src); |
| 33 | auto output = reinterpret_cast<BFloat16*>(dst); |
| 34 | size_t numElements = size/2; // 2 bytes per bf16 |
| 35 | armnnUtils::FloatingPointConverter::ConvertFloat32ToBFloat16(input, numElements, output); |
| 36 | }; |
| 37 | |
| 38 | for (const auto& pair : m_TensorHandlePairs) |
| 39 | { |
| 40 | CopyTensorContentsGeneric(pair.first, pair.second, convertFunc); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | } //namespace armnn |