From 2f6960613ce285cea1aed8c5cc396be6bf2fecb7 Mon Sep 17 00:00:00 2001 From: Chi Lo Date: Mon, 11 Aug 2025 11:58:42 -0700 Subject: [PATCH 01/10] update --- .../test/perftest/command_args_parser.cc | 38 ++++--------------- onnxruntime/test/perftest/strings_helper.cc | 28 ++++++++++++++ onnxruntime/test/perftest/strings_helper.h | 2 + 3 files changed, 38 insertions(+), 30 deletions(-) diff --git a/onnxruntime/test/perftest/command_args_parser.cc b/onnxruntime/test/perftest/command_args_parser.cc index 5c81696d5c57e..9f74967964e25 100644 --- a/onnxruntime/test/perftest/command_args_parser.cc +++ b/onnxruntime/test/perftest/command_args_parser.cc @@ -30,8 +30,12 @@ static const onnxruntime::perftest::PerformanceTestConfig& DefaultPerformanceTes return default_config; } -ABSL_FLAG(std::string, f, "", "Specifies a free dimension by name to override to a specific value for performance optimization."); -ABSL_FLAG(std::string, F, "", "Specifies a free dimension by denotation to override to a specific value for performance optimization."); +ABSL_FLAG(std::string, f, "", + "Specifies free dimensions by name to override with the specific values for performance optimization. Key-value paris are separated by space.\n" + "[Usage]: -f \"dimension_name_1:override_value_1 dimension_name_2:override_value_2 ... \". Override value must > 0."); +ABSL_FLAG(std::string, F, "", + "Specifies free dimensions by denotation to override with the specific values for performance optimization. Key-value paris are separated by space.\n" + "[Usage]: -F \"denotation_name_1:override_value_1 denotation_name_2:override_value_2 ... \". Override value must > 0."); ABSL_FLAG(std::string, m, "duration", "Specifies the test mode. Value could be 'duration' or 'times'."); ABSL_FLAG(std::string, e, "cpu", "Specifies the provider 'cpu','cuda','dnnl','tensorrt', 'nvtensorrtrtx', 'openvino', 'dml', 'acl', 'nnapi', 'coreml', 'qnn', 'snpe', 'rocm', 'migraphx', 'xnnpack', 'vitisai' or 'webgpu'."); ABSL_FLAG(size_t, r, DefaultPerformanceTestConfig().run_config.repeated_times, "Specifies the repeated times if running in 'times' test mode."); @@ -168,26 +172,6 @@ ABSL_FLAG(bool, h, false, "Print program usage."); namespace onnxruntime { namespace perftest { -static bool ParseDimensionOverride(std::string& dim_identifier, int64_t& override_val, const char* option) { - std::basic_string free_dim_str(option); - size_t delimiter_location = free_dim_str.find(":"); - if (delimiter_location >= free_dim_str.size() - 1) { - return false; - } - dim_identifier = free_dim_str.substr(0, delimiter_location); - std::string override_val_str = free_dim_str.substr(delimiter_location + 1, std::string::npos); - ORT_TRY { - override_val = std::stoll(override_val_str.c_str()); - if (override_val <= 0) { - return false; - } - } - ORT_CATCH(...) { - return false; - } - return true; -} - std::string CustomUsageMessage() { std::ostringstream oss; oss << "onnxruntime_perf_test [options...] model_path [result_file]\n\n"; @@ -220,12 +204,9 @@ bool CommandLineParser::ParseArguments(PerformanceTestConfig& test_config, int a { const auto& dim_override_str = absl::GetFlag(FLAGS_f); if (!dim_override_str.empty()) { - std::string dim_name; - int64_t override_val; - if (!ParseDimensionOverride(dim_name, override_val, dim_override_str.c_str())) { + if (!ParseDimensionOverride(dim_override_str, test_config.run_config.free_dim_name_overrides)) { return false; } - test_config.run_config.free_dim_name_overrides[dim_name] = override_val; } } @@ -233,12 +214,9 @@ bool CommandLineParser::ParseArguments(PerformanceTestConfig& test_config, int a { const auto& dim_override_str = absl::GetFlag(FLAGS_F); if (!dim_override_str.empty()) { - std::string dim_denotation; - int64_t override_val; - if (!ParseDimensionOverride(dim_denotation, override_val, dim_override_str.c_str())) { + if (!ParseDimensionOverride(dim_override_str, test_config.run_config.free_dim_denotation_overrides)) { return false; } - test_config.run_config.free_dim_denotation_overrides[dim_denotation] = override_val; } } diff --git a/onnxruntime/test/perftest/strings_helper.cc b/onnxruntime/test/perftest/strings_helper.cc index f4860b35c79da..3e2fbe1420df5 100644 --- a/onnxruntime/test/perftest/strings_helper.cc +++ b/onnxruntime/test/perftest/strings_helper.cc @@ -56,6 +56,34 @@ void ParseSessionConfigs(const std::string& configs_string, } } +bool ParseDimensionOverride(const std::string& input, std::map& free_dim_override_map) { + std::stringstream ss(input); + std::string free_dim_str; + + while (std::getline(ss, free_dim_str, ';')) { + if (!free_dim_str.empty()) { + size_t delimiter_location = free_dim_str.find(":"); + if (delimiter_location >= free_dim_str.size() - 1) { + return false; + } + std::string dim_identifier = free_dim_str.substr(0, delimiter_location); + std::string override_val_str = free_dim_str.substr(delimiter_location + 1, std::string::npos); + ORT_TRY { + int64_t override_val = std::stoll(override_val_str.c_str()); + if (override_val <= 0) { + return false; + } + free_dim_override_map[dim_identifier] = override_val; + } + ORT_CATCH(...) { + return false; + } + } + } + + return true; +} + void ParseEpOptions(const std::string& input, std::vector>& result) { auto tokens = utils::SplitString(input, ";", true); diff --git a/onnxruntime/test/perftest/strings_helper.h b/onnxruntime/test/perftest/strings_helper.h index 621ab746273bd..374a85ca9e29c 100644 --- a/onnxruntime/test/perftest/strings_helper.h +++ b/onnxruntime/test/perftest/strings_helper.h @@ -14,6 +14,8 @@ void ParseSessionConfigs(const std::string& configs_string, std::unordered_map& session_configs, const std::unordered_set& available_keys = {}); +bool ParseDimensionOverride(const std::string& input, std::map& free_dim_override_map); + void ParseEpList(const std::string& input, std::vector& result); void ParseEpOptions(const std::string& input, std::vector>& result); From ce8fd28f2fafd7507f37ddcae532e677d5d5fe7b Mon Sep 17 00:00:00 2001 From: Chi Lo Date: Mon, 11 Aug 2025 12:18:26 -0700 Subject: [PATCH 02/10] add include file --- onnxruntime/test/perftest/strings_helper.h | 1 + 1 file changed, 1 insertion(+) diff --git a/onnxruntime/test/perftest/strings_helper.h b/onnxruntime/test/perftest/strings_helper.h index 374a85ca9e29c..3c84e32b2b092 100644 --- a/onnxruntime/test/perftest/strings_helper.h +++ b/onnxruntime/test/perftest/strings_helper.h @@ -3,6 +3,7 @@ // SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates // Licensed under the MIT License. #include +#include #include #include #include From ed268983d7fa10a5e8d9b5019376f0ae1ca5bd65 Mon Sep 17 00:00:00 2001 From: Chi Lo Date: Mon, 11 Aug 2025 12:30:42 -0700 Subject: [PATCH 03/10] update delimiter --- onnxruntime/test/perftest/strings_helper.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxruntime/test/perftest/strings_helper.cc b/onnxruntime/test/perftest/strings_helper.cc index 3e2fbe1420df5..dc0f3fcd73f02 100644 --- a/onnxruntime/test/perftest/strings_helper.cc +++ b/onnxruntime/test/perftest/strings_helper.cc @@ -60,7 +60,7 @@ bool ParseDimensionOverride(const std::string& input, std::map= free_dim_str.size() - 1) { From ae1617abd9cf7eba583cb5da7b444f1e7559892c Mon Sep 17 00:00:00 2001 From: Chi Lo Date: Mon, 11 Aug 2025 12:35:06 -0700 Subject: [PATCH 04/10] fix typo --- onnxruntime/test/perftest/command_args_parser.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/onnxruntime/test/perftest/command_args_parser.cc b/onnxruntime/test/perftest/command_args_parser.cc index 9f74967964e25..2fdcddd6e3159 100644 --- a/onnxruntime/test/perftest/command_args_parser.cc +++ b/onnxruntime/test/perftest/command_args_parser.cc @@ -31,10 +31,10 @@ static const onnxruntime::perftest::PerformanceTestConfig& DefaultPerformanceTes } ABSL_FLAG(std::string, f, "", - "Specifies free dimensions by name to override with the specific values for performance optimization. Key-value paris are separated by space.\n" + "Specifies free dimensions by name to override with the specific values for performance optimization. Key-value pairs are separated by space.\n" "[Usage]: -f \"dimension_name_1:override_value_1 dimension_name_2:override_value_2 ... \". Override value must > 0."); ABSL_FLAG(std::string, F, "", - "Specifies free dimensions by denotation to override with the specific values for performance optimization. Key-value paris are separated by space.\n" + "Specifies free dimensions by denotation to override with the specific values for performance optimization. Key-value pairs are separated by space.\n" "[Usage]: -F \"denotation_name_1:override_value_1 denotation_name_2:override_value_2 ... \". Override value must > 0."); ABSL_FLAG(std::string, m, "duration", "Specifies the test mode. Value could be 'duration' or 'times'."); ABSL_FLAG(std::string, e, "cpu", "Specifies the provider 'cpu','cuda','dnnl','tensorrt', 'nvtensorrtrtx', 'openvino', 'dml', 'acl', 'nnapi', 'coreml', 'qnn', 'snpe', 'rocm', 'migraphx', 'xnnpack', 'vitisai' or 'webgpu'."); From 0bd09b60e7197af32f9ac11c2abedfa0d575a27c Mon Sep 17 00:00:00 2001 From: Chi Lo Date: Mon, 11 Aug 2025 22:05:40 -0700 Subject: [PATCH 05/10] address reviewer's comment --- onnxruntime/test/perftest/strings_helper.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/onnxruntime/test/perftest/strings_helper.cc b/onnxruntime/test/perftest/strings_helper.cc index dc0f3fcd73f02..374cdbedb359e 100644 --- a/onnxruntime/test/perftest/strings_helper.cc +++ b/onnxruntime/test/perftest/strings_helper.cc @@ -75,7 +75,10 @@ bool ParseDimensionOverride(const std::string& input, std::map Date: Tue, 12 Aug 2025 12:20:39 -0700 Subject: [PATCH 06/10] address reviewer's comment --- .../test/perftest/command_args_parser.cc | 12 ++++++++---- onnxruntime/test/perftest/main.cc | 4 ++-- onnxruntime/test/perftest/strings_helper.cc | 18 +++++++++++++++++- onnxruntime/test/perftest/strings_helper.h | 2 ++ 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/onnxruntime/test/perftest/command_args_parser.cc b/onnxruntime/test/perftest/command_args_parser.cc index 2fdcddd6e3159..ddb68833c2900 100644 --- a/onnxruntime/test/perftest/command_args_parser.cc +++ b/onnxruntime/test/perftest/command_args_parser.cc @@ -196,15 +196,18 @@ bool CommandLineParser::ParseArguments(PerformanceTestConfig& test_config, int a absl::SetFlagsUsageConfig(config); absl::SetProgramUsageMessage(CustomUsageMessage()); - auto utf8_strings = utils::ConvertArgvToUtf8Strings(argc, argv); - auto utf8_argv = utils::CStringsFromStrings(utf8_strings); + auto utf8_argv_strings = utils::ConvertArgvToUtf8Strings(argc, argv); + auto utf8_argv = utils::CStringsFromStrings(utf8_argv_strings); auto positional = absl::ParseCommandLine(static_cast(utf8_argv.size()), utf8_argv.data()); // -f { const auto& dim_override_str = absl::GetFlag(FLAGS_f); if (!dim_override_str.empty()) { - if (!ParseDimensionOverride(dim_override_str, test_config.run_config.free_dim_name_overrides)) { + // Abseil doesn't support the same option being provided multiple times — only the last occurrence is applied. + // To preserve the intended usage of '-f', where users may specify it multiple times to override different dimension names, + // we need to manually parse argv. + if (!ParseDimensionOverrideFromArgv(argc, utf8_argv_strings, "f", test_config.run_config.free_dim_name_overrides)) { return false; } } @@ -214,7 +217,8 @@ bool CommandLineParser::ParseArguments(PerformanceTestConfig& test_config, int a { const auto& dim_override_str = absl::GetFlag(FLAGS_F); if (!dim_override_str.empty()) { - if (!ParseDimensionOverride(dim_override_str, test_config.run_config.free_dim_denotation_overrides)) { + // Same reason as '-f' above to manully parse argv. + if (!ParseDimensionOverrideFromArgv(argc, utf8_argv_strings, "F", test_config.run_config.free_dim_denotation_overrides)) { return false; } } diff --git a/onnxruntime/test/perftest/main.cc b/onnxruntime/test/perftest/main.cc index 973baf774b024..513122609bb01 100644 --- a/onnxruntime/test/perftest/main.cc +++ b/onnxruntime/test/perftest/main.cc @@ -35,7 +35,7 @@ int real_main(int argc, char* argv[]) { } ORT_CATCH(const Ort::Exception& e) { ORT_HANDLE_EXCEPTION([&]() { - fprintf(stderr, "Error creating environment: %s \n", e.what()); + std::cerr << "Error creating environment: " << e.what() << std::endl; failed = true; }); } @@ -98,7 +98,7 @@ int main(int argc, char* argv[]) { } ORT_CATCH(const std::exception& ex) { ORT_HANDLE_EXCEPTION([&]() { - fprintf(stderr, "%s\n", ex.what()); + std::cerr << ex.what() << std::endl; retval = -1; }); } diff --git a/onnxruntime/test/perftest/strings_helper.cc b/onnxruntime/test/perftest/strings_helper.cc index 374cdbedb359e..5e87b063767e8 100644 --- a/onnxruntime/test/perftest/strings_helper.cc +++ b/onnxruntime/test/perftest/strings_helper.cc @@ -77,7 +77,7 @@ bool ParseDimensionOverride(const std::string& input, std::map argv, std::string option, std::map& free_dim_override_map) { + for (int i = 1; i < argc; ++i) { + auto utf8_arg = argv[i]; + if (utf8_arg == ("-" + option) || utf8_arg == ("--" + option)) { + auto value_idx = i + 1; + if (value_idx >= argc || argv[value_idx][0] == '-') { + std::cerr << utf8_arg << " should be followed by a key-value pair." << std::endl; + return false; + } + + if (!ParseDimensionOverride(argv[value_idx], free_dim_override_map)) return false; + } + } + return true; +} + void ParseEpOptions(const std::string& input, std::vector>& result) { auto tokens = utils::SplitString(input, ";", true); diff --git a/onnxruntime/test/perftest/strings_helper.h b/onnxruntime/test/perftest/strings_helper.h index 3c84e32b2b092..976f8051b8145 100644 --- a/onnxruntime/test/perftest/strings_helper.h +++ b/onnxruntime/test/perftest/strings_helper.h @@ -17,6 +17,8 @@ void ParseSessionConfigs(const std::string& configs_string, bool ParseDimensionOverride(const std::string& input, std::map& free_dim_override_map); +bool ParseDimensionOverrideFromArgv(int argc, std::vector argv, std::string option, std::map& free_dim_override_map); + void ParseEpList(const std::string& input, std::vector& result); void ParseEpOptions(const std::string& input, std::vector>& result); From da2af6abc95f7bff1d5424efd6fc7fd9666cdc74 Mon Sep 17 00:00:00 2001 From: Chi Lo Date: Tue, 12 Aug 2025 12:32:38 -0700 Subject: [PATCH 07/10] update flag description --- onnxruntime/test/perftest/command_args_parser.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/onnxruntime/test/perftest/command_args_parser.cc b/onnxruntime/test/perftest/command_args_parser.cc index ddb68833c2900..780c590ab7b64 100644 --- a/onnxruntime/test/perftest/command_args_parser.cc +++ b/onnxruntime/test/perftest/command_args_parser.cc @@ -31,11 +31,13 @@ static const onnxruntime::perftest::PerformanceTestConfig& DefaultPerformanceTes } ABSL_FLAG(std::string, f, "", - "Specifies free dimensions by name to override with the specific values for performance optimization. Key-value pairs are separated by space.\n" - "[Usage]: -f \"dimension_name_1:override_value_1 dimension_name_2:override_value_2 ... \". Override value must > 0."); + "Specifies a free dimension by name to override to a specific value for performance optimization.\n" + "[Usage]: -f \"dimension_name1:override_value1\" -f \"dimension_name2:override_value2\" ... or" + " -f \"dimension_name1:override_value1 dimension_name2:override_value2 ... \". Override value must > 0."); ABSL_FLAG(std::string, F, "", - "Specifies free dimensions by denotation to override with the specific values for performance optimization. Key-value pairs are separated by space.\n" - "[Usage]: -F \"denotation_name_1:override_value_1 denotation_name_2:override_value_2 ... \". Override value must > 0."); + "Specifies a free dimension by denotation to override to a specific value for performance optimization.\n" + "[Usage]: -f \"dimension_denotation1:override_value1\" -f \"dimension_denotation2:override_value2\" ... or" + " -f \"dimension_denotation1:override_value1 dimension_denotation2 : override_value2... \". Override value must > 0."); ABSL_FLAG(std::string, m, "duration", "Specifies the test mode. Value could be 'duration' or 'times'."); ABSL_FLAG(std::string, e, "cpu", "Specifies the provider 'cpu','cuda','dnnl','tensorrt', 'nvtensorrtrtx', 'openvino', 'dml', 'acl', 'nnapi', 'coreml', 'qnn', 'snpe', 'rocm', 'migraphx', 'xnnpack', 'vitisai' or 'webgpu'."); ABSL_FLAG(size_t, r, DefaultPerformanceTestConfig().run_config.repeated_times, "Specifies the repeated times if running in 'times' test mode."); From f625a093fdde4de1a2b548f1e54fd8d1a8fed0e9 Mon Sep 17 00:00:00 2001 From: Chi Lo Date: Tue, 12 Aug 2025 13:39:13 -0700 Subject: [PATCH 08/10] update the file that contains illegal character --- onnxruntime/test/perftest/command_args_parser.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxruntime/test/perftest/command_args_parser.cc b/onnxruntime/test/perftest/command_args_parser.cc index 780c590ab7b64..4f7e75df7fbff 100644 --- a/onnxruntime/test/perftest/command_args_parser.cc +++ b/onnxruntime/test/perftest/command_args_parser.cc @@ -207,7 +207,7 @@ bool CommandLineParser::ParseArguments(PerformanceTestConfig& test_config, int a const auto& dim_override_str = absl::GetFlag(FLAGS_f); if (!dim_override_str.empty()) { // Abseil doesn't support the same option being provided multiple times — only the last occurrence is applied. - // To preserve the intended usage of '-f', where users may specify it multiple times to override different dimension names, + // To preserve the previous usage of '-f', where users may specify it multiple times to override different dimension names, // we need to manually parse argv. if (!ParseDimensionOverrideFromArgv(argc, utf8_argv_strings, "f", test_config.run_config.free_dim_name_overrides)) { return false; From 0b7ccf6fc00652f9031c7b78844a858548e16585 Mon Sep 17 00:00:00 2001 From: Chi Lo Date: Tue, 12 Aug 2025 14:13:46 -0700 Subject: [PATCH 09/10] update the file that contains illegal character --- onnxruntime/test/perftest/command_args_parser.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxruntime/test/perftest/command_args_parser.cc b/onnxruntime/test/perftest/command_args_parser.cc index 4f7e75df7fbff..207eba36d6ff3 100644 --- a/onnxruntime/test/perftest/command_args_parser.cc +++ b/onnxruntime/test/perftest/command_args_parser.cc @@ -206,7 +206,7 @@ bool CommandLineParser::ParseArguments(PerformanceTestConfig& test_config, int a { const auto& dim_override_str = absl::GetFlag(FLAGS_f); if (!dim_override_str.empty()) { - // Abseil doesn't support the same option being provided multiple times — only the last occurrence is applied. + // Abseil doesn't support the same option being provided multiple times - only the last occurrence is applied. // To preserve the previous usage of '-f', where users may specify it multiple times to override different dimension names, // we need to manually parse argv. if (!ParseDimensionOverrideFromArgv(argc, utf8_argv_strings, "f", test_config.run_config.free_dim_name_overrides)) { From a771a130d25457def6ff89eab7824344eeca4b6a Mon Sep 17 00:00:00 2001 From: Chi Lo Date: Mon, 18 Aug 2025 15:06:48 -0700 Subject: [PATCH 10/10] address reviewer's comments --- onnxruntime/test/perftest/command_args_parser.cc | 6 ++++-- onnxruntime/test/perftest/strings_helper.cc | 2 +- onnxruntime/test/perftest/strings_helper.h | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/onnxruntime/test/perftest/command_args_parser.cc b/onnxruntime/test/perftest/command_args_parser.cc index 207eba36d6ff3..a22375320edae 100644 --- a/onnxruntime/test/perftest/command_args_parser.cc +++ b/onnxruntime/test/perftest/command_args_parser.cc @@ -209,7 +209,8 @@ bool CommandLineParser::ParseArguments(PerformanceTestConfig& test_config, int a // Abseil doesn't support the same option being provided multiple times - only the last occurrence is applied. // To preserve the previous usage of '-f', where users may specify it multiple times to override different dimension names, // we need to manually parse argv. - if (!ParseDimensionOverrideFromArgv(argc, utf8_argv_strings, "f", test_config.run_config.free_dim_name_overrides)) { + std::string option = "f"; + if (!ParseDimensionOverrideFromArgv(argc, utf8_argv_strings, option, test_config.run_config.free_dim_name_overrides)) { return false; } } @@ -220,7 +221,8 @@ bool CommandLineParser::ParseArguments(PerformanceTestConfig& test_config, int a const auto& dim_override_str = absl::GetFlag(FLAGS_F); if (!dim_override_str.empty()) { // Same reason as '-f' above to manully parse argv. - if (!ParseDimensionOverrideFromArgv(argc, utf8_argv_strings, "F", test_config.run_config.free_dim_denotation_overrides)) { + std::string option = "F"; + if (!ParseDimensionOverrideFromArgv(argc, utf8_argv_strings, option, test_config.run_config.free_dim_denotation_overrides)) { return false; } } diff --git a/onnxruntime/test/perftest/strings_helper.cc b/onnxruntime/test/perftest/strings_helper.cc index 5e87b063767e8..5743346f8edf1 100644 --- a/onnxruntime/test/perftest/strings_helper.cc +++ b/onnxruntime/test/perftest/strings_helper.cc @@ -87,7 +87,7 @@ bool ParseDimensionOverride(const std::string& input, std::map argv, std::string option, std::map& free_dim_override_map) { +bool ParseDimensionOverrideFromArgv(int argc, std::vector& argv, std::string& option, std::map& free_dim_override_map) { for (int i = 1; i < argc; ++i) { auto utf8_arg = argv[i]; if (utf8_arg == ("-" + option) || utf8_arg == ("--" + option)) { diff --git a/onnxruntime/test/perftest/strings_helper.h b/onnxruntime/test/perftest/strings_helper.h index 976f8051b8145..a33b3d5089c9b 100644 --- a/onnxruntime/test/perftest/strings_helper.h +++ b/onnxruntime/test/perftest/strings_helper.h @@ -17,7 +17,7 @@ void ParseSessionConfigs(const std::string& configs_string, bool ParseDimensionOverride(const std::string& input, std::map& free_dim_override_map); -bool ParseDimensionOverrideFromArgv(int argc, std::vector argv, std::string option, std::map& free_dim_override_map); +bool ParseDimensionOverrideFromArgv(int argc, std::vector& argv, std::string& option, std::map& free_dim_override_map); void ParseEpList(const std::string& input, std::vector& result);