2 * Copyright (c) 2023 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 #ifndef __MPQSOLVER_DUMPER_H__
18 #define __MPQSOLVER_DUMPER_H__
20 #include <luci/IR/Module.h>
21 #include <luci/CircleQuantizer.h>
30 using LayerParam = luci::CircleQuantizer::Options::LayerParam;
31 using LayerParams = std::vector<std::shared_ptr<LayerParam>>;
37 Dumper(const std::string &dir_path);
40 * @brief sets model path for further usage
42 void set_model_path(const std::string &model_path);
45 * @brief dumps mpq configuration
46 * @param layers specific quantization parameters
47 * @param def_dtype default quantization data type
48 * @param step id of mpq configuration
50 void dump_MPQ_configuration(const LayerParams &layers, const std::string &def_dtype,
54 * @brief dumps final mpq configuration
55 * @param layers specific quantization parameters
56 * @param def_dtype default quantization data type
58 void dump_final_MPQ(const LayerParams &layers, const std::string &def_dtype) const;
61 * @brief dumps quantized module
62 * @param layers specific quantization parameters
63 * @param step id of quantized module
65 void dump_quantized(luci::Module *module, uint32_t step) const;
68 * @brief create file for error dumping
70 void prepare_for_error_dumping() const;
73 * @brief append error of Q8 quantization
75 void dump_Q8_error(float error) const;
78 * @brief append error of Q16 quantization
80 void dump_Q16_error(float error) const;
83 * @brief append error of mpq quantization
84 * @param error error of quantization
85 * @param step id of error
87 void dump_MPQ_error(float error, uint32_t step) const;
90 * @brief dump final error
91 * @param error final error of quantization
93 void dump_MPQ_error(float error) const;
96 void write_data_to_file(const std::string &path, const std::string &data) const;
97 void dump_MPQ_configuration(const LayerParams &layers, const std::string &def_dtype,
98 const std::string &path) const;
99 void prepare_directory(const std::string &dir_path) const;
100 void save_circle(luci::Module *module, std::string &path) const;
101 void dump_error(float error, const std::string &tag, const std::string &path) const;
102 std::string get_error_path() const { return _dir_path + "/errors" + ".mpq.txt"; }
105 std::string _dir_path;
106 std::string _model_path;
111 } // namespace mpqsolver
113 #endif //__MPQSOLVER_DUMPER_H__