From 8ca6aeae83f9b8613aec19a20490eae529aa3309 Mon Sep 17 00:00:00 2001 From: Anton Pankratov Date: Tue, 1 Feb 2022 13:05:14 +0300 Subject: [PATCH] New configuration API in set get property (#10012) * New configuration API in set|get property * removed supported metrics and keys * Fixed build * Fixed build * Fixed samples build * Fixed samples build * Fixed build * Removed old properties in plugin * Fixed build --- samples/cpp/benchmark_app/main.cpp | 35 +++++++++---------- .../common/utils/include/samples/common.hpp | 6 ++-- samples/cpp/hello_query_device/main.cpp | 27 +++++--------- .../python/src/pyopenvino/core/common.cpp | 16 +++------ .../src/cpp/ie_executable_network.cpp | 17 +++++++-- src/inference/src/ie_core.cpp | 5 ++- .../exec_network_base.hpp | 22 ++++++------ .../src/behavior/ov_plugin/life_time.cpp | 2 +- tools/compile_tool/main.cpp | 4 ++- 9 files changed, 64 insertions(+), 70 deletions(-) diff --git a/samples/cpp/benchmark_app/main.cpp b/samples/cpp/benchmark_app/main.cpp index 1b8ef2991a3..f746afc52fa 100644 --- a/samples/cpp/benchmark_app/main.cpp +++ b/samples/cpp/benchmark_app/main.cpp @@ -193,15 +193,15 @@ int main(int argc, char* argv[]) { if (FLAGS_hint.empty()) { for (auto& device : devices) { - std::vector supported_config_keys = - core.get_property(device, METRIC_KEY(SUPPORTED_CONFIG_KEYS)); - if (std::find(supported_config_keys.begin(), - supported_config_keys.end(), - CONFIG_KEY(PERFORMANCE_HINT)) != supported_config_keys.end()) { - slog::warn << "-hint default value is determined as " << CONFIG_VALUE(THROUGHPUT) + auto supported_properties = core.get_property(device, ov::supported_properties); + if (std::find(supported_properties.begin(), supported_properties.end(), ov::hint::performance_mode) != + supported_properties.end()) { + slog::warn << "-hint default value is determined as " << ov::hint::PerformanceMode::THROUGHPUT << " automatically for " << device << " device. For more detailed information look at README." << slog::endl; - FLAGS_hint = CONFIG_VALUE(THROUGHPUT); + std::stringstream strm; + strm << ov::hint::PerformanceMode::THROUGHPUT; + FLAGS_hint = strm.str(); } } } @@ -280,10 +280,9 @@ int main(int argc, char* argv[]) { const std::string key = getDeviceTypeFromName(device) + "_THROUGHPUT_STREAMS"; if (device_nstreams.count(device)) { // set to user defined value - std::vector supported_config_keys = - core.get_property(device, METRIC_KEY(SUPPORTED_CONFIG_KEYS)); - if (std::find(supported_config_keys.begin(), supported_config_keys.end(), key) == - supported_config_keys.end()) { + auto supported_properties = core.get_property(device, ov::supported_properties); + if (std::find(supported_properties.begin(), supported_properties.end(), key) == + supported_properties.end()) { throw std::logic_error("Device " + device + " doesn't support config key '" + key + "'! " + "Please specify -nstreams for correct devices in format " ":,:" + @@ -350,11 +349,10 @@ int main(int argc, char* argv[]) { else device_config[GNA_CONFIG_KEY(PRECISION)] = "I16"; } else { - std::vector supported_config_keys = - core.get_property(device, METRIC_KEY(SUPPORTED_CONFIG_KEYS)); + auto supported_properties = core.get_property(device, ov::supported_properties); auto supported = [&](const std::string& key) { - return std::find(std::begin(supported_config_keys), std::end(supported_config_keys), key) != - std::end(supported_config_keys); + return std::find(std::begin(supported_properties), std::end(supported_properties), key) != + std::end(supported_properties); }; if (supported(CONFIG_KEY(CPU_THREADS_NUM)) && isFlagSetInCommandLine("nthreads")) { device_config[CONFIG_KEY(CPU_THREADS_NUM)] = std::to_string(FLAGS_nthreads); @@ -380,7 +378,7 @@ int main(int argc, char* argv[]) { // Takes priority over config from file if (!FLAGS_cache_dir.empty()) { - core.set_property({{CONFIG_KEY(CACHE_DIR), FLAGS_cache_dir}}); + core.set_property(ov::cache_dir(FLAGS_cache_dir)); } bool isDynamicNetwork = false; @@ -618,10 +616,9 @@ int main(int argc, char* argv[]) { next_step(); // output of the actual settings that the device selected for (const auto& device : devices) { - std::vector supported_config_keys = - core.get_property(device, METRIC_KEY(SUPPORTED_CONFIG_KEYS)); + auto supported_properties = core.get_property(device, ov::supported_properties); slog::info << "Device: " << device << slog::endl; - for (const auto& cfg : supported_config_keys) { + for (const auto& cfg : supported_properties) { try { slog::info << " {" << cfg << " , " << compiledModel.get_property(cfg).as(); slog::info << " }" << slog::endl; diff --git a/samples/cpp/common/utils/include/samples/common.hpp b/samples/cpp/common/utils/include/samples/common.hpp index 16d6889f82e..532e361402d 100644 --- a/samples/cpp/common/utils/include/samples/common.hpp +++ b/samples/cpp/common/utils/include/samples/common.hpp @@ -977,12 +977,10 @@ inline void showAvailableDevices() { std::map parseConfig(const std::string& configName, char comment = '#'); inline std::string getFullDeviceName(ov::Core& core, std::string device) { - ov::Any p; try { - p = core.get_property(device, METRIC_KEY(FULL_DEVICE_NAME)); - return p.as(); + return core.get_property(device, ov::device::full_name); } catch (ov::Exception&) { - return ""; + return {}; } } diff --git a/samples/cpp/hello_query_device/main.cpp b/samples/cpp/hello_query_device/main.cpp index 0ec17053d69..8e7bdef7519 100644 --- a/samples/cpp/hello_query_device/main.cpp +++ b/samples/cpp/hello_query_device/main.cpp @@ -105,25 +105,14 @@ int main(int argc, char* argv[]) { for (auto&& device : availableDevices) { slog::info << device << slog::endl; - // Query supported metrics and print all of them - slog::info << "\tSUPPORTED_METRICS: " << slog::endl; - std::vector supportedMetrics = core.get_property(device, METRIC_KEY(SUPPORTED_METRICS)); - for (auto&& metricName : supportedMetrics) { - if (metricName != METRIC_KEY(SUPPORTED_METRICS) && metricName != METRIC_KEY(SUPPORTED_CONFIG_KEYS)) { - slog::info << "\t\t" << metricName << " : " << slog::flush; - print_any_value(core.get_property(device, metricName)); - } - } - - // Query supported config keys and print all of them - if (std::find(supportedMetrics.begin(), supportedMetrics.end(), METRIC_KEY(SUPPORTED_CONFIG_KEYS)) != - supportedMetrics.end()) { - slog::info << "\tSUPPORTED_CONFIG_KEYS (default values): " << slog::endl; - std::vector supportedConfigKeys = - core.get_property(device, METRIC_KEY(SUPPORTED_CONFIG_KEYS)); - for (auto&& configKey : supportedConfigKeys) { - slog::info << "\t\t" << configKey << " : " << slog::flush; - print_any_value(core.get_property(device, configKey)); + // Query supported properties and print all of them + slog::info << "\tSUPPORTED_PROPERTIES: " << slog::endl; + auto supported_properties = core.get_property(device, ov::supported_properties); + for (auto&& property : supported_properties) { + if (property != ov::supported_properties.name()) { + slog::info << "\t\t" << (property.is_mutable() ? "Mutable: " : "Immutable: ") << property << " : " + << slog::flush; + print_any_value(core.get_property(device, property)); } } diff --git a/src/bindings/python/src/pyopenvino/core/common.cpp b/src/bindings/python/src/pyopenvino/core/common.cpp index f4e76eae004..2a993b75a98 100644 --- a/src/bindings/python/src/pyopenvino/core/common.cpp +++ b/src/bindings/python/src/pyopenvino/core/common.cpp @@ -301,18 +301,12 @@ PyAny from_ov_any(const ov::Any& any) { uint32_t get_optimal_number_of_requests(const ov::CompiledModel& actual) { try { - auto parameter_value = actual.get_property(METRIC_KEY(SUPPORTED_METRICS)); - auto supported_metrics = parameter_value.as>(); - const std::string key = METRIC_KEY(OPTIMAL_NUMBER_OF_INFER_REQUESTS); - if (std::find(supported_metrics.begin(), supported_metrics.end(), key) != supported_metrics.end()) { - parameter_value = actual.get_property(key); - if (parameter_value.is()) - return parameter_value.as(); - else - IE_THROW() << "Unsupported format for " << key << "!" - << " Please specify number of infer requests directly!"; + auto supported_properties = actual.get_property(ov::supported_properties); + if (std::find(supported_properties.begin(), supported_properties.end(), ov::optimal_number_of_infer_requests) != + supported_properties.end()) { + return actual.get_property(ov::optimal_number_of_infer_requests); } else { - IE_THROW() << "Can't load network: " << key << " is not supported!" + IE_THROW() << "Can't load network: " << ov::optimal_number_of_infer_requests.name() << " is not supported!" << " Please specify number of infer requests directly!"; } } catch (const std::exception& ex) { diff --git a/src/inference/src/cpp/ie_executable_network.cpp b/src/inference/src/cpp/ie_executable_network.cpp index 5b0bb8132fd..6368852116e 100644 --- a/src/inference/src/cpp/ie_executable_network.cpp +++ b/src/inference/src/cpp/ie_executable_network.cpp @@ -216,13 +216,24 @@ Any CompiledModel::get_property(const std::string& name) const { OV_EXEC_NET_CALL_STATEMENT({ if (ov::supported_properties == name) { try { - return {_impl->GetMetric(name), _so}; + auto supported_properties = _impl->GetMetric(name).as>(); + supported_properties.erase(std::remove_if(supported_properties.begin(), + supported_properties.end(), + [](const ov::PropertyName& name) { + return name == METRIC_KEY(SUPPORTED_METRICS) || + name == METRIC_KEY(SUPPORTED_CONFIG_KEYS); + }), + supported_properties.end()); + return supported_properties; } catch (ie::Exception&) { auto ro_properties = _impl->GetMetric(METRIC_KEY(SUPPORTED_METRICS)).as>(); - auto rw_properties = _impl->GetConfig(METRIC_KEY(SUPPORTED_CONFIG_KEYS)).as>(); + auto rw_properties = _impl->GetMetric(METRIC_KEY(SUPPORTED_CONFIG_KEYS)).as>(); std::vector supported_properties; for (auto&& ro_property : ro_properties) { - supported_properties.emplace_back(ro_property, PropertyMutability::RO); + if (ro_property != METRIC_KEY(SUPPORTED_METRICS) && + ro_property != METRIC_KEY(SUPPORTED_CONFIG_KEYS)) { + supported_properties.emplace_back(ro_property, PropertyMutability::RO); + } } for (auto&& rw_property : rw_properties) { supported_properties.emplace_back(rw_property, PropertyMutability::RW); diff --git a/src/inference/src/ie_core.cpp b/src/inference/src/ie_core.cpp index 724ed69fb4e..4d79faf70c4 100644 --- a/src/inference/src/ie_core.cpp +++ b/src/inference/src/ie_core.cpp @@ -1808,7 +1808,10 @@ Any Core::get_property(const std::string& deviceName, const std::string& name) c .as>(); std::vector supported_properties; for (auto&& ro_property : ro_properties) { - supported_properties.emplace_back(ro_property, PropertyMutability::RO); + if (ro_property != METRIC_KEY(SUPPORTED_METRICS) && + ro_property != METRIC_KEY(SUPPORTED_CONFIG_KEYS)) { + supported_properties.emplace_back(ro_property, PropertyMutability::RO); + } } for (auto&& rw_property : rw_properties) { supported_properties.emplace_back(rw_property, PropertyMutability::RW); diff --git a/src/tests/functional/plugin/shared/include/behavior/ov_executable_network/exec_network_base.hpp b/src/tests/functional/plugin/shared/include/behavior/ov_executable_network/exec_network_base.hpp index 6a013934cc9..ffc951ae4b2 100644 --- a/src/tests/functional/plugin/shared/include/behavior/ov_executable_network/exec_network_base.hpp +++ b/src/tests/functional/plugin/shared/include/behavior/ov_executable_network/exec_network_base.hpp @@ -104,24 +104,24 @@ TEST_P(OVExecutableNetworkBaseTest, checkGetExecGraphInfoIsNotNullptr) { TEST_P(OVExecutableNetworkBaseTest, checkGetMetric) { auto execNet = core->compile_model(function, targetDevice, configuration); - EXPECT_NO_THROW(execNet.get_property(METRIC_KEY(SUPPORTED_CONFIG_KEYS))); + EXPECT_NO_THROW(execNet.get_property(ov::supported_properties)); } TEST_P(OVExecutableNetworkBaseTest, canLoadCorrectNetworkToGetExecutableAndCheckConfig) { auto execNet = core->compile_model(function, targetDevice, configuration); for (const auto& configItem : configuration) { - InferenceEngine::Parameter param; + ov::Any param; EXPECT_NO_THROW(param = execNet.get_property(configItem.first)); EXPECT_FALSE(param.empty()); - EXPECT_EQ(param, InferenceEngine::Parameter(configItem.second)); + EXPECT_EQ(param, configItem.second); } } TEST_P(OVExecutableNetworkBaseTest, CanSetConfigToExecNet) { auto execNet = core->compile_model(function, targetDevice); - std::map config; + std::map config; for (const auto& confItem : configuration) { - config.insert({confItem.first, InferenceEngine::Parameter(confItem.second)}); + config.emplace(confItem.first, confItem.second); } EXPECT_NO_THROW(execNet.set_property(config)); } @@ -129,25 +129,25 @@ TEST_P(OVExecutableNetworkBaseTest, CanSetConfigToExecNet) { TEST_P(OVExecutableNetworkBaseTest, CanSetConfigToExecNetWithIncorrectConfig) { auto execNet = core->compile_model(function, targetDevice); std::map incorrectConfig = {{"abc", "def"}}; - std::map config; + std::map config; for (const auto& confItem : incorrectConfig) { - config.insert({confItem.first, InferenceEngine::Parameter(confItem.second)}); + config.emplace(confItem.first, confItem.second); } EXPECT_ANY_THROW(execNet.set_property(config)); } TEST_P(OVExecutableNetworkBaseTest, CanSetConfigToExecNetAndCheckConfigAndCheck) { auto execNet = core->compile_model(function, targetDevice); - std::map config; + std::map config; for (const auto& confItem : configuration) { - config.insert({confItem.first, InferenceEngine::Parameter(confItem.second)}); + config.emplace(confItem.first, confItem.second); } execNet.set_property(config); for (const auto& configItem : configuration) { - InferenceEngine::Parameter param; + ov::Any param; EXPECT_NO_THROW(param = execNet.get_property(configItem.first)); EXPECT_FALSE(param.empty()); - EXPECT_EQ(param, InferenceEngine::Parameter(configItem.second)); + EXPECT_EQ(param, configItem.second); } } diff --git a/src/tests/functional/plugin/shared/src/behavior/ov_plugin/life_time.cpp b/src/tests/functional/plugin/shared/src/behavior/ov_plugin/life_time.cpp index 9639539e408..b7e67945eb4 100644 --- a/src/tests/functional/plugin/shared/src/behavior/ov_plugin/life_time.cpp +++ b/src/tests/functional/plugin/shared/src/behavior/ov_plugin/life_time.cpp @@ -87,7 +87,7 @@ TEST_P(OVHoldersTest, LoadedAny) { { ov::Core core = createCoreWithTemplate(); auto compiled_model = core.compile_model(function, targetDevice); - any = compiled_model.get_property(METRIC_KEY(SUPPORTED_METRICS)); + any = compiled_model.get_property(ov::supported_properties.name()); } } diff --git a/tools/compile_tool/main.cpp b/tools/compile_tool/main.cpp index 4dc199cc2db..01ca69692f6 100644 --- a/tools/compile_tool/main.cpp +++ b/tools/compile_tool/main.cpp @@ -781,7 +781,9 @@ int main(int argc, char* argv[]) { } else { ov::Core core; if (!FLAGS_log_level.empty()) { - core.set_property(FLAGS_d, {{CONFIG_KEY(LOG_LEVEL), FLAGS_log_level}}); + ov::log::Level level; + std::stringstream{FLAGS_log_level} >> level; + core.set_property(FLAGS_d, ov::log::level(level)); } auto model = core.read_model(FLAGS_m);