diff --git a/onnxruntime/core/providers/openvino/openvino_provider_factory.cc b/onnxruntime/core/providers/openvino/openvino_provider_factory.cc index 4a1b2b83c9f81..22dc0abbb44a7 100644 --- a/onnxruntime/core/providers/openvino/openvino_provider_factory.cc +++ b/onnxruntime/core/providers/openvino/openvino_provider_factory.cc @@ -445,17 +445,35 @@ struct OpenVINO_Provider : Provider { return Status(common::ONNXRUNTIME, ORT_EP_FAIL, "No devices provided to CreateEp"); } - // Block setting certain provider options via AppendExecutionProvider_V2 - // TODO: Expand this out and give better guidance for keys that should now flow through load_config. - const std::unordered_set blocked_provider_keys = { - "device_type", "device_id", "device_luid", "cache_dir", "precision", - "context", "num_of_threads", "model_priority", "num_streams", - "enable_opencl_throttling", "enable_qdq_optimizer", "disable_dynamic_shapes"}; + // For provider options that we don't support anymore, give some guidance & examples + // about how to make use of the option through load_config. + const std::vector> block_and_advise_entries = { + {"cache_dir", "\"CACHE_DIR\": \"\""}, + {"precision", "\"INFERENCE_PRECISION_HINT\": \"F32\""}, + {"num_streams", "\"NUM_STREAMS\": \"1\""}, + {"model_priority", "\"MODEL_PRIORITY\": \"LOW\""}, + {"enable_opencl_throttling", "\"GPU\": {\"PLUGIN_THROTTLE\": \"1\"}"}, + {"enable_qdq_optimizer", "\"NPU\": {\"NPU_QDQ_OPTIMIZATION\": \"YES\"}"} + }; + + for (auto& block_and_advise_entry : block_and_advise_entries) { + if (provider_options.find(block_and_advise_entry.first) != provider_options.end()) { + std::string message = "OpenVINO EP: Option '" + block_and_advise_entry.first + + "' cannot be set when using AppendExecutionProvider_V2. " + + "It can instead be enabled by a load_config key / value pair. For example: " + + block_and_advise_entry.second; + return Status(common::ONNXRUNTIME, ORT_INVALID_ARGUMENT, message); + } + } + + // For the rest of the disallowed provider options, give a generic error message. + const std::vector blocked_provider_keys = { + "device_type", "device_id", "device_luid", "context", "num_of_threads", "disable_dynamic_shapes"}; for (const auto& key : blocked_provider_keys) { if (provider_options.find(key) != provider_options.end()) { return Status(common::ONNXRUNTIME, ORT_INVALID_ARGUMENT, - "OpenVINO EP: Option '" + key + "' cannot be set explicitly when using AppendExecutionProvider_V2."); + "OpenVINO EP: Option '" + key + "' cannot be set when using AppendExecutionProvider_V2."); } } diff --git a/onnxruntime/test/providers/openvino/openvino_plugin.cc b/onnxruntime/test/providers/openvino/openvino_plugin.cc index bf2cb698a8aa2..5abca55820a24 100644 --- a/onnxruntime/test/providers/openvino/openvino_plugin.cc +++ b/onnxruntime/test/providers/openvino/openvino_plugin.cc @@ -137,6 +137,22 @@ TEST_F(OrtEpLibraryOv, MetaDevicesAvailable) { } } +TEST_F(OrtEpLibraryOv, RunSessionWithAllAUTODevices) { + auto ep_devices = ort_env->GetEpDevices(); + std::vector matching_devices; + + for (const auto& device : ep_devices) { + std::string ep_name = device.EpName(); + if (ep_name.find(registration_name) != std::string::npos && + (ep_name == registration_name + ".AUTO")) { + matching_devices.push_back(device); + } + } + Ort::SessionOptions session_options; + session_options.AppendExecutionProvider_V2(*ort_env, matching_devices, std::unordered_map{}); + Ort::Session session(*ort_env, ORT_TSTR("testdata/mul_1.onnx"), session_options); +} + TEST_F(OrtEpLibraryOv, PluginEp_AppendV2_MulInference) { auto plugin_ep_device = GetOvCpuEpDevice(); ASSERT_NE(plugin_ep_device, nullptr); @@ -178,6 +194,31 @@ TEST_F(OrtEpLibraryOv, PluginEp_AppendV2_cpu_epctx_variants) { } } +TEST_F(OrtEpLibraryOv, PluginEp_CheckV2DisallowedProviderOptions) { + auto plugin_ep_device = GetOvCpuEpDevice(); + ASSERT_NE(plugin_ep_device, nullptr); + std::vector> disallowed_provider_option_examples = { + {{"device_type", "CPU"}}, + {{"device_id", "CPU"}}, + {{"device_luid", "1234"}}, + {{"cache_dir", "cache"}}, + {{"precision", "F32"}}, + {{"context", "4"}}, + {{"num_of_threads", "1"}}, + {{"model_priority", "DEFAULT"}}, + {{"num_streams", "1"}}, + {{"enable_opencl_throttling", "true"}}, + {{"enable_qdq_optimizer", "true"}}, + {{"disable_dynamic_shapes", "true"}}, + }; + for (auto& example : disallowed_provider_option_examples) { + EXPECT_THROW({ + Ort::SessionOptions session_options; + session_options.AppendExecutionProvider_V2(*ort_env, std::vector{plugin_ep_device}, example); + Ort::Session session(*ort_env, ORT_TSTR("testdata/mul_1.onnx"), session_options); }, Ort::Exception); + } +} + TEST_F(OrtEpLibraryOv, GenerateEpContextEmbedded) { GenerateEpContextOnPluginPath(ORT_TSTR("mul_1_ctx_cpu_embed1.onnx"), true); }