onnxruntime_perf_test: Add -u option to save optimized model (#2227)

This commit is contained in:
KeDengMS 2019-10-28 12:36:31 -07:00 committed by GitHub
parent 3ecdd985cb
commit 5611a528f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 1 deletions

View file

@ -20,6 +20,8 @@ Options:
-o: [optimization level]: Default is 1. Valid values are 0 (disable), 1 (basic), 2 (extended), 99 (all). Please see __onnxruntime_c_api.h__ (enum GraphOptimizationLevel) for the full list of all optimization levels.
-u: [path to save optimized model]: Default is empty so no optimized model would be saved.
-p: [profile_file]: Specifies the profile name to enable profiling and dump the profile data to the file.
-r: [repeated_times]: Specifies the repeated times if running in 'times' test mode.Default:1000.

View file

@ -46,12 +46,13 @@ namespace perftest {
"\t-P: Use parallel executor instead of sequential executor.\n"
"\t-o [optimization level]: Default is 1. Valid values are 0 (disable), 1 (basic), 2 (extended), 99 (all).\n"
"\t\tPlease see onnxruntime_c_api.h (enum GraphOptimizationLevel) for the full list of all optimization levels. \n"
"\t-u [optimized_model_path]: Specify the optimized model path for saving.\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("b:m:e:r:t:p:x:y:c:o:AMPvhs"))) != -1) {
while ((ch = getopt(argc, argv, ORT_TSTR("b:m:e:r:t:p:x:y:c:o:u:AMPvhs"))) != -1) {
switch (ch) {
case 'm':
if (!CompareCString(optarg, ORT_TSTR("duration"))) {
@ -166,6 +167,9 @@ namespace perftest {
}
break;
}
case 'u':
test_config.run_config.optimized_model_path = optarg;
break;
case '?':
case 'h':
default:

View file

@ -105,6 +105,8 @@ OnnxRuntimeTestSession::OnnxRuntimeTestSession(Ort::Env& env, std::random_device
session_options.SetGraphOptimizationLevel(performance_test_config.run_config.optimization_level);
if (!performance_test_config.run_config.profile_file.empty())
session_options.EnableProfiling(performance_test_config.run_config.profile_file.c_str());
if (!performance_test_config.run_config.optimized_model_path.empty())
session_options.SetOptimizedModelFilePath(performance_test_config.run_config.optimized_model_path.c_str());
session_ = Ort::Session(env, performance_test_config.model_info.model_file_path.c_str(), session_options);
size_t output_count = session_.GetOutputCount();

View file

@ -48,6 +48,7 @@ struct RunConfig {
int intra_op_num_threads{0};
int inter_op_num_threads{0};
GraphOptimizationLevel optimization_level{ORT_ENABLE_EXTENDED};
std::basic_string<ORTCHAR_T> optimized_model_path;
};
struct PerformanceTestConfig {