2 * Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "kernels/Dequantize.h"
18 #include "kernels/Utils.h"
19 #include "PALDequantize.h"
21 namespace luci_interpreter
26 Dequantize::Dequantize(const Tensor *input, Tensor *output) : Kernel({input}, {output}) {}
28 void Dequantize::configure()
30 LUCI_INTERPRETER_CHECK(input()->element_type() == DataType::S8 ||
31 input()->element_type() == DataType::U8 ||
32 input()->element_type() == DataType::S16);
34 LUCI_INTERPRETER_CHECK(input()->scales().size() == 1);
36 if (input()->element_type() == DataType::S16)
37 LUCI_INTERPRETER_CHECK(input()->zero_point() == 0);
39 LUCI_INTERPRETER_CHECK(output()->element_type() == DataType::FLOAT32);
41 // TODO: enable it only if kernel with dynamic shapes
42 output()->resize(input()->shape());
45 void Dequantize::execute() const
47 tflite::DequantizationParams op_params;
48 op_params.zero_point = input()->zero_point();
49 op_params.scale = input()->scale();
51 switch (input()->element_type())
55 luci_interpreter_pal::Dequantize(op_params, getTensorShape(input()),
56 getTensorData<uint8_t>(input()), getTensorShape(output()),
57 getTensorData<float>(output()));
62 luci_interpreter_pal::Dequantize(op_params, getTensorShape(input()),
63 getTensorData<int8_t>(input()), getTensorShape(output()),
64 getTensorData<float>(output()));
69 luci_interpreter_pal::Dequantize(op_params, getTensorShape(input()),
70 getTensorData<int16_t>(input()), getTensorShape(output()),
71 getTensorData<float>(output()));
75 assert(false && "Unsupported type.");
79 } // namespace kernels
80 } // namespace luci_interpreter