Narumol Prangnawarat | ea54a01 | 2020-03-16 16:36:10 +0000 | [diff] [blame] | 1 | // |
Matthew Sloyan | 21a6a1a | 2022-06-30 17:13:04 +0100 | [diff] [blame] | 2 | // Copyright © 2022 Arm Ltd and Contributors. All rights reserved. |
Narumol Prangnawarat | ea54a01 | 2020-03-16 16:36:10 +0000 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "RefConvertFp32ToBf16Workload.hpp" |
| 7 | #include "RefWorkloadUtils.hpp" |
| 8 | |
| 9 | #include <armnnUtils/FloatingPointConverter.hpp> |
| 10 | |
| 11 | #include <BFloat16.hpp> |
| 12 | |
| 13 | namespace armnn |
| 14 | { |
| 15 | |
| 16 | void RefConvertFp32ToBf16Workload::Execute() const |
| 17 | { |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 18 | Execute(m_Data.m_Inputs, m_Data.m_Outputs); |
| 19 | } |
| 20 | |
Matthew Sloyan | 21a6a1a | 2022-06-30 17:13:04 +0100 | [diff] [blame] | 21 | void RefConvertFp32ToBf16Workload::ExecuteAsync(ExecutionData& executionData) |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 22 | { |
Matthew Sloyan | 21a6a1a | 2022-06-30 17:13:04 +0100 | [diff] [blame] | 23 | WorkingMemDescriptor* workingMemDescriptor = static_cast<WorkingMemDescriptor*>(executionData.m_Data); |
| 24 | Execute(workingMemDescriptor->m_Inputs, workingMemDescriptor->m_Outputs); |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | void RefConvertFp32ToBf16Workload::Execute(std::vector<ITensorHandle*> inputs, |
| 28 | std::vector<ITensorHandle*> outputs) const |
| 29 | { |
Narumol Prangnawarat | ea54a01 | 2020-03-16 16:36:10 +0000 | [diff] [blame] | 30 | ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefConvertFp32ToBf16Workload_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 | BFloat16* const output = reinterpret_cast<BFloat16*>(outputs[0]->Map()); |
Narumol Prangnawarat | ea54a01 | 2020-03-16 16:36:10 +0000 | [diff] [blame] | 34 | |
Finn Williams | b8181f7 | 2021-04-07 10:23:21 +0100 | [diff] [blame] | 35 | unsigned int numElements = GetTensorInfo(inputs[0]).GetNumElements(); |
Narumol Prangnawarat | ea54a01 | 2020-03-16 16:36:10 +0000 | [diff] [blame] | 36 | armnnUtils::FloatingPointConverter::ConvertFloat32ToBFloat16(input, numElements, output); |
| 37 | } |
| 38 | |
| 39 | } //namespace armnn |