add value verification to check if device priorities value is available (#12069)

* add value verificatioin for the key ov::device::priorities and corresponding test case.

Signed-off-by: Wang, Yang <yang4.wang@intel.com>

* Update.

Signed-off-by: Wang, Yang <yang4.wang@intel.com>

* Retrieve the device name via the DeviceIDParser rather than via the priorities directly.

Signed-off-by: Wang, Yang <yang4.wang@intel.com>

* Add logic to support devices like CPU(x),GPU(x).

Signed-off-by: Wang, Yang <yang4.wang@intel.com>

* Update.

Signed-off-by: Wang, Yang <yang4.wang@intel.com>

* Update.

Signed-off-by: Wang, Yang <yang4.wang@intel.com>

* Add 'mock' as a available device name when checking if ov::device::priorities is correct.

Signed-off-by: Wang, Yang <yang4.wang@intel.com>

* Update.

Signed-off-by: Wang, Yang <yang4.wang@intel.com>

* Update.

Signed-off-by: Wang, Yang <yang4.wang@intel.com>

* Update.

Signed-off-by: Wang, Yang <yang4.wang@intel.com>

* Update format.

Signed-off-by: Wang, Yang <yang4.wang@intel.com>

* do not check if priorities is available when value of priorigies is empty.

Signed-off-by: Wang, Yang <yang4.wang@intel.com>

* Update.

Signed-off-by: Wang, Yang <yang4.wang@intel.com>

Signed-off-by: Wang, Yang <yang4.wang@intel.com>
Co-authored-by: Chen Peter <peter.chen@intel.com>
This commit is contained in:
Wang, Yang 2022-08-22 12:51:49 +08:00 committed by GitHub
parent c35af4c0d0
commit 1c6f460458
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 121 additions and 21 deletions

View File

@ -83,16 +83,7 @@ std::vector<DeviceInformation> MultiDeviceInferencePlugin::ParseMetaDevices(cons
std::vector<DeviceInformation> metaDevices; std::vector<DeviceInformation> metaDevices;
// parsing the string and splitting to tokens // parsing the string and splitting to tokens
std::vector<std::string> devicesWithRequests; std::vector<std::string> devicesWithRequests = _pluginConfig.ParsePrioritiesDevices(priorities);
// parsing the string and splitting the comma-separated tokens
std::string::size_type i = 0;
std::string::size_type idelimeter;
while ((idelimeter = priorities.find(',', i)) != std::string::npos) {
devicesWithRequests.push_back(priorities.substr(i, idelimeter - i));
i = idelimeter + 1;
}
// last token in the string (which has no comma after that)
devicesWithRequests.push_back(priorities.substr(i, priorities.length() - i));
auto getDeviceConfig = [&] (const DeviceName & deviceWithID) { auto getDeviceConfig = [&] (const DeviceName & deviceWithID) {
DeviceIDParser deviceParser(deviceWithID); DeviceIDParser deviceParser(deviceWithID);
@ -764,17 +755,9 @@ std::string MultiDeviceInferencePlugin::GetDeviceList(const std::map<std::string
allDevices += ((device == deviceList[deviceList.size()-1]) ? "" : ","); allDevices += ((device == deviceList[deviceList.size()-1]) ? "" : ",");
} }
} else { } else {
// parsing the string and splitting the comma-separated tokens
std::string::size_type i = 0;
std::string::size_type idelimeter;
std::vector<std::string> deviceVec;
auto priorities = deviceListConfig->second; auto priorities = deviceListConfig->second;
while ((idelimeter = priorities.find(',', i)) != std::string::npos) { // parsing the string and splitting the comma-separated tokens
deviceVec.push_back(priorities.substr(i, idelimeter - i)); std::vector<std::string> deviceVec = _pluginConfig.ParsePrioritiesDevices(priorities);
i = idelimeter + 1;
}
// last token in the string (which has no comma after that)
deviceVec.push_back(priorities.substr(i, priorities.length() - i));
std::vector<std::string> devicesToBeDeleted; std::vector<std::string> devicesToBeDeleted;
auto updateDeviceVec = [&](const std::string& delPattern = "") { auto updateDeviceVec = [&](const std::string& delPattern = "") {
auto iter = deviceVec.begin(); auto iter = deviceVec.begin();

View File

@ -92,6 +92,8 @@ struct PluginConfig {
IE_THROW() << "Unsupported config value: " << kvp.second IE_THROW() << "Unsupported config value: " << kvp.second
<< " for key: " << kvp.first; << " for key: " << kvp.first;
} else if (kvp.first == ov::device::priorities.name()) { } else if (kvp.first == ov::device::priorities.name()) {
if (!kvp.second.empty())
ParsePrioritiesDevices(kvp.second);
_devicePriority = kvp.second; _devicePriority = kvp.second;
} else if (std::find(perf_hints_configs.begin(), perf_hints_configs.end(), kvp.first) != perf_hints_configs.end()) { } else if (std::find(perf_hints_configs.begin(), perf_hints_configs.end(), kvp.first) != perf_hints_configs.end()) {
_perfHintsConfig.SetConfig(kvp.first, kvp.second); _perfHintsConfig.SetConfig(kvp.first, kvp.second);
@ -111,6 +113,42 @@ struct PluginConfig {
_keyConfigMap.clear(); _keyConfigMap.clear();
adjustKeyMapValues(); adjustKeyMapValues();
} }
std::vector<std::string> ParsePrioritiesDevices(const std::string& priorities, const char separator = ',') const {
std::vector<std::string> devices;
std::string::size_type pos = 0;
std::string::size_type endpos = 0;
auto isAvailableDevice = [&](std::string& deviceName) -> bool {
if (deviceName.empty())
return false;
auto realDevName = deviceName[0] != '-' ? deviceName : deviceName.substr(1);
if (realDevName.empty()) {
return false;
}
realDevName = DeviceIDParser(realDevName).getDeviceName();
std::string::size_type realEndPos = 0;
if ((realEndPos = realDevName.find('(')) != std::string::npos) {
realDevName = realDevName.substr(0, realEndPos);
}
if (_availableDevices.end() == std::find(_availableDevices.begin(), _availableDevices.end(), realDevName)) {
return false;
}
return true;
};
while ((endpos = priorities.find(separator, pos)) != std::string::npos) {
auto subStr = priorities.substr(pos, endpos - pos);
if (!isAvailableDevice(subStr)) {
IE_THROW() << "Unavailable device name: " << subStr;
}
devices.push_back(subStr);
pos = endpos + 1;
}
auto subStr = priorities.substr(pos, priorities.length() - pos);
if (!isAvailableDevice(subStr)) {
IE_THROW() << "Unavailable device name: " << subStr;
}
devices.push_back(subStr);
return devices;
}
void adjustKeyMapValues() { void adjustKeyMapValues() {
if (_useProfiling) { if (_useProfiling) {
_keyConfigMap[PluginConfigParams::KEY_PERF_COUNT] = PluginConfigParams::YES; _keyConfigMap[PluginConfigParams::KEY_PERF_COUNT] = PluginConfigParams::YES;
@ -165,6 +203,18 @@ struct PluginConfig {
PerfHintsConfig _perfHintsConfig; PerfHintsConfig _perfHintsConfig;
std::map<std::string, std::string> _passThroughConfig; std::map<std::string, std::string> _passThroughConfig;
std::map<std::string, std::string> _keyConfigMap; std::map<std::string, std::string> _keyConfigMap;
const std::set<std::string> _availableDevices = {"CPU", "GPU", "GNA", "TEMPLATE", "MYRAID", "HDDL", "VPUX", "MULTI", "HETERO", "CUDA", "HPU_GOYA"}; const std::set<std::string> _availableDevices = {"AUTO",
"CPU",
"GPU",
"GNA",
"TEMPLATE",
"MYRIAD",
"HDDL",
"VPUX",
"MULTI",
"HETERO",
"CUDA",
"HPU_GOYA",
"mock"};
}; };
} // namespace MultiDevicePlugin } // namespace MultiDevicePlugin

View File

@ -31,12 +31,69 @@ const std::vector<ov::AnyMap> auto_multi_properties = {
{ov::device::priorities(CommonTestUtils::DEVICE_GPU), ov::intel_auto::device_bind_buffer("NO")} {ov::device::priorities(CommonTestUtils::DEVICE_GPU), ov::intel_auto::device_bind_buffer("NO")}
}; };
const std::vector<ov::AnyMap> multi_properties = {
{ov::device::priorities("CPU", "GPU")},
{ov::device::priorities("CPU(1)", "GPU")},
{ov::device::priorities("CPU(1)", "GPU(2)")}
};
const std::vector<ov::AnyMap> auto_properties = {
{ov::device::priorities("CPU", "GPU")},
{ov::device::priorities("-CPU", "GPU")},
{ov::device::priorities("CPU(1)", "GPU")},
{ov::device::priorities("CPU(1)", "GPU(2)")},
{ov::device::priorities("CPU", "-GPU")}
};
const std::vector<ov::AnyMap> auto_Multi_compiled_empty_properties = {
{}
};
const std::vector<ov::AnyMap> multi_plugin_Incorrect_properties = {
{ov::device::priorities("NONE")}
};
const std::vector<ov::AnyMap> auto_plugin_Incorrect_properties = {
{ov::device::priorities("NONE", "GPU")},
{ov::device::priorities("-", "GPU")},
{ov::device::priorities("-NONE", "CPU")},
{ov::device::priorities("-CPU", "-NONE")},
{ov::device::priorities("-NONE", "-NONE")}
};
INSTANTIATE_TEST_SUITE_P(smoke_AutoMultiBehaviorTests, OVPropertiesTests, INSTANTIATE_TEST_SUITE_P(smoke_AutoMultiBehaviorTests, OVPropertiesTests,
::testing::Combine( ::testing::Combine(
::testing::Values(CommonTestUtils::DEVICE_AUTO, CommonTestUtils::DEVICE_MULTI), ::testing::Values(CommonTestUtils::DEVICE_AUTO, CommonTestUtils::DEVICE_MULTI),
::testing::ValuesIn(auto_multi_properties)), ::testing::ValuesIn(auto_multi_properties)),
OVPropertiesTests::getTestCaseName); OVPropertiesTests::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_AutoBehaviorTests, OVPropertiesTests,
::testing::Combine(
::testing::Values(CommonTestUtils::DEVICE_AUTO),
::testing::ValuesIn(auto_properties)),
OVPropertiesTests::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_MultiBehaviorTests, OVPropertiesTests,
::testing::Combine(
::testing::Values(CommonTestUtils::DEVICE_MULTI),
::testing::ValuesIn(multi_properties)),
OVPropertiesTests::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_AutoBehaviorIncorrectPropertiesTests, OVSetPropComplieModleWihtIncorrectPropTests,
::testing::Combine(
::testing::Values(CommonTestUtils::DEVICE_AUTO),
::testing::ValuesIn(auto_plugin_Incorrect_properties),
::testing::ValuesIn(auto_Multi_compiled_empty_properties)),
OVSetPropComplieModleWihtIncorrectPropTests::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_MultiBehaviorIncorrectPropertiesTests, OVSetPropComplieModleWihtIncorrectPropTests,
::testing::Combine(
::testing::Values(CommonTestUtils::DEVICE_MULTI),
::testing::ValuesIn(multi_plugin_Incorrect_properties),
::testing::ValuesIn(auto_Multi_compiled_empty_properties)),
OVSetPropComplieModleWihtIncorrectPropTests::getTestCaseName);
const std::vector<ov::AnyMap> gpu_plugin_properties = { const std::vector<ov::AnyMap> gpu_plugin_properties = {
{ov::hint::performance_mode(ov::hint::PerformanceMode::THROUGHPUT), {ov::hint::performance_mode(ov::hint::PerformanceMode::THROUGHPUT),
ov::hint::num_requests(2), ov::hint::num_requests(2),

View File

@ -56,6 +56,7 @@ public:
AnyMap compileModelProperties; AnyMap compileModelProperties;
}; };
using OVSetPropComplieModleWihtIncorrectPropTests = OVSetPropComplieModleGetPropTests;
} // namespace behavior } // namespace behavior
} // namespace test } // namespace test

View File

@ -145,6 +145,15 @@ TEST_P(OVSetPropComplieModleGetPropTests, SetPropertyComplieModelGetProperty) {
} }
} }
TEST_P(OVSetPropComplieModleWihtIncorrectPropTests, SetPropertyComplieModelWithIncorrectProperty) {
OV_ASSERT_NO_THROW(core->set_property(target_device, properties));
ASSERT_THROW(core->compile_model(model, target_device, compileModelProperties), ov::Exception);
}
TEST_P(OVSetPropComplieModleWihtIncorrectPropTests, CanNotCompileModelWithIncorrectProperties) {
ASSERT_THROW(core->compile_model(model, target_device, properties), ov::Exception);
}
} // namespace behavior } // namespace behavior
} // namespace test } // namespace test
} // namespace ov } // namespace ov