@@ -30,8 +30,14 @@ static const onnxruntime::perftest::PerformanceTestConfig& DefaultPerformanceTes
3030 return default_config;
3131}
3232
33- ABSL_FLAG (std::string, f, " " , " Specifies a free dimension by name to override to a specific value for performance optimization." );
34- ABSL_FLAG (std::string, F, " " , " Specifies a free dimension by denotation to override to a specific value for performance optimization." );
33+ ABSL_FLAG (std::string, f, " " ,
34+ " Specifies a free dimension by name to override to a specific value for performance optimization.\n "
35+ " [Usage]: -f \" dimension_name1:override_value1\" -f \" dimension_name2:override_value2\" ... or"
36+ " -f \" dimension_name1:override_value1 dimension_name2:override_value2 ... \" . Override value must > 0." );
37+ ABSL_FLAG (std::string, F, " " ,
38+ " Specifies a free dimension by denotation to override to a specific value for performance optimization.\n "
39+ " [Usage]: -f \" dimension_denotation1:override_value1\" -f \" dimension_denotation2:override_value2\" ... or"
40+ " -f \" dimension_denotation1:override_value1 dimension_denotation2 : override_value2... \" . Override value must > 0." );
3541ABSL_FLAG (std::string, m, " duration" , " Specifies the test mode. Value could be 'duration' or 'times'." );
3642ABSL_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'." );
3743ABSL_FLAG (size_t , r, DefaultPerformanceTestConfig().run_config.repeated_times, "Specifies the repeated times if running in 'times' test mode.");
@@ -168,26 +174,6 @@ ABSL_FLAG(bool, h, false, "Print program usage.");
168174namespace onnxruntime {
169175namespace perftest {
170176
171- static bool ParseDimensionOverride (std::string& dim_identifier, int64_t & override_val, const char * option) {
172- std::basic_string<char > free_dim_str (option);
173- size_t delimiter_location = free_dim_str.find (" :" );
174- if (delimiter_location >= free_dim_str.size () - 1 ) {
175- return false ;
176- }
177- dim_identifier = free_dim_str.substr (0 , delimiter_location);
178- std::string override_val_str = free_dim_str.substr (delimiter_location + 1 , std::string::npos);
179- ORT_TRY {
180- override_val = std::stoll (override_val_str.c_str ());
181- if (override_val <= 0 ) {
182- return false ;
183- }
184- }
185- ORT_CATCH (...) {
186- return false ;
187- }
188- return true ;
189- }
190-
191177std::string CustomUsageMessage () {
192178 std::ostringstream oss;
193179 oss << " onnxruntime_perf_test [options...] model_path [result_file]\n\n " ;
@@ -212,33 +198,33 @@ bool CommandLineParser::ParseArguments(PerformanceTestConfig& test_config, int a
212198 absl::SetFlagsUsageConfig (config);
213199 absl::SetProgramUsageMessage (CustomUsageMessage ());
214200
215- auto utf8_strings = utils::ConvertArgvToUtf8Strings (argc, argv);
216- auto utf8_argv = utils::CStringsFromStrings (utf8_strings );
201+ auto utf8_argv_strings = utils::ConvertArgvToUtf8Strings (argc, argv);
202+ auto utf8_argv = utils::CStringsFromStrings (utf8_argv_strings );
217203 auto positional = absl::ParseCommandLine (static_cast <int >(utf8_argv.size ()), utf8_argv.data ());
218204
219205 // -f
220206 {
221207 const auto & dim_override_str = absl::GetFlag (FLAGS_f);
222208 if (!dim_override_str.empty ()) {
223- std::string dim_name;
224- int64_t override_val;
225- if (!ParseDimensionOverride (dim_name, override_val, dim_override_str.c_str ())) {
209+ // Abseil doesn't support the same option being provided multiple times - only the last occurrence is applied.
210+ // To preserve the previous usage of '-f', where users may specify it multiple times to override different dimension names,
211+ // we need to manually parse argv.
212+ std::string option = " f" ;
213+ if (!ParseDimensionOverrideFromArgv (argc, utf8_argv_strings, option, test_config.run_config .free_dim_name_overrides )) {
226214 return false ;
227215 }
228- test_config.run_config .free_dim_name_overrides [dim_name] = override_val;
229216 }
230217 }
231218
232219 // -F
233220 {
234221 const auto & dim_override_str = absl::GetFlag (FLAGS_F);
235222 if (!dim_override_str.empty ()) {
236- std::string dim_denotation;
237- int64_t override_val ;
238- if (!ParseDimensionOverride (dim_denotation, override_val, dim_override_str. c_str () )) {
223+ // Same reason as '-f' above to manully parse argv.
224+ std::string option = " F " ;
225+ if (!ParseDimensionOverrideFromArgv (argc, utf8_argv_strings, option, test_config. run_config . free_dim_denotation_overrides )) {
239226 return false ;
240227 }
241- test_config.run_config .free_dim_denotation_overrides [dim_denotation] = override_val;
242228 }
243229 }
244230
0 commit comments