ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Dequantize.cpp
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
18#include "OMStatus.h"
20#include "core/OMUtils.h"
21#include "PALDequantize.h"
22#include "core/OMRuntimeShape.h"
23
24#include "execute/OMUtils.h"
25
26using namespace onert_micro;
27using namespace onert_micro::execute;
28
29namespace
30{
31
32constexpr uint32_t inputTensorIdx = 0;
33constexpr uint32_t outputTensorIdx = 0;
34
35} // namespace
36
37// NOTE: doesnt currently support dynamic shapes
38namespace onert_micro
39{
40namespace execute
41{
42
44{
45 const circle::Tensor *input = nullptr;
46 const circle::Tensor *output = nullptr;
47
48 uint8_t *input_data = nullptr;
49 uint8_t *output_data = nullptr;
50
51 SISOHeader(execute_args, &input, &output, &input_data, &output_data);
52
53 assert(output->type() == circle::TensorType_FLOAT32);
54
55 OMStatus status = Ok;
56 switch (input->type())
57 {
58#ifndef DIS_FLOAT
59 case circle::TensorType_INT8:
60 {
61 assert(input->quantization() != nullptr);
62 assert(input->quantization()->scale() != nullptr and
63 input->quantization()->scale()->size() == 1);
64 assert(input->quantization()->zero_point() != nullptr and
65 input->quantization()->zero_point()->size() == 1);
67 params.zero_point = input->quantization()->zero_point()->operator[](0);
68 params.scale = input->quantization()->scale()->operator[](0);
69
70 status = pal::Dequantize(params, core::OMRuntimeShape(input).flatSize(),
71 core::utils::castInputData<int8_t>(input_data),
72 core::utils::castOutputData<float>(output_data));
73 }
74 break;
75#endif // DIS_FLOAT
76 default:
77 {
78 status = UnsupportedType;
79 assert(false && "Unsupported type.");
80 }
81 }
82
83 return status;
84}
85
86} // namespace execute
87} // namespace onert_micro
constexpr uint32_t outputTensorIdx
OMStatus Dequantize(const core::QuantizationParams op_params, const uint32_t flat_size, const InputT *input_data, OutputT *output_data)
OMStatus execute_kernel_CircleDequantize(const OMExecuteArgs &execute_args)
OMStatus SISOHeader(const OMExecuteArgs &execute_args, const circle::Tensor **input, const circle::Tensor **output, uint8_t **input_data, uint8_t **output_data)
Definition OMUtils.cpp:159
@ UnsupportedType
Definition OMStatus.h:26