Skip to content

Commit ea7d681

Browse files
preetha-intelankitm3k
authored andcommitted
Add support for parsing AUTO, HETERO and MULTI from json config (#605)
* Add support for parsing AUTO, HETERO and MULTI from json config * Fix lint issues * Address review comments
1 parent f213710 commit ea7d681

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

onnxruntime/core/providers/openvino/backends/basic_backend.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ void BasicBackend::PopulateConfigValue(ov::AnyMap& device_config) {
284284
//// Parse to get the device mode (e.g., "AUTO:CPU,GPU" -> "AUTO")
285285
std::unordered_set<std::string> supported_mode = {"AUTO", "HETERO", "MULTI"};
286286
auto device_mode = find_device_type_mode(session_context_.device_type);
287-
ORT_ENFORCE(supported_mode.find(device_mode) != supported_mode.end(), " Invalid device mode is passed : ", session_context_.device_type);
287+
ORT_ENFORCE(supported_mode.find(device_mode)!=supported_mode.end(), " Invalid device mode is passed : " , session_context_.device_type);
288288
// Parse individual devices (e.g., "AUTO:CPU,GPU" -> ["CPU", "GPU"])
289289
auto individual_devices = parse_individual_devices(session_context_.device_type);
290290
if (!device_mode.empty()) individual_devices.emplace_back(device_mode);

onnxruntime/core/providers/openvino/openvino_provider_factory.cc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,19 @@ struct OpenVINO_Provider : Provider {
221221
continue;
222222
}
223223

224-
// Ensure that the value for each device is an object (PROPERTY -> VALUE)
225-
if (!value.is_object()) {
226-
ORT_THROW("Invalid JSON structure: Expected an object for device properties.");
227-
}
224+
for (auto& [key, value] : json_config.items()) {
225+
ov::AnyMap inner_map;
226+
std::set<std::string> valid_ov_devices = {"CPU", "GPU", "NPU", "AUTO", "HETERO", "MULTI"};
227+
// Ensure the key is one of "CPU", "GPU", or "NPU"
228+
if (valid_ov_devices.find(key) == valid_ov_devices.end()) {
229+
LOGS_DEFAULT(WARNING) << "Unsupported device key: " << key << ". Skipping entry.\n";
230+
continue;
231+
}
232+
233+
// Ensure that the value for each device is an object (PROPERTY -> VALUE)
234+
if (!value.is_object()) {
235+
ORT_THROW("Invalid JSON structure: Expected an object for device properties.");
236+
}
228237

229238
for (auto& [inner_key, inner_value] : value.items()) {
230239
if (inner_value.is_string()) {

0 commit comments

Comments
 (0)