Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion onnxruntime/test/perftest/command_args_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ ABSL_FLAG(std::string, select_ep_devices, "", "Specifies a semicolon-separated l
ABSL_FLAG(std::string, filter_ep_devices, "",
"Specifies EP or Device metadata entries as key-value pairs to filter ep devices passed to AppendExecutionProvider_V2.\n"
"[Usage]: --filter_ep_devices \"<key1>|<value1> <key2>|<value2>\" \n"
"Devices that match any of the key-value pair will be appended to the session. --select_ep_devices will take precedence over this option.\n");
"Devices that match any of the key-value pair will be appended to the session. --select_ep_devices will take precedence over this option.\n"
"[Example] --filter_ep_devices \"ov_device|NPU ov_device|CPU\" \n"
"Above example will append npu device first if available, followed by cpu device.");
ABSL_FLAG(bool, compile_ep_context, DefaultPerformanceTestConfig().run_config.compile_ep_context, "Generate an EP context model");
ABSL_FLAG(std::string, compile_model_path, "model_ctx.onnx", "The compiled model path for saving EP context model. Overwrites if already exists");
ABSL_FLAG(bool, compile_binary_embed, DefaultPerformanceTestConfig().run_config.compile_binary_embed, "Embed binary blob within EP context node");
Expand Down
21 changes: 13 additions & 8 deletions onnxruntime/test/perftest/ort_test_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,20 @@ OnnxRuntimeTestSession::OnnxRuntimeTestSession(Ort::Env& env, std::random_device
}
} else if (!performance_test_config.filter_ep_device_kv_pairs.empty()) {
// Find and select the OrtEpDevice associated with the EP in "--filter_ep_devices".
for (size_t index = 0; index < ep_devices.size(); ++index) {
auto device = ep_devices[index];
if (ep_set.find(std::string(device.EpName())) == ep_set.end())
continue;
for (const auto& kv : performance_test_config.filter_ep_device_kv_pairs) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good. I would only recommend updating the usage documentation for this option to explicitly define what the expected matching order should be.

Perhaps a simple example like:
--filter_ep_devices "ov_device|NPU ov_device|CPU" means that an NPU device, if available, will be added first before one with cpu.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, also skipped if the device already added.

for (size_t index = 0; index < ep_devices.size(); ++index) {
auto device = ep_devices[index];
if (ep_set.find(std::string(device.EpName())) == ep_set.end())
continue;

// Skip if deviced was already added
if (added_ep_devices.find(device.EpName()) != added_ep_devices.end() &&
std::find(added_ep_devices[device.EpName()].begin(), added_ep_devices[device.EpName()].end(), device) != added_ep_devices[device.EpName()].end())
continue;

// Check both EP metadata and device metadata for a match
auto ep_metadata_kv_pairs = device.EpMetadata().GetKeyValuePairs();
auto device_metadata_kv_pairs = device.Device().Metadata().GetKeyValuePairs();
for (const auto& kv : performance_test_config.filter_ep_device_kv_pairs) {
// Check both EP metadata and device metadata for a match
auto ep_metadata_kv_pairs = device.EpMetadata().GetKeyValuePairs();
auto device_metadata_kv_pairs = device.Device().Metadata().GetKeyValuePairs();
auto ep_metadata_itr = ep_metadata_kv_pairs.find(kv.first);
auto device_metadata_itr = device_metadata_kv_pairs.find(kv.first);

Expand Down
Loading