From 0a96e7b4eba303037e81e670c3b9dde313c0a24f Mon Sep 17 00:00:00 2001 From: seongwoo chae Date: Thu, 29 Aug 2024 14:13:07 +0900 Subject: [PATCH] [record-minmax] Revise driver script (#13820) This commit revises driver script for static analysis tool. ONE-DCO-1.0-Signed-off-by: seongwoo --- compiler/record-minmax/driver/Driver.cpp | 49 ++++++++---------------- 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/compiler/record-minmax/driver/Driver.cpp b/compiler/record-minmax/driver/Driver.cpp index 24a4ff80f02..8f25ebff5e8 100644 --- a/compiler/record-minmax/driver/Driver.cpp +++ b/compiler/record-minmax/driver/Driver.cpp @@ -30,6 +30,15 @@ void print_version(void) std::cout << vconone::get_copyright() << std::endl; } +template +T get_values_from(arser::Arser &arser, const std::string arg, const T default_value) +{ + if (arser[arg]) + return arser.get(arg); + + return default_value; +} + int entry(const int argc, char **argv) { using namespace record_minmax; @@ -105,45 +114,21 @@ int entry(const int argc, char **argv) auto input_model_path = arser.get("--input_model"); auto output_model_path = arser.get("--output_model"); - // Default values - std::string mode("percentile"); - float min_percentile = 1.0; - float max_percentile = 99.0; - uint32_t moving_avg_batch = 16; - float moving_avg_const = 0.1; - std::string input_data_format("h5"); - uint32_t num_threads = 1; - - if (arser["--min_percentile"]) - min_percentile = arser.get("--min_percentile"); - - if (arser["--num_threads"]) - num_threads = arser.get("--num_threads"); - + float min_percentile = ::get_values_from(arser, "--min_percentile", 1.0); + uint32_t num_threads = ::get_values_from(arser, "--num_threads", 1); if (num_threads < 1) throw std::runtime_error("The number of threads must be greater than zero"); - - if (arser["--max_percentile"]) - max_percentile = arser.get("--max_percentile"); - - if (arser["--mode"]) - mode = arser.get("--mode"); - - if (arser["--moving_avg_batch"]) - moving_avg_batch = arser.get("--moving_avg_batch"); - - if (arser["--moving_avg_const"]) - moving_avg_const = arser.get("--moving_avg_const"); - + float max_percentile = ::get_values_from(arser, "--max_percentile", 99.0); + std::string mode = ::get_values_from(arser, "--mode", "percentile"); + uint32_t moving_avg_batch = ::get_values_from(arser, "--moving_avg_batch", 16); + float moving_avg_const = ::get_values_from(arser, "--moving_avg_const", 0.1); if (mode != "percentile" && mode != "moving_average") throw std::runtime_error("Unsupported mode"); - + std::string input_data_format = + ::get_values_from(arser, "--input_data_format", "h5"); if (arser["--generate_profile_data"]) settings->set(luci::UserSettings::Key::ProfilingDataGen, true); - if (arser["--input_data_format"]) - input_data_format = arser.get("--input_data_format"); - std::unique_ptr computer; { if (mode == "percentile")