ArmNN
 25.11
Loading...
Searching...
No Matches
RefFakeQuantizationFloat32Workload.cpp
Go to the documentation of this file.
1//
2// Copyright © 2017-2018,2020-2024 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
7
9
10#include "Profiling.hpp"
11
13
14namespace armnn
15{
16
17void 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 = armnn::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
30{
31 Execute(m_Data.m_Inputs, m_Data.m_Outputs);
32}
33
34void RefFakeQuantizationFloat32Workload::Execute(std::vector<ITensorHandle*> inputs,
35 std::vector<ITensorHandle*> outputs) const
36{
37 ARMNN_SCOPED_PROFILING_EVENT_REF_NAME_GUID("RefFakeQuantizationFloat32Workload_Execute");
38
39 const TensorInfo& inputInfo = GetTensorInfo(inputs[0]);
40
41 const float* inputData = reinterpret_cast<const float*>(inputs[0]->Map());
42 float* outputData = reinterpret_cast<float*>(outputs[0]->Map());
43 FakeQuantization(inputData, outputData, inputInfo.GetNumElements(),
44 m_Data.m_Parameters.m_Min,
45 m_Data.m_Parameters.m_Max);
46}
47
48} //namespace armnn
#define ARMNN_SCOPED_PROFILING_EVENT_REF_NAME_GUID(label)
Creates a profiling event that uses GetGuid() and GetName() from the calling class.
QueueDescriptor m_Data
Definition Workload.hpp:74
unsigned int GetNumElements() const
Definition Tensor.hpp:198
Copyright (c) 2021 ARM Limited and Contributors.
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
armnn::TensorInfo GetTensorInfo(unsigned int numberOfBatches, unsigned int numberOfChannels, unsigned int height, unsigned int width, const armnn::DataLayout dataLayout, const armnn::DataType dataType)