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 "kernels/Dequantize.h"
18#include "kernels/Utils.h"
19#include "PALDequantize.h"
20
21namespace luci_interpreter
22{
23namespace kernels
24{
25
26Dequantize::Dequantize(const Tensor *input, Tensor *output) : Kernel({input}, {output}) {}
27
29{
30 LUCI_INTERPRETER_CHECK(input()->element_type() == loco::DataType::S8 ||
31 input()->element_type() == loco::DataType::U8 ||
32 input()->element_type() == loco::DataType::S16);
33
34 LUCI_INTERPRETER_CHECK(input()->scales().size() == 1);
35
36 if (input()->element_type() == loco::DataType::S16)
37 LUCI_INTERPRETER_CHECK(input()->zero_point() == 0);
38
39 LUCI_INTERPRETER_CHECK(output()->element_type() == loco::DataType::FLOAT32);
40
41 output()->resize(input()->shape());
42}
43
45{
46 tflite::DequantizationParams op_params;
47 op_params.zero_point = input()->zero_point();
48 op_params.scale = input()->scale();
49
50 switch (input()->element_type())
51 {
52 case loco::DataType::U8:
53 {
54 luci_interpreter_pal::Dequantize(op_params, getTensorShape(input()),
55 getTensorData<uint8_t>(input()), getTensorShape(output()),
56 getTensorData<float>(output()));
57 break;
58 }
59 case loco::DataType::S8:
60 {
61 luci_interpreter_pal::Dequantize(op_params, getTensorShape(input()),
62 getTensorData<int8_t>(input()), getTensorShape(output()),
63 getTensorData<float>(output()));
64 break;
65 }
66 case loco::DataType::S16:
67 {
68 luci_interpreter_pal::Dequantize(op_params, getTensorShape(input()),
69 getTensorData<int16_t>(input()), getTensorShape(output()),
70 getTensorData<float>(output()));
71 break;
72 }
73 default:
74 throw std::runtime_error("luci-intp Dequantize Unsupported type.");
75 }
76}
77
78} // namespace kernels
79} // namespace luci_interpreter
void resize(const Shape &new_shape)
Definition Tensor.cpp:56
float scale() const
Definition Tensor.h:109
int32_t zero_point() const
Definition Tensor.h:115
Dequantize(const Tensor *input, Tensor *output)
#define LUCI_INTERPRETER_CHECK(cond)
Definition Utils.h:36
tflite::RuntimeShape getTensorShape(const Tensor *tensor)
Definition Utils.h:194
int32_t size[5]
Definition Slice.cpp:35