ONE - On-device Neural Engine
Loading...
Searching...
No Matches
PALDequantize.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ONERT_MICRO_EXECUTE_PAL_DEQUANTIZE_COMMON_H
18#define ONERT_MICRO_EXECUTE_PAL_DEQUANTIZE_COMMON_H
19
20#include "core/OMRuntimeShape.h"
21#include "OMStatus.h"
22#include "core/OMKernelData.h"
23#include "PALUtils.h"
24
25#include <cmath>
26
27namespace onert_micro
28{
29namespace execute
30{
31namespace pal
32{
33
34template <typename InputT, typename OutputT>
35OMStatus Dequantize(const core::QuantizationParams op_params, const uint32_t flat_size,
36 const InputT *input_data, OutputT *output_data)
37{
38 const int32_t zero_point = op_params.zero_point;
39 const double scale = op_params.scale;
40
41 for (uint32_t i = 0; i < flat_size; i++)
42 {
43 const int32_t val = input_data[i];
44 const auto result = static_cast<OutputT>(scale * (val - zero_point));
45 output_data[i] = result;
46 }
47 return Ok;
48}
49} // namespace pal
50} // namespace execute
51} // namespace onert_micro
52
53#endif // ONERT_MICRO_EXECUTE_PAL_DEQUANTIZE_COMMON_H
OMStatus Dequantize(const core::QuantizationParams op_params, const uint32_t flat_size, const InputT *input_data, OutputT *output_data)