Imported Upstream version 1.22.1
[platform/core/ml/nnfw.git] / compiler / circle-mpqsolver / src / bisection / Quantizer.h
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 #ifndef __MPQSOLVER_BISECTION_QUANTIZER_H__
18 #define __MPQSOLVER_BISECTION_QUANTIZER_H__
19
20 #include <luci/IR/Module.h>
21 #include <luci/CircleQuantizer.h>
22
23 #include <string>
24 #include <vector>
25 #include <memory>
26
27 namespace mpqsolver
28 {
29 namespace bisection
30 {
31
32 using LayerParam = luci::CircleQuantizer::Options::LayerParam;
33 using LayerParams = std::vector<std::shared_ptr<LayerParam>>;
34
35 class Quantizer
36 {
37 public:
38   Quantizer(const std::string &input_dtype, const std::string &output_type);
39
40   /**
41    * @brief quantize recorded module (min/max initialized) with specified parameters
42    * returns true on success
43    */
44   bool quantize(luci::Module *module, const std::string &quant_dtype, LayerParams &layer_params);
45
46   /**
47    * @brief fake_quantize recorded module (min/max initialized) with specified parameters
48    * returns true on success
49    */
50   bool fake_quantize(luci::Module *module, const std::string &quant_dtype,
51                      LayerParams &layer_params);
52
53 private:
54   std::string _input_dtype = "uint8";
55   std::string _output_dtype = "uint8";
56 };
57
58 } // namespace bisection
59 } // namespace mpqsolver
60
61 #endif //__MPQSOLVER_BISECTION_QUANTIZER_H__