Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
43f261d
add support for perf test to run plugin ep
chilo-ms Jul 12, 2025
8b982ab
Unregister all registered plugin EP libraries before program exit
chilo-ms Jul 12, 2025
7fd4713
remove unnecessary code
chilo-ms Jul 12, 2025
de32583
fix compile error
chilo-ms Jul 13, 2025
43ef004
Merge branch 'main' into chi/add_plugin_ep_for_perf_test
chilo-ms Jul 16, 2025
4a9c5a3
Replace getopt with cxxopts and include --list_devices and --select_d…
chilo-ms Jul 18, 2025
6cbc3ea
fix build errors on Linux
chilo-ms Jul 18, 2025
eb2220e
address build erros/warnings
chilo-ms Jul 19, 2025
3d3dacb
remove test code
chilo-ms Jul 19, 2025
aa085cb
continue the rest of converting getopt to cxxopts
chilo-ms Jul 19, 2025
c5fd68c
address compile warning
chilo-ms Jul 19, 2025
5fb5693
update usage explanation
chilo-ms Jul 19, 2025
f673e0e
remove test code
chilo-ms Jul 19, 2025
3607d68
add -DCXXOPTS_NO_RTTI for minimal build
chilo-ms Jul 21, 2025
e03d00b
address lintrunner issue
chilo-ms Jul 21, 2025
0736200
fix type
chilo-ms Jul 21, 2025
0396a27
fix typos
chilo-ms Jul 21, 2025
fe9e1de
add back getopts for the build which disables exceptions
chilo-ms Jul 21, 2025
8af32b3
add define for DISABLE_EXCEPTIONS
chilo-ms Jul 21, 2025
bd133cf
Merge branch 'main' into chi/add_plugin_ep_for_perf_test
chilo-ms Jul 22, 2025
51b3412
address reviewer's comments
chilo-ms Jul 23, 2025
e281ca5
revert code back
chilo-ms Jul 23, 2025
bdfd3f5
address reviewer's comments
chilo-ms Jul 24, 2025
22d3b80
address reviewer's comments
chilo-ms Jul 24, 2025
2cd8a30
address lint issue
chilo-ms Jul 24, 2025
ad4d8a8
add '\n' for fprintf
chilo-ms Jul 24, 2025
3e92522
address reviewers' comments
chilo-ms Jul 25, 2025
d2fb335
fix some issues
chilo-ms Jul 25, 2025
ad0ac64
update option usage example
chilo-ms Jul 25, 2025
ec5e973
revert usage description
chilo-ms Jul 25, 2025
2396d2c
Use abseil (ABSL Flags) instead of cxxopts
chilo-ms Jul 30, 2025
fdd95ea
update cmake file
chilo-ms Jul 30, 2025
3131024
get correct positional options
chilo-ms Jul 30, 2025
17eaccf
revert deps.txt
chilo-ms Jul 30, 2025
0550d6c
use PathString typedef
chilo-ms Jul 30, 2025
6cbb20f
address some of the reviewer's comments
chilo-ms Aug 1, 2025
706b1c8
fix build issues
chilo-ms Aug 1, 2025
991bb41
address reveiwer's comments
chilo-ms Aug 1, 2025
01da1a5
Alias '-h' to '--help' and remove showUsage function
chilo-ms Aug 5, 2025
3bf3183
supress mem leak info
chilo-ms Aug 5, 2025
a00c352
remove calling showUsage
chilo-ms Aug 5, 2025
7236e44
fix build issue for Linux
chilo-ms Aug 5, 2025
02499f8
fix build issue in Linux
chilo-ms Aug 5, 2025
461d57d
clean up
chilo-ms Aug 5, 2025
1cfa077
clean up
chilo-ms Aug 5, 2025
8e48b80
Add flags_internal::FlagImpl::Init to the filter of the mem check
chilo-ms Aug 5, 2025
849c0ba
Merge branch 'main' into chi/add_plugin_ep_for_perf_test
chilo-ms Aug 6, 2025
330d8ed
address reviewer's comments
chilo-ms Aug 6, 2025
a848340
Remove the filtering of expected mem leak with ABSL flags, will handl…
chilo-ms Aug 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions onnxruntime/test/perftest/command_args_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ namespace perftest {
"\t-A: Disable memory arena\n"
"\t-I: Generate tensor input binding. Free dimensions are treated as 1 unless overridden using -f.\n"
"\t-c [parallel runs]: Specifies the (max) number of runs to invoke simultaneously. Default:1.\n"
"\t-e [cpu|cuda|dnnl|tensorrt|openvino|dml|acl|nnapi|coreml|qnn|snpe|rocm|migraphx|xnnpack|vitisai|webgpu]: Specifies the provider 'cpu','cuda','dnnl','tensorrt', "
"'nvtensorrtrtx', 'openvino', 'dml', 'acl', 'nnapi', 'coreml', 'qnn', 'snpe', 'rocm', 'migraphx', 'xnnpack', 'vitisai' or 'webgpu'. "
"\t-e [cpu|cuda|dnnl|tensorrt|openvino|dml|acl|nnapi|coreml|qnn|snpe|rocm|migraphx|xnnpack|vitisai|webgpu|plugin_ep]: Specifies the provider 'cpu','cuda','dnnl','tensorrt', "
"'nvtensorrtrtx', 'openvino', 'dml', 'acl', 'nnapi', 'coreml', 'qnn', 'snpe', 'rocm', 'migraphx', 'xnnpack', 'vitisai', 'webgpu' or plugin execution provider that provided via ep library. "
Comment thread
chilo-ms marked this conversation as resolved.
Outdated
"Default:'cpu'.\n"
"\t-b [tf|ort]: backend to use. Default:ort\n"
"\t-r [repeated_times]: Specifies the repeated times if running in 'times' test mode.Default:1000.\n"
Expand Down Expand Up @@ -195,7 +195,7 @@ static bool ParseDimensionOverride(std::basic_string<ORTCHAR_T>& dim_identifier,

/*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:y:c:d:o:u:i:f:F:S:T:C:AMPIDZvhsqznlgR:X"))) != -1) {
while ((ch = getopt(argc, argv, ORT_TSTR("m:e:r:t:p:x:y:c:d:o:u:i:f:F:S:T:C:AMPIDZvhsqznlgR:XL:"))) != -1) {
switch (ch) {
case 'f': {
std::basic_string<ORTCHAR_T> dim_name;
Expand Down Expand Up @@ -273,7 +273,8 @@ static bool ParseDimensionOverride(std::basic_string<ORTCHAR_T>& dim_identifier,
} else if (!CompareCString(optarg, ORT_TSTR("nvtensorrtrtx"))) {
test_config.machine_config.provider_type_name = onnxruntime::kNvTensorRTRTXExecutionProvider;
} else {
return false;
// Could be plugin EP, save it first and handle later.
test_config.machine_config.provider_type_name = ToUTF8String(optarg);
}
break;
case 'r':
Expand Down Expand Up @@ -404,6 +405,9 @@ static bool ParseDimensionOverride(std::basic_string<ORTCHAR_T>& dim_identifier,
case 'X':
test_config.run_config.use_extensions = true;
break;
case 'L':
test_config.plugin_ep_names_and_libs = optarg;
break;
case '?':
case 'h':
default:
Expand Down
48 changes: 38 additions & 10 deletions onnxruntime/test/perftest/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <random>
#include "command_args_parser.h"
#include "performance_runner.h"
#include "strings_helper.h"
#include <google/protobuf/stubs/common.h>

using namespace onnxruntime;
Expand Down Expand Up @@ -41,23 +42,50 @@ int real_main(int argc, char* argv[]) {
if (failed)
return -1;
}
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 = Status::OK();

{
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;
}

status = perf_runner.Run();

if (!status.IsOK()) {
printf("Run failed:%s\n", status.ErrorMessage().c_str());
} else {
perf_runner.SerializeResult();
}
}

// Unregister all registered plugin EP libraries before program exits.
//
// This is necessary because unregistering the plugin EP also unregisters any associated shared allocators.
// If we don't do this first and program returns, the factories stored inside the environment will be destroyed when the environment goes out of scope.
// Later, when the shared allocator's deleter runs, it may cause a segmentation fault because it attempts to use the already-destroyed factory to call ReleaseAllocator.
//
// See "ep_device.ep_factory->ReleaseAllocator" in Environment::CreateSharedAllocatorImpl.
std::unordered_map<std::string, std::string> ep_names_to_libs;
#ifdef _MSC_VER
std::string ep_names_and_libs_string = ToUTF8String(test_config.plugin_ep_names_and_libs);
#else
std::string ep_names_and_libs_string = test_config.plugin_ep_names_and_libs;
#endif
onnxruntime::perftest::ParseSessionConfigs(ep_names_and_libs_string, ep_names_to_libs);
for (auto& pair : ep_names_to_libs) {
env.UnregisterExecutionProviderLibrary(pair.first.c_str());
Comment thread
chilo-ms marked this conversation as resolved.
Outdated
}

auto status = perf_runner.Run();
if (!status.IsOK()) {
printf("Run failed:%s\n", status.ErrorMessage().c_str());
return -1;
}

perf_runner.SerializeResult();

return 0;
}

Expand Down
53 changes: 52 additions & 1 deletion onnxruntime/test/perftest/ort_test_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,56 @@
: rand_engine_(rd()), input_names_(m.GetInputCount()), input_names_str_(m.GetInputCount()), input_length_(m.GetInputCount()) {
Ort::SessionOptions session_options;

#ifdef _MSC_VER
Comment thread
chilo-ms marked this conversation as resolved.
Outdated
std::string ep_names_and_libs_string = ToUTF8String(performance_test_config.plugin_ep_names_and_libs);
#else
std::string ep_names_and_libs_string = performance_test_config.plugin_ep_names_and_libs;
#endif
std::unordered_map<std::string, std::string> ep_names_to_libs;
ParseSessionConfigs(ep_names_and_libs_string, ep_names_to_libs);
bool is_plugin_ep_avaiable = false;

Check warning on line 72 in onnxruntime/test/perftest/ort_test_session.cc

View workflow job for this annotation

GitHub Actions / Optional Lint

[misspell] reported by reviewdog 🐶 "avaiable" is a misspelling of "available" Raw Output: ./onnxruntime/test/perftest/ort_test_session.cc:72:20: "avaiable" is a misspelling of "available"

if (ep_names_to_libs.size() > 0) {
// Register plugin EP libraries if provided via "-L" argument.
for (auto& pair : ep_names_to_libs) {
const std::filesystem::path library_path = pair.second;
const std::string registration_name = pair.first;
env.RegisterExecutionProviderLibrary(registration_name.c_str(), library_path.c_str());
registered_plugin_ep_names_.push_back(registration_name);
}

std::vector<Ort::ConstEpDevice> ep_devices = env.GetEpDevices();
std::vector<Ort::ConstEpDevice> added_ep_devices;

// All OrtEpDevice instances must be from the same execution provider.
// Find the OrtEpDevice associated with the execution provider provided via "-e" argument.
Ort::ConstEpDevice plugin_ep_device;
for (Ort::ConstEpDevice& device : ep_devices) {
if (std::string(device.EpName()) == performance_test_config.machine_config.provider_type_name) {
plugin_ep_device = device;
added_ep_devices.push_back(plugin_ep_device);
}
}

if (added_ep_devices.empty()) {
for (auto ep_name : registered_plugin_ep_names_) {
env.UnregisterExecutionProviderLibrary(ep_name.c_str());
}
ORT_THROW(
"[ERROR] [plugin EP] No matching execution provider name found in EP library's factory.");
}

#if defined(_MSC_VER)
std::string provider_option_string = ToUTF8String(performance_test_config.run_config.ep_runtime_config_string);
#else
std::string provider_option_string = performance_test_config.run_config.ep_runtime_config_string;
#endif
std::unordered_map<std::string, std::string> provider_options;
ParseSessionConfigs(provider_option_string, provider_options);
session_options.AppendExecutionProvider_V2(env, added_ep_devices, provider_options);
is_plugin_ep_avaiable = true;

Check warning on line 112 in onnxruntime/test/perftest/ort_test_session.cc

View workflow job for this annotation

GitHub Actions / Optional Lint

[misspell] reported by reviewdog 🐶 "avaiable" is a misspelling of "available" Raw Output: ./onnxruntime/test/perftest/ort_test_session.cc:112:17: "avaiable" is a misspelling of "available"
}

provider_name_ = performance_test_config.machine_config.provider_type_name;
std::unordered_map<std::string, std::string> provider_options;
if (provider_name_ == onnxruntime::kDnnlExecutionProvider) {
Expand Down Expand Up @@ -574,7 +624,8 @@
#endif
} else if (!provider_name_.empty() &&
provider_name_ != onnxruntime::kCpuExecutionProvider &&
provider_name_ != onnxruntime::kOpenVINOExecutionProvider) {
provider_name_ != onnxruntime::kOpenVINOExecutionProvider &&
!is_plugin_ep_avaiable) {

Check warning on line 628 in onnxruntime/test/perftest/ort_test_session.cc

View workflow job for this annotation

GitHub Actions / Optional Lint

[misspell] reported by reviewdog 🐶 "avaiable" is a misspelling of "available" Raw Output: ./onnxruntime/test/perftest/ort_test_session.cc:628:27: "avaiable" is a misspelling of "available"
ORT_THROW("This backend is not included in perf test runner.\n");
}

Expand Down
1 change: 1 addition & 0 deletions onnxruntime/test/perftest/ort_test_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class OnnxRuntimeTestSession : public TestSession {
const int input_length_;
std::string provider_name_;
std::string device_memory_name_; // Device memory type name to use from the list in allocator.h
std::vector<std::string> registered_plugin_ep_names_;
Comment thread
chilo-ms marked this conversation as resolved.
Outdated
};

} // namespace perftest
Expand Down
1 change: 1 addition & 0 deletions onnxruntime/test/perftest/test_configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ struct PerformanceTestConfig {
ModelInfo model_info;
MachineConfig machine_config;
RunConfig run_config;
std::basic_string<ORTCHAR_T> plugin_ep_names_and_libs;
};

} // namespace perftest
Expand Down
Loading