diff --git a/onnxruntime/test/perftest/command_args_parser.cc b/onnxruntime/test/perftest/command_args_parser.cc index 83d533d5185ca..e06cca73b95b7 100644 --- a/onnxruntime/test/perftest/command_args_parser.cc +++ b/onnxruntime/test/perftest/command_args_parser.cc @@ -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 \"| |\" \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"); diff --git a/onnxruntime/test/perftest/ort_test_session.cc b/onnxruntime/test/perftest/ort_test_session.cc index dd0ed75f4782f..b9ec73da40bf4 100644 --- a/onnxruntime/test/perftest/ort_test_session.cc +++ b/onnxruntime/test/perftest/ort_test_session.cc @@ -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) { + 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);