ArmNN
 25.02
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
8 #include "RefWorkloadUtils.hpp"
9 
10 #include "Profiling.hpp"
11 
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 = 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 {
32 }
33 
34 void 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.
const TensorInfo & GetTensorInfo(const ITensorHandle *tensorHandle)
float32 helpers
void FakeQuantization(const float *inputData, float *outputData, uint32_t numElements, float min, float max)
std::vector< ITensorHandle * > m_Inputs
std::vector< ITensorHandle * > m_Outputs