mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-29 20:14:01 +00:00
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:
parent
7fa6f4fca4
commit
a622710fe1
5 changed files with 20 additions and 1 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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.");
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@ class PerformanceRunner {
|
|||
~PerformanceRunner();
|
||||
Status Run();
|
||||
|
||||
void LogSessionCreationTime();
|
||||
|
||||
inline const PerformanceResult& GetResult() const { return performance_result_; }
|
||||
|
||||
inline void SerializeResult() const {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue