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