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
32 changes: 25 additions & 7 deletions onnxruntime/core/providers/openvino/openvino_provider_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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<std::pair<std::string, std::string>> block_and_advise_entries = {
{"cache_dir", "\"CACHE_DIR\": \"<filesystem_path>\""},
{"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<std::string> 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.");
}
}

Expand Down
41 changes: 41 additions & 0 deletions onnxruntime/test/providers/openvino/openvino_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ TEST_F(OrtEpLibraryOv, MetaDevicesAvailable) {
}
}

TEST_F(OrtEpLibraryOv, RunSessionWithAllAUTODevices) {
auto ep_devices = ort_env->GetEpDevices();
std::vector<Ort::ConstEpDevice> 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<std::string, std::string>{});
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);
Expand Down Expand Up @@ -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<std::unordered_map<std::string, std::string>> 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<Ort::ConstEpDevice>{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);
}
Expand Down
Loading