Laurent Carlier | 749294b | 2020-06-01 09:03:17 +0100 | [diff] [blame] | 1 | // |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [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 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | |
| 6 | #include "RefFakeQuantizationFloat32Workload.hpp" |
| 7 | |
| 8 | #include "RefWorkloadUtils.hpp" |
| 9 | |
| 10 | #include "Profiling.hpp" |
| 11 | |
| 12 | #include <boost/numeric/conversion/cast.hpp> |
| 13 | |
| 14 | namespace armnn |
| 15 | { |
| 16 | |
| 17 | void FakeQuantization(const float* inputData, float* outputData, uint32_t numElements, float min, float max) |
| 18 | { |
| 19 | float scale = (max - min) / 255.f; |
| 20 | int32_t offset = boost::numeric_cast<int32_t>((-min * 255.f) / (max - min)); |
| 21 | |
| 22 | for (uint32_t i = 0; i < numElements; i++) |
| 23 | { |
| 24 | outputData[i] = static_cast<float>(armnn::Quantize<uint8_t>(inputData[i], scale, offset)); |
| 25 | } |
| 26 | |
| 27 | } |
| 28 | |
| 29 | void RefFakeQuantizationFloat32Workload::Execute() const |
| 30 | { |
| 31 | ARMNN_SCOPED_PROFILING_EVENT(Compute::CpuRef, "RefFakeQuantizationFloat32Workload_Execute"); |
| 32 | |
| 33 | const TensorInfo& inputInfo = GetTensorInfo(m_Data.m_Inputs[0]); |
| 34 | |
| 35 | const float* inputData = GetInputTensorDataFloat(0, m_Data); |
| 36 | float* outputData = GetOutputTensorDataFloat(0, m_Data); |
| 37 | FakeQuantization(inputData, outputData, inputInfo.GetNumElements(), |
| 38 | m_Data.m_Parameters.m_Min, |
| 39 | m_Data.m_Parameters.m_Max); |
| 40 | } |
| 41 | |
| 42 | } //namespace armnn |