Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / compiler / circle-mpqsolver / src / bisection / VISQErrorApproximator.h
1 /*
2  * Copyright (c) 2023 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_VISQ_ERROR_APPROXIMATOR_H__
18 #define __MPQSOLVER_BISECTION_VISQ_ERROR_APPROXIMATOR_H__
19
20 #include <string>
21 #include <map>
22
23 namespace mpqsolver
24 {
25 namespace bisection
26 {
27
28 class VISQErrorApproximator final
29 {
30 public:
31   /**
32    * @brief constructor of VISQErrorApproximator
33    */
34   VISQErrorApproximator() = default;
35
36   /**
37    * @brief initiliaze by visq_data_path (throws on failure)
38    */
39   void init(const std::string &visq_data_path);
40
41   /**
42    * @brief approximate error introduced while quantizing node into Q8
43    */
44   float approximate(const std::string &node_name) const;
45
46 private:
47   /**
48    * @brief initiliaze by visq_data (throws on failure)
49    */
50   void init(std::istream &visq_data);
51
52 private:
53   std::string _visq_data_path;
54   std::map<std::string, float> _layer_errors;
55 };
56
57 } // namespace bisection
58 } // namespace mpqsolver
59
60 #endif // __MPQSOLVER_BISECTION_VISQ_ERROR_APPROXIMATOR_H__