Skip to content

Commit

Permalink
Insert validDeviceName function to parseDeviceNameIntoConfig and rewr…
Browse files Browse the repository at this point in the history
…ite tests
  • Loading branch information
awayzjj committed Feb 26, 2024
1 parent b368bc1 commit 040a8ee
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 80 deletions.
19 changes: 11 additions & 8 deletions src/inference/src/dev/core_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@ void stripDeviceName(std::string& device, const std::string& substr) {
}
}

void validDeviceName(const std::string& device) {
auto pos = device.rfind(")");
if (pos != std::string::npos && pos != device.length() - 1) {
OPENVINO_THROW("Device with \"", device, "\" name is illegal in the OpenVINO Runtime");
}
}

bool is_virtual_device(const std::string& device_name) {
return (device_name.find("AUTO") != std::string::npos || device_name.find("MULTI") != std::string::npos ||
device_name.find("HETERO") != std::string::npos || device_name.find("BATCH") != std::string::npos);
Expand Down Expand Up @@ -248,6 +241,16 @@ bool ov::is_config_applicable(const std::string& user_device_name, const std::st
ov::Parsed ov::parseDeviceNameIntoConfig(const std::string& deviceName,
const AnyMap& config,
const bool keep_core_property) {

// check
auto bracket_pos = deviceName.find(")");
while (bracket_pos != std::string::npos) {
if (bracket_pos < deviceName.length() - 1 && deviceName[bracket_pos + 1] != ',') {
OPENVINO_THROW("Device with \"", deviceName, "\" name is illegal in the OpenVINO Runtime");
}
bracket_pos = deviceName.find(")", bracket_pos + 1);
}

auto updated_config = config;
auto updated_device_name = deviceName;

Expand Down Expand Up @@ -716,9 +719,9 @@ ov::Plugin ov::CoreImpl::get_plugin(const std::string& pluginName) const {
ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model(const std::shared_ptr<const ov::Model>& model_,
const std::string& device_name,
const ov::AnyMap& config) const {

OV_ITT_SCOPE(FIRST_INFERENCE, ov::itt::domains::LoadTime, "Core::compile_model::model");
std::string deviceName = device_name;
validDeviceName(deviceName);
ov::AnyMap config_with_batch = config;
// if auto-batching is applicable, the below function will patch the device name and config accordingly:
auto model = apply_auto_batching(model_, deviceName, config_with_batch);
Expand Down
5 changes: 5 additions & 0 deletions src/inference/tests/unit/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,11 @@ TEST(CoreTests_parse_device_config, get_device_config) {
"HETERO",
ov::AnyMap{ov::device::priorities("MULTI,DEVICE"),
ov::device::properties(ov::AnyMap{{"MULTI", ov::AnyMap{ov::device::priorities("DEVICE")}}})});

// invalid device name with characters after parenthesis except comma
EXPECT_THROW(ov::parseDeviceNameIntoConfig("DEVICE(0)ov", ov::AnyMap{}), ov::Exception);
EXPECT_THROW(ov::parseDeviceNameIntoConfig("MULTI:DEVICE(0)ov,DEVICE(1)", ov::AnyMap{}), ov::Exception);

}

class ApplyAutoBatchThreading : public testing::Test {
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 040a8ee

Please sign in to comment.