Add option to skip session run in perf_test tool (#19501)

Enable a option to exit after session creation so that user can measure session creation time to measure impact of enabling any initialization optimizations.
This commit is contained in:
Hector Li 2024-02-12 19:11:40 -08:00 committed by GitHub
parent 7fa6f4fca4
commit a622710fe1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 20 additions and 1 deletions

View file

@ -128,6 +128,7 @@ namespace perftest {
"\t\t The number of affinities must be equal to intra_op_num_threads - 1\n\n"
"\t-D [Disable thread spinning]: disable spinning entirely for thread owned by onnxruntime intra-op thread pool.\n"
"\t-Z [Force thread to stop spinning between runs]: disallow thread from spinning during runs to reduce cpu usage.\n"
"\t-n [Exit after session creation]: allow user to measure session creation time to measure impact of enabling any initialization optimizations.\n"
"\t-h: help\n");
}
#ifdef _WIN32
@ -190,7 +191,7 @@ static bool ParseSessionConfigs(const std::string& configs_string,
/*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:d:o:u:i:f:F:S:T:C:AMPIDZvhsqz"))) != -1) {
while ((ch = getopt(argc, argv, ORT_TSTR("b:m:e:r:t:p:x:y:c:d:o:u:i:f:F:S:T:C:AMPIDZvhsqzn"))) != -1) {
switch (ch) {
case 'f': {
std::basic_string<ORTCHAR_T> dim_name;
@ -373,6 +374,9 @@ static bool ParseSessionConfigs(const std::string& configs_string,
case 'Z':
test_config.run_config.disable_spinning_between_run = true;
break;
case 'n':
test_config.run_config.exit_after_session_creation = true;
break;
case '?':
case 'h':
default:

View file

@ -43,6 +43,13 @@ int real_main(int argc, char* argv[]) {
}
std::random_device rd;
perftest::PerformanceRunner perf_runner(env, test_config, rd);
// Exit if user enabled -n option so that user can measure session creation time
if (test_config.run_config.exit_after_session_creation) {
perf_runner.LogSessionCreationTime();
return 0;
}
auto status = perf_runner.Run();
if (!status.IsOK()) {
printf("Run failed:%s\n", status.ErrorMessage().c_str());

View file

@ -115,6 +115,11 @@ void PerformanceResult::DumpToFile(const std::basic_string<ORTCHAR_T>& path, boo
}
}
void PerformanceRunner::LogSessionCreationTime() {
std::chrono::duration<double> session_create_duration = session_create_end_ - session_create_start_;
std::cout << "\nSession creation time cost: " << session_create_duration.count() << " s\n";
}
Status PerformanceRunner::Run() {
if (!Initialize()) {
return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "failed to initialize.");

View file

@ -46,6 +46,8 @@ class PerformanceRunner {
~PerformanceRunner();
Status Run();
void LogSessionCreationTime();
inline const PerformanceResult& GetResult() const { return performance_result_; }
inline void SerializeResult() const {

View file

@ -63,6 +63,7 @@ struct RunConfig {
std::string intra_op_thread_affinities;
bool disable_spinning = false;
bool disable_spinning_between_run = false;
bool exit_after_session_creation = false;
};
struct PerformanceTestConfig {