ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Dequantize.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 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#include "Builders.h"
18#include "kernels/Utils.h"
19#include "SISOKernel.h"
20
21#include "PALDequantize.h"
22
23namespace luci_interpreter
24{
25
26void configure_kernel_CircleDequantize(const circle::Operator *cur_op,
27 BaseRuntimeGraph *runtime_graph)
28{
29#ifndef DIS_QUANT
30 kernels::SISOKernel kernel(cur_op, runtime_graph);
31
32 LUCI_INTERPRETER_CHECK(Tensor::num_elements(kernel.input()) ==
33 Tensor::num_elements(kernel.output()));
34 LUCI_INTERPRETER_CHECK(Tensor::num_dims(kernel.input()) == Tensor::num_dims(kernel.output()));
35 LUCI_INTERPRETER_CHECK(!Tensor::scales(kernel.input()).empty());
36 LUCI_INTERPRETER_CHECK(!Tensor::zero_points(kernel.input()).empty());
37#else
38 assert(false && "Remove DIS_QUANT flag");
39#endif // DIS_QUANT
40}
41
42void execute_kernel_CircleDequantize(const circle::Operator *cur_op,
43 BaseRuntimeGraph *runtime_graph)
44{
45#ifndef DIS_QUANT
46 kernels::SISOKernel kernel(cur_op, runtime_graph);
47
48 const auto *input_data = runtime_graph->getDataByTensor(kernel.input());
49 assert(input_data);
50
51 auto *output_data = runtime_graph->getDataByTensor(kernel.output());
52 assert(output_data);
53
54 const int flat_size = kernels::getTensorRuntimeShape(kernel.input(), runtime_graph).flatSize();
55
56 switch (Tensor::element_type(kernel.output()))
57 {
58#ifndef DIS_FLOAT
59 case DataType::FLOAT32:
60 {
62 params.zero_point = Tensor::zero_point(kernel.input());
63 params.scale = Tensor::scale(kernel.input());
64 switch (Tensor::element_type(kernel.input()))
65 {
66 case DataType::S8:
67 luci_interpreter_pal::Dequantize(params, flat_size,
68 kernels::getTensorData<int8_t>(input_data),
69 kernels::getTensorData<float>(output_data));
70 break;
71 case DataType::U8:
72 luci_interpreter_pal::Dequantize(params, flat_size,
73 kernels::getTensorData<uint8_t>(input_data),
74 kernels::getTensorData<float>(output_data));
75 break;
76 case DataType::S16:
77 luci_interpreter_pal::Dequantize(params, flat_size,
78 kernels::getTensorData<int16_t>(input_data),
79 kernels::getTensorData<float>(output_data));
80 break;
81 default:
82 assert(false && "Unsupported type");
83 }
84 break;
85 }
86#endif // DIS_FLOAT
87 default:
88 assert(false && "Unsupported type");
89 }
90#else
91 assert(false && "Remove DIS_QUANT flag");
92#endif // DIS_QUANT
93}
94
95} // namespace luci_interpreter
uint8_t * getDataByTensor(const circle::Tensor *raw_tensor)
const circle::Tensor * output() const
Definition SISOKernel.h:47
const circle::Tensor * input() const
Definition SISOKernel.h:46
#define LUCI_INTERPRETER_CHECK(cond)
Definition Utils.h:36
luci_interpreter::RuntimeShape getTensorRuntimeShape(const circle::Tensor *circle_tensor, BaseRuntimeGraph *runtime_graph)
Definition Utils.cpp:29
void execute_kernel_CircleDequantize(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)
void configure_kernel_CircleDequantize(const circle::Operator *cur_op, BaseRuntimeGraph *runtime_graph)