From a088d1ab7dd92d471f392003df05d3daa8c903cd Mon Sep 17 00:00:00 2001 From: "Wang, Yang" Date: Fri, 17 Feb 2023 14:15:38 +0800 Subject: [PATCH] Disable core::set_property() to support ov::device::properties setting (#15175) * Disable set_property() to support ov::device::properties setting. * Update benchmark APP to set device properties through compile_model() instead of through set_property(). * Update. * Update. * Update some test case including ov::device::properties setting via core.ser_property(). * Since core.set_property() didn't support ov::device::properties setting, just remove the test case to check compile_model() works well if setting ov::device::properties via core.set_property() first. * Update CompileModel in test name to CompiledModel Co-authored-by: Ilya Lavrenov * Add corresponding test case. Signed-off-by: Wang, Yang * Update. * Update. * Remove the changes of this commit as this modification has nothing to do with this PR. This reverts commit 4f04b9f085307aaeefcbad69fa368abfcb079df2. --------- Signed-off-by: Wang, Yang Co-authored-by: Chen Peter Co-authored-by: Ilya Lavrenov --- samples/cpp/benchmark_app/main.cpp | 17 ++++--- src/inference/src/dev/core_impl.cpp | 31 +++++------- src/inference/src/dev/core_impl.hpp | 2 +- src/inference/src/ie_core.cpp | 4 +- .../behavior/ov_plugin/core_integration.hpp | 47 ++++++------------- .../behavior/ov_plugin/properties_tests.cpp | 15 +----- .../openvino/tools/benchmark/main.py | 9 ++-- 7 files changed, 49 insertions(+), 76 deletions(-) diff --git a/samples/cpp/benchmark_app/main.cpp b/samples/cpp/benchmark_app/main.cpp index 0723c1531c9..c5eae11edf9 100644 --- a/samples/cpp/benchmark_app/main.cpp +++ b/samples/cpp/benchmark_app/main.cpp @@ -606,11 +606,14 @@ int main(int argc, char* argv[]) { device_nstreams.erase(device); } } - - for (auto&& item : config) { - core.set_property(item.first, item.second); - } - + auto result = std::find_if(config.begin(), config.end(), [&](const std::pair& item) { + if (device_name.find(item.first) == 0) + return true; + return false; + }); + ov::AnyMap device_config = {}; + if (result != config.end()) + device_config = result->second; size_t batchSize = FLAGS_b; ov::element::Type type = ov::element::undefined; std::string topology_name = ""; @@ -642,7 +645,7 @@ int main(int argc, char* argv[]) { next_step(); slog::info << "Skipping the step for loading model from file" << slog::endl; auto startTime = Time::now(); - compiledModel = core.compile_model(FLAGS_m, device_name); + compiledModel = core.compile_model(FLAGS_m, device_name, device_config); auto duration_ms = get_duration_ms_till_now(startTime); slog::info << "Compile model took " << double_to_string(duration_ms) << " ms" << slog::endl; slog::info << "Original model I/O parameters:" << slog::endl; @@ -821,7 +824,7 @@ int main(int argc, char* argv[]) { // -------------------------------------------------------- next_step(); startTime = Time::now(); - compiledModel = core.compile_model(model, device_name); + compiledModel = core.compile_model(model, device_name, device_config); duration_ms = get_duration_ms_till_now(startTime); slog::info << "Compile model took " << double_to_string(duration_ms) << " ms" << slog::endl; if (statistics) diff --git a/src/inference/src/dev/core_impl.cpp b/src/inference/src/dev/core_impl.cpp index c7d3581ca4f..d05b9e9c817 100644 --- a/src/inference/src/dev/core_impl.cpp +++ b/src/inference/src/dev/core_impl.cpp @@ -615,24 +615,19 @@ void ov::CoreImpl::set_property(const std::string& device_name, const AnyMap& pr "set_property is supported only for BATCH itself (without devices). " "You can configure the devices with set_property before creating the BATCH on top."); - bool isMetaDevice = device_name.find("AUTO") != std::string::npos || - device_name.find("MULTI") != std::string::npos || - device_name.find("HETERO") != std::string::npos; - if (!isMetaDevice) { - // unsupport to set ov::device::properties to HW device through this function - auto devices = get_registered_devices(); - for (auto&& config : properties) { - auto parsed = parseDeviceNameIntoConfig(config.first); - auto is_secondary_config_for_hw_device = - std::any_of(devices.begin(), devices.end(), [&](const std::string& device) { - return device == parsed._deviceName; - }); - OPENVINO_ASSERT(!is_secondary_config_for_hw_device, - "set_property only supported ov::device::propreties for Meta device (AUTO/MULTI/HETERO). " - "You can configure the devices through the compile_model()/loadNetwork() API."); - } + // unsupport to set ov::device::properties to HW device through this function + auto devices = get_registered_devices(); + for (auto&& config : properties) { + auto parsed = parseDeviceNameIntoConfig(config.first); + auto is_secondary_config_for_hw_device = + std::any_of(devices.begin(), devices.end(), [&](const std::string& device) { + return device == parsed._deviceName; + }); + OPENVINO_ASSERT(!is_secondary_config_for_hw_device, + "set_property do not support ov::device::propreties. " + "You can configure the devices through the compile_model()/loadNetwork() API."); } - set_property_for_devivce(properties, device_name); + set_property_for_device(properties, device_name); } ov::Any ov::CoreImpl::get_property_for_core(const std::string& name) const { @@ -724,7 +719,7 @@ std::vector ov::CoreImpl::get_registered_devices() const { * @note `deviceName` is not allowed in form of MULTI:CPU, HETERO:GPU,CPU, AUTO:CPU * just simple forms like CPU, GPU, MULTI, GPU.0, etc */ -void ov::CoreImpl::set_property_for_devivce(const ov::AnyMap& configMap, const std::string& deviceName) { +void ov::CoreImpl::set_property_for_device(const ov::AnyMap& configMap, const std::string& deviceName) { auto config = configMap; if (config.empty()) { return; diff --git a/src/inference/src/dev/core_impl.hpp b/src/inference/src/dev/core_impl.hpp index 1b015a39bfd..b743b158e55 100644 --- a/src/inference/src/dev/core_impl.hpp +++ b/src/inference/src/dev/core_impl.hpp @@ -385,7 +385,7 @@ public: * @note `deviceName` is not allowed in form of MULTI:CPU, HETERO:GPU,CPU, AUTO:CPU * just simple forms like CPU, GPU, MULTI, GPU.0, etc */ - void set_property_for_devivce(const ov::AnyMap& configMap, const std::string& deviceName); + void set_property_for_device(const ov::AnyMap& configMap, const std::string& deviceName); void add_extension(const std::vector& extensions); diff --git a/src/inference/src/ie_core.cpp b/src/inference/src/ie_core.cpp index 694065c30f2..7093e42bfcb 100644 --- a/src/inference/src/ie_core.cpp +++ b/src/inference/src/ie_core.cpp @@ -269,9 +269,9 @@ void Core::SetConfig(const std::map& config, const std ov::AnyMap conf = ov::any_copy(config); if (deviceName.empty()) { - _impl->set_property_for_devivce(conf, std::string()); + _impl->set_property_for_device(conf, std::string()); } else { - _impl->set_property_for_devivce(conf, deviceName); + _impl->set_property_for_device(conf, deviceName); } } diff --git a/src/tests/functional/plugin/shared/include/behavior/ov_plugin/core_integration.hpp b/src/tests/functional/plugin/shared/include/behavior/ov_plugin/core_integration.hpp index 7ff084c49b8..358c4b55dfe 100644 --- a/src/tests/functional/plugin/shared/include/behavior/ov_plugin/core_integration.hpp +++ b/src/tests/functional/plugin/shared/include/behavior/ov_plugin/core_integration.hpp @@ -326,6 +326,21 @@ TEST(OVClassBasicTest, smoke_SetConfigHeteroThrows) { OV_ASSERT_NO_THROW(ie.set_property(CommonTestUtils::DEVICE_HETERO, ov::enable_profiling(true))); } +TEST(OVClassBasicTest, smoke_SetConfigDevicePropertiesThrows) { + ov::Core ie = createCoreWithTemplate(); + ASSERT_THROW(ie.set_property("", ov::device::properties(CommonTestUtils::DEVICE_CPU, ov::enable_profiling(true))), + ov::Exception); + ASSERT_THROW(ie.set_property(CommonTestUtils::DEVICE_CPU, + ov::device::properties(CommonTestUtils::DEVICE_CPU, ov::enable_profiling(true))), + ov::Exception); + ASSERT_THROW(ie.set_property(CommonTestUtils::DEVICE_AUTO, + ov::device::properties(CommonTestUtils::DEVICE_CPU, ov::enable_profiling(true))), + ov::Exception); + ASSERT_THROW(ie.set_property(CommonTestUtils::DEVICE_AUTO, + ov::device::properties(CommonTestUtils::DEVICE_CPU, ov::num_streams(4))), + ov::Exception); +} + TEST_P(OVClassBasicTestP, SetConfigHeteroTargetFallbackThrows) { ov::Core ie = createCoreWithTemplate(); OV_ASSERT_NO_THROW(ie.set_property(CommonTestUtils::DEVICE_HETERO, ov::device::priorities(target_device))); @@ -360,38 +375,6 @@ TEST(OVClassBasicTest, smoke_SetConfigAutoNoThrows) { EXPECT_EQ(value, ov::hint::Priority::HIGH); } -TEST(OVClassBasicTest, smoke_SetConfigWithNoChangeToHWPluginThroughMetaPluginNoThrows) { - ov::Core ie = createCoreWithTemplate(); - int32_t preValue = -1, curValue = -1; - - ASSERT_NO_THROW(ie.set_property(CommonTestUtils::DEVICE_CPU, {ov::num_streams(20)})); - ASSERT_NO_THROW(curValue = ie.get_property(CommonTestUtils::DEVICE_CPU, ov::num_streams)); - EXPECT_EQ(curValue, 20); - std::vector metaDevices = {CommonTestUtils::DEVICE_AUTO, - CommonTestUtils::DEVICE_MULTI, - CommonTestUtils::DEVICE_HETERO}; - - for (auto&& metaDevice : metaDevices) { - ASSERT_NO_THROW(preValue = ie.get_property(CommonTestUtils::DEVICE_CPU, ov::num_streams)); - ASSERT_NO_THROW( - ie.set_property(metaDevice, {ov::device::properties(CommonTestUtils::DEVICE_CPU, ov::num_streams(20))})); - ASSERT_NO_THROW(curValue = ie.get_property(CommonTestUtils::DEVICE_CPU, ov::num_streams)); - EXPECT_EQ(curValue, preValue); - } - ASSERT_THROW(ie.set_property(CommonTestUtils::DEVICE_CPU, - {ov::device::properties(CommonTestUtils::DEVICE_CPU, ov::num_streams(20))}), - ov::Exception); - ASSERT_THROW(ie.set_property(CommonTestUtils::DEVICE_GPU, - {ov::device::properties(CommonTestUtils::DEVICE_CPU, ov::num_streams(20))}), - ov::Exception); - ASSERT_THROW(ie.set_property(CommonTestUtils::DEVICE_GPU, - {ov::device::properties("GPU.0", ov::num_streams(20))}), - ov::Exception); - ASSERT_THROW(ie.set_property("GPU.0", - {ov::device::properties("GPU.0", ov::num_streams(20))}), - ov::Exception); -} - TEST_P(OVClassSpecificDeviceTestSetConfig, SetConfigSpecificDeviceNoThrow) { ov::Core ie = createCoreWithTemplate(); diff --git a/src/tests/functional/plugin/shared/src/behavior/ov_plugin/properties_tests.cpp b/src/tests/functional/plugin/shared/src/behavior/ov_plugin/properties_tests.cpp index 4a6cb0106ec..9b619d41d99 100644 --- a/src/tests/functional/plugin/shared/src/behavior/ov_plugin/properties_tests.cpp +++ b/src/tests/functional/plugin/shared/src/behavior/ov_plugin/properties_tests.cpp @@ -195,23 +195,12 @@ 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); } -TEST_P(OVSetSupportPropComplieModleWithoutConfigTests, SetPropertyComplieModelWithCorrectProperty) { - OV_ASSERT_NO_THROW(core->set_property(target_device, properties)); - ASSERT_NO_THROW(core->compile_model(model, target_device, {})); -} - -TEST_P(OVSetUnsupportPropComplieModleWithoutConfigTests, SetPropertyComplieModelWithIncorrectProperty) { - OV_ASSERT_NO_THROW(core->set_property(target_device, properties)); - ASSERT_THROW(core->compile_model(model, target_device, {}), ov::Exception); +TEST_P(OVSetSupportPropComplieModleWithoutConfigTests, SetPropertyCompiledModelWithCorrectProperty) { + ASSERT_NO_THROW(core->compile_model(model, target_device, properties)); } std::string OVCompileModelGetExecutionDeviceTests::getTestCaseName(testing::TestParamInfo obj) { diff --git a/tools/benchmark_tool/openvino/tools/benchmark/main.py b/tools/benchmark_tool/openvino/tools/benchmark/main.py index 3945e4d135f..96eb30056a2 100644 --- a/tools/benchmark_tool/openvino/tools/benchmark/main.py +++ b/tools/benchmark_tool/openvino/tools/benchmark/main.py @@ -322,7 +322,10 @@ def main(): del device_number_streams[device] perf_counts = perf_counts - benchmark.set_config(config) + device_config = {} + for device in config: + if benchmark.device.find(device) == 0: + device_config = config[device] if args.cache_dir: benchmark.set_cache_dir(args.cache_dir) @@ -348,7 +351,7 @@ def main(): next_step() start_time = datetime.utcnow() - compiled_model = benchmark.core.compile_model(args.path_to_model, benchmark.device) + compiled_model = benchmark.core.compile_model(args.path_to_model, benchmark.device, device_config) duration_ms = f"{(datetime.utcnow() - start_time).total_seconds() * 1000:.2f}" logger.info(f"Compile model took {duration_ms} ms") if statistics: @@ -411,7 +414,7 @@ def main(): next_step() start_time = datetime.utcnow() - compiled_model = benchmark.core.compile_model(model, benchmark.device) + compiled_model = benchmark.core.compile_model(model, benchmark.device, device_config) duration_ms = f"{(datetime.utcnow() - start_time).total_seconds() * 1000:.2f}" logger.info(f"Compile model took {duration_ms} ms") if statistics: