Imported Upstream version 1.22.1
[platform/core/ml/nnfw.git] / compiler / circle-mpqsolver / src / bisection / Evaluator.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_EVALUATOR_H__
18 #define __MPQSOLVER_BISECTION_EVALUATOR_H__
19
20 #include "ErrorMetric.h"
21
22 #include <luci/IR/Module.h>
23 #include <luci/CircleQuantizer.h>
24
25 #include <string>
26 #include <vector>
27
28 namespace mpqsolver
29 {
30 namespace bisection
31 {
32
33 class DatasetEvaluator final
34 {
35 public:
36   /**
37    * @brief create Evaluator for comparing output of ref_module on h5file
38    */
39   DatasetEvaluator(const luci::Module *ref_module, const std::string &h5file,
40                    const ErrorMetric &metric);
41   DatasetEvaluator() = delete;
42   ~DatasetEvaluator() = default;
43
44   /**
45    * @brief evaluate trgt_fq_module (fake-quantized)
46    * returns error-metric
47    */
48   float evaluate(const luci::Module *trgt_fq_module) const;
49
50 private:
51   /**
52    * @brief throws if there is something wrong with the module
53    */
54   void validate(const luci::Module *module) const;
55
56 private:
57   const luci::Module *_ref_module = nullptr;
58   std::string _h5file;
59   WholeOutput _ref_output;
60   const ErrorMetric *_metric = nullptr;
61 };
62
63 } // namespace bisection
64 } // namespace mpqsolver
65
66 #endif //__MPQSOLVER_BISECTION_EVALUATOR_H__