diff --git a/src/evaluator/quantizer.cpp b/src/evaluator/quantizer.cpp index 8795dc618a..5848f4879d 100644 --- a/src/evaluator/quantizer.cpp +++ b/src/evaluator/quantizer.cpp @@ -44,14 +44,12 @@ static std::vector smooth_distribution(const std::vector &p, const { auto it = p.begin(); std::generate(is_zeros.begin(), is_zeros.end(), - [&it]() - { return static_cast(*(it++) == 0.f); }); + [&it]() { return static_cast(*(it++) == 0.f); }); } { auto it = p.begin(); std::generate(is_nonzeros.begin(), is_nonzeros.end(), - [&it]() - { return static_cast(*(it++) != 0.f); }); + [&it]() { return static_cast(*(it++) != 0.f); }); } size_t n_zeros = std::accumulate(is_zeros.begin(), is_zeros.end(), 0); size_t n_nonzeros = p.size() - n_zeros; @@ -144,8 +142,7 @@ void run_kld_m2(std::vector &src_bins_, std::optional::max(); - auto kld = [&](size_t lower_threshold, size_t upper_threshold) - { + auto kld = [&](size_t lower_threshold, size_t upper_threshold) { auto src_range = upper_threshold - lower_threshold; auto src_per_bin = src_range / dest_bins; @@ -176,8 +173,7 @@ void run_kld_m2(std::vector &src_bins_, std::optional &src_bins_, std::optional ups2_q_dist(src_bins_.size()); // left outliers auto count = 0.f; - count += std::count_if(src_bins_.begin(), src_bins_.begin() + lower_threshold + src_per_bin, [](float v) - { return v; }); + count += std::count_if(src_bins_.begin(), src_bins_.begin() + lower_threshold + src_per_bin, [](float v) { return v; }); auto value = std::reduce(src_bins_.begin(), src_bins_.begin() + lower_threshold + src_per_bin) / count; for (size_t i = 0; i < lower_threshold + src_per_bin; i++) { @@ -205,8 +200,7 @@ void run_kld_m2(std::vector &src_bins_, std::optional &ops) { - auto visitor = make_relay_ir_visitor([&](node &node) - { + auto visitor = make_relay_ir_visitor([&](node &node) { if (node.inputs().size() == 1) { auto it = quant_ranges_.find(node.input_at(0).connection()); @@ -669,8 +661,7 @@ void quantizer::histogram::finish() count += (end - right_lower); } - count += std::count_if(range_dist.begin() + left_upper, range_dist.begin() + right_lower, [](float v) - { return v; }); + count += std::count_if(range_dist.begin() + left_upper, range_dist.begin() + right_lower, [](float v) { return v; }); if (!count) continue; auto upsample_value = q_dist[i] / count; diff --git a/src/nncase/compiler.cpp b/src/nncase/compiler.cpp index d955a5a4f7..c6c6e95466 100644 --- a/src/nncase/compiler.cpp +++ b/src/nncase/compiler.cpp @@ -438,22 +438,19 @@ class compiler_impl : public compiler void pre_process(ir::graph &graph, compile_options &cmp_options) { using namespace ir::transforms; - run_passes("pre_process", graph, [&]([[maybe_unused]] const module_type_t &module_type, ir::transforms::pass_manager &pmgr) - { pmgr.add_pass( - cmp_options.mean, cmp_options.std, cmp_options.input_range, cmp_options.input_shape, cmp_options.swapRB, input_layout_, cmp_options.input_type, cmp_options.quant_type, real_inlayout_, cmp_options.letterbox_value); }); + run_passes("pre_process", graph, [&]([[maybe_unused]] const module_type_t &module_type, ir::transforms::pass_manager &pmgr) { pmgr.add_pass( + cmp_options.mean, cmp_options.std, cmp_options.input_range, cmp_options.input_shape, cmp_options.swapRB, input_layout_, cmp_options.input_type, cmp_options.quant_type, real_inlayout_, cmp_options.letterbox_value); }); } void post_process(ir::graph &graph, compile_options &cmp_options) { using namespace ir::transforms; - run_passes("post_process", graph, [&]([[maybe_unused]] const module_type_t &module_type, ir::transforms::pass_manager &pmgr) - { pmgr.add_pass( - cmp_options.output_layout, real_outlayout_); }); + run_passes("post_process", graph, [&]([[maybe_unused]] const module_type_t &module_type, ir::transforms::pass_manager &pmgr) { pmgr.add_pass( + cmp_options.output_layout, real_outlayout_); }); } void optimize_target_independent(ir::graph &graph) { - run_passes("target_indep", graph, [&](const module_type_t &module_type, ir::transforms::pass_manager &pmgr) - { target_->register_target_independent_passes(module_type, pmgr); }); + run_passes("target_indep", graph, [&](const module_type_t &module_type, ir::transforms::pass_manager &pmgr) { target_->register_target_independent_passes(module_type, pmgr); }); } void optimize_merge_module_regions(ir::graph &graph) @@ -461,8 +458,7 @@ class compiler_impl : public compiler std::cout << "7.1. Merge module regions..." << std::endl; using namespace ir::transforms; - run_passes("mark_noaction", graph, [&]([[maybe_unused]] const module_type_t &module_type, ir::transforms::pass_manager &pmgr) - { + run_passes("mark_noaction", graph, [&]([[maybe_unused]] const module_type_t &module_type, ir::transforms::pass_manager &pmgr) { pmgr.add_pass(); pmgr.add_pass(); pmgr.add_pass(); }); @@ -480,8 +476,7 @@ class compiler_impl : public compiler void optimize_benchmark(ir::graph &graph) { using namespace ir::transforms; - run_passes("mark_noaction", graph, [&]([[maybe_unused]] const module_type_t &module_type, ir::transforms::pass_manager &pmgr) - { pmgr.add_pass(); }); + run_passes("mark_noaction", graph, [&]([[maybe_unused]] const module_type_t &module_type, ir::transforms::pass_manager &pmgr) { pmgr.add_pass(); }); dump_graph(graph, "optimize_benchmark"); } @@ -489,8 +484,7 @@ class compiler_impl : public compiler { using namespace ir::transforms; - run_passes("buffer_fusion", graph, [&]([[maybe_unused]] const module_type_t &module_type, ir::transforms::pass_manager &pmgr) - { + run_passes("buffer_fusion", graph, [&]([[maybe_unused]] const module_type_t &module_type, ir::transforms::pass_manager &pmgr) { pmgr.add_pass(); pmgr.add_pass(); pmgr.add_pass(); @@ -507,34 +501,29 @@ class compiler_impl : public compiler { using namespace ir::transforms; - run_passes("target_dependent_after_buffer_fusion", graph, [&](const module_type_t &module_type, ir::transforms::pass_manager &pmgr) - { + run_passes("target_dependent_after_buffer_fusion", graph, [&](const module_type_t &module_type, ir::transforms::pass_manager &pmgr) { target_->register_target_dependent_after_buffer_fusion_passes(module_type, pmgr); pmgr.add_pass(); }); } void optimize_target_dependent(ir::graph &graph, bool use_ptq) { - run_passes("target_dep", graph, [&](const module_type_t &module_type, ir::transforms::pass_manager &pmgr) - { target_->register_target_dependent_passes(module_type, pmgr, use_ptq, compile_options_.split_w_to_act); }); + run_passes("target_dep", graph, [&](const module_type_t &module_type, ir::transforms::pass_manager &pmgr) { target_->register_target_dependent_passes(module_type, pmgr, use_ptq, compile_options_.split_w_to_act); }); } void optimize_target_dependent_after_quant(ir::graph &graph) { - run_passes("target_dep_after_quant", graph, [&](const module_type_t &module_type, ir::transforms::pass_manager &pmgr) - { target_->register_target_dependent_after_quantization_passes(module_type, pmgr); }); + run_passes("target_dep_after_quant", graph, [&](const module_type_t &module_type, ir::transforms::pass_manager &pmgr) { target_->register_target_dependent_after_quantization_passes(module_type, pmgr); }); } void add_quantize_annotation(ir::graph &graph) { - run_passes("quantize_annotation", graph, [&](const module_type_t &module_type, ir::transforms::pass_manager &pmgr) - { target_->register_quantize_annotation_passes(module_type, pmgr); }); + run_passes("quantize_annotation", graph, [&](const module_type_t &module_type, ir::transforms::pass_manager &pmgr) { target_->register_quantize_annotation_passes(module_type, pmgr); }); } void quantize_graph(ir::graph &graph, ir::evaluator &evaluator) { - auto graph_runner = [&](ir::graph &graph) - { + auto graph_runner = [&](ir::graph &graph) { ir::transforms::pass_manager pmgr(graph, *target_); auto quant = evaluator.quantizer(graph.module_type()); if (compile_options_.input_type != "float32" && compile_options_.preprocess == true) @@ -579,15 +568,13 @@ class compiler_impl : public compiler if (step != eval_step::after_import) { - auto calib_method = std::visit([](auto &options) - { return to_calibrate_method(options.calibrate_method); }, + auto calib_method = std::visit([](auto &options) { return to_calibrate_method(options.calibrate_method); }, ptq_options_); evaluator.enable_ptq(*target_, calib_method); } else { - auto calib_method = std::visit([](auto &options) - { return to_calibrate_method(options.calibrate_method); }, + auto calib_method = std::visit([](auto &options) { return to_calibrate_method(options.calibrate_method); }, dump_range_options_); evaluator.enable_ptq(*target_, calib_method); } @@ -753,8 +740,7 @@ class compiler_impl : public compiler template void run_passes(std::string_view name, ir::graph &root_graph, Callable &®ister_passes) { - auto graph_runner = [&](ir::graph &graph) - { + auto graph_runner = [&](ir::graph &graph) { ir::transforms::pass_manager pmgr(graph, *target_); if (compile_options_.dump_ir) pmgr.dump_dir(compile_options_.dump_dir);