diff --git a/onnxruntime/test/perftest/command_args_parser.cc b/onnxruntime/test/perftest/command_args_parser.cc index bc6ed2e5e6..863179bd61 100644 --- a/onnxruntime/test/perftest/command_args_parser.cc +++ b/onnxruntime/test/perftest/command_args_parser.cc @@ -35,12 +35,13 @@ namespace perftest { "\t-s: Show statistics result, like P75, P90.\n" "\t-v: Show verbose information.\n" "\t-x [thread_size]: Use parallel executor, default (without -x): sequential executor.\n" + "\t-o [optimization level]: 0: No transformer optimization, 1:basic optimization, 2: full optimization. \n" "\t-h: help\n"); } /*static*/ bool CommandLineParser::ParseArguments(PerformanceTestConfig& test_config, int argc, ORTCHAR_T* argv[]) { int ch; - while ((ch = getopt(argc, argv, ORT_TSTR("m:e:r:t:p:x:vhs"))) != -1) { + while ((ch = getopt(argc, argv, ORT_TSTR("m:e:r:t:p:x:o:vhs"))) != -1) { switch (ch) { case 'm': if (!CompareCString(optarg, ORT_TSTR("duration"))) { @@ -96,6 +97,13 @@ namespace perftest { return false; } break; + case 'o': + test_config.run_config.optimization_level = static_cast(OrtStrtol(optarg, nullptr)); + // Valid values are: 0, 1, 2. + if (test_config.run_config.optimization_level > 2 ) { + return false; + } + break; case '?': case 'h': default: diff --git a/onnxruntime/test/perftest/performance_runner.cc b/onnxruntime/test/perftest/performance_runner.cc index 66dc1625f6..c9defc54a7 100644 --- a/onnxruntime/test/perftest/performance_runner.cc +++ b/onnxruntime/test/perftest/performance_runner.cc @@ -140,6 +140,10 @@ bool PerformanceRunner::Initialize() { sf.DisableSequentialExecution(); fprintf(stdout, "Setting thread pool size to %d\n", performance_test_config_.run_config.session_thread_pool_size); sf.SetSessionThreadPoolSize(performance_test_config_.run_config.session_thread_pool_size); + + // Set optimization level. + sf.SetSessionGraphOptimizationLevel(performance_test_config_.run_config.optimization_level); + session_object_ = sf.OrtCreateSession(test_case->GetModelUrl()); auto provider_type = performance_test_config_.machine_config.provider_type_name; diff --git a/onnxruntime/test/perftest/test_configuration.h b/onnxruntime/test/perftest/test_configuration.h index 966e665800..182b120789 100644 --- a/onnxruntime/test/perftest/test_configuration.h +++ b/onnxruntime/test/perftest/test_configuration.h @@ -42,6 +42,7 @@ struct RunConfig { bool f_verbose{false}; bool enable_sequential_execution{true}; int session_thread_pool_size{6}; + uint32_t optimization_level{2}; }; struct PerformanceTestConfig {