From 4cbcf4b4e340366232ea57aac3d97a81717e61f6 Mon Sep 17 00:00:00 2001 From: Anton Pankratov Date: Tue, 1 Feb 2022 23:56:52 +0300 Subject: [PATCH] Added get property additional arguments (#9993) * Added get property additional arguments * Fixed build * Fixed error * Added api wiht property and map * Fixed gna build * reverted available_devices --- .../openvino/runtime/compiled_model.hpp | 2 +- .../include/openvino/runtime/core.hpp | 100 ++++++++++++++---- .../include/openvino/runtime/properties.hpp | 16 +-- src/inference/src/ie_core.cpp | 13 ++- .../behavior/ov_plugin/core_integration.hpp | 16 +++ 5 files changed, 114 insertions(+), 33 deletions(-) diff --git a/src/inference/include/openvino/runtime/compiled_model.hpp b/src/inference/include/openvino/runtime/compiled_model.hpp index d7df1ac7e9b..8713bcd64bc 100644 --- a/src/inference/include/openvino/runtime/compiled_model.hpp +++ b/src/inference/include/openvino/runtime/compiled_model.hpp @@ -175,7 +175,7 @@ public: * @return nothing */ template - util::EnableIfAllProperties set_property(Properties&&... properties) { + util::EnableIfAllStringAny set_property(Properties&&... properties) { set_property(AnyMap{std::forward(properties)...}); } diff --git a/src/inference/include/openvino/runtime/core.hpp b/src/inference/include/openvino/runtime/core.hpp index 22c1f96603c..759490732f8 100644 --- a/src/inference/include/openvino/runtime/core.hpp +++ b/src/inference/include/openvino/runtime/core.hpp @@ -42,7 +42,7 @@ class OPENVINO_RUNTIME_API Core { class Impl; std::shared_ptr _impl; - void get_property(const std::string& device_name, const std::string& name, ov::Any& to) const; + void get_property(const std::string& device_name, const std::string& name, const AnyMap& arguments, Any& to) const; public: /** @brief Constructs OpenVINO Core instance using XML configuration file with @@ -139,7 +139,7 @@ public: * @return A compiled model */ template - util::EnableIfAllProperties compile_model( + util::EnableIfAllStringAny compile_model( const std::shared_ptr& model, Properties&&... properties) { return compile_model(model, AnyMap{std::forward(properties)...}); @@ -174,7 +174,7 @@ public: * @return A compiled model */ template - util::EnableIfAllProperties compile_model( + util::EnableIfAllStringAny compile_model( const std::shared_ptr& model, const std::string& device_name, Properties&&... properties) { @@ -211,8 +211,8 @@ public: * @return A compiled model */ template - util::EnableIfAllProperties compile_model(const std::string& model_path, - Properties&&... properties) { + util::EnableIfAllStringAny compile_model(const std::string& model_path, + Properties&&... properties) { return compile_model(model_path, AnyMap{std::forward(properties)...}); } @@ -248,9 +248,9 @@ public: * @return A compiled model */ template - util::EnableIfAllProperties compile_model(const std::string& model_path, - const std::string& device_name, - Properties&&... properties) { + util::EnableIfAllStringAny compile_model(const std::string& model_path, + const std::string& device_name, + Properties&&... properties) { return compile_model(model_path, device_name, AnyMap{std::forward(properties)...}); } @@ -276,7 +276,7 @@ public: * @return A compiled model object */ template - util::EnableIfAllProperties compile_model( + util::EnableIfAllStringAny compile_model( const std::shared_ptr& model, const RemoteContext& context, Properties&&... properties) { @@ -388,9 +388,9 @@ public: * @return A compiled model */ template - util::EnableIfAllProperties import_model(std::istream& model_stream, - const std::string& device_name, - Properties&&... properties) { + util::EnableIfAllStringAny import_model(std::istream& model_stream, + const std::string& device_name, + Properties&&... properties) { return import_model(model_stream, device_name, AnyMap{std::forward(properties)...}); } @@ -416,9 +416,9 @@ public: * @return A compiled model */ template - util::EnableIfAllProperties import_model(std::istream& model_stream, - const RemoteContext& context, - Properties&&... properties) { + util::EnableIfAllStringAny import_model(std::istream& model_stream, + const RemoteContext& context, + Properties&&... properties) { return import_model(model_stream, context, AnyMap{std::forward(properties)...}); } @@ -445,7 +445,7 @@ public: * @return An object containing a map of pairs a operation name -> a device name supporting this operation. */ template - util::EnableIfAllProperties query_model( + util::EnableIfAllStringAny query_model( const std::shared_ptr& model, const std::string& device_name, Properties&&... properties) const { @@ -469,7 +469,7 @@ public: * @return nothing */ template - util::EnableIfAllProperties set_property(Properties&&... properties) { + util::EnableIfAllStringAny set_property(Properties&&... properties) { set_property(AnyMap{std::forward(properties)...}); } @@ -491,8 +491,8 @@ public: * @return nothing */ template - util::EnableIfAllProperties set_property(const std::string& device_name, - Properties&&... properties) { + util::EnableIfAllStringAny set_property(const std::string& device_name, + Properties&&... properties) { set_property(device_name, AnyMap{std::forward(properties)...}); } @@ -507,6 +507,18 @@ public: */ Any get_property(const std::string& device_name, const std::string& name) const; + /** + * @brief Gets properties dedicated to device behaviour. + * + * The method is targeted to extract information which can be set via set_property method. + * + * @param device_name - A name of a device to get a properties value. + * @param name - property name. + * @param arguments - additional arguments to get property + * @return Value of property corresponding to property name. + */ + Any get_property(const std::string& device_name, const std::string& name, const AnyMap& arguments) const; + /** * @brief Gets properties dedicated to device behaviour. * @@ -514,6 +526,7 @@ public: * It can be device name, temperature, other devices-specific values. * * @tparam T - type of returned value + * @tparam M - property mutability * @param deviceName - A name of a device to get a properties value. * @param property - property object. * @return Property value. @@ -521,7 +534,50 @@ public: template T get_property(const std::string& deviceName, const ov::Property& property) const { auto to = Any::make(); - get_property(deviceName, property.name(), to); + get_property(deviceName, property.name(), {}, to); + return to.template as(); + } + + /** + * @brief Gets properties dedicated to device behaviour. + * + * The method is needed to request common device or system properties. + * It can be device name, temperature, other devices-specific values. + * + * @tparam T - type of returned value + * @tparam M - property mutability + * @param deviceName - A name of a device to get a properties value. + * @param property - property object. + * @param arguments - additional arguments to get property + * @return Property value. + */ + template + T get_property(const std::string& deviceName, const ov::Property& property, const AnyMap& arguments) const { + auto to = Any::make(); + get_property(deviceName, property.name(), arguments, to); + return to.template as(); + } + + /** + * @brief Gets properties dedicated to device behaviour. + * + * The method is needed to request common device or system properties. + * It can be device name, temperature, other devices-specific values. + * + * @tparam T - type of returned value + * @tparam M - property mutability + * @tparam Args - set of additional arguments ended with property object variable + * @param deviceName - A name of a device to get a properties value. + * @param property - property object. + * @param args - Optional pack of pairs: (argument name, argument value) ended with property object + * @return Property value. + */ + template + util::EnableIfAllStringAny get_property(const std::string& deviceName, + const ov::Property& property, + Args&&... args) const { + auto to = Any::make(); + get_property(deviceName, property.name(), AnyMap{std::forward(args)...}, to); return to.template as(); } @@ -609,8 +665,8 @@ public: * @return A shared pointer to a created remote context. */ template - util::EnableIfAllProperties create_context(const std::string& device_name, - Properties&&... properties) { + util::EnableIfAllStringAny create_context(const std::string& device_name, + Properties&&... properties) { return create_context(device_name, AnyMap{std::forward(properties)...}); } diff --git a/src/inference/include/openvino/runtime/properties.hpp b/src/inference/include/openvino/runtime/properties.hpp index 5f8dd0d248f..61c8bbf31a8 100644 --- a/src/inference/include/openvino/runtime/properties.hpp +++ b/src/inference/include/openvino/runtime/properties.hpp @@ -59,29 +59,31 @@ private: /** @cond INTERNAL */ namespace util { +struct PropertyTag {}; + template -struct AllProperties; +struct StringAny; template -struct AllProperties { +struct StringAny { constexpr static const bool value = - std::is_convertible>::value && AllProperties::value; + std::is_convertible>::value && StringAny::value; }; template -struct AllProperties { +struct StringAny { constexpr static const bool value = std::is_convertible>::value; }; template -using EnableIfAllProperties = typename std::enable_if::value, T>::type; +using EnableIfAllStringAny = typename std::enable_if::value, T>::type; /** * @brief This class is used to bind property name with property type * @tparam T type of value used to pass or get property */ template -struct BaseProperty { +struct BaseProperty : public PropertyTag { using value_type = T; //!< Property type constexpr static const auto mutability = mutability_; //!< Property readability @@ -468,7 +470,7 @@ struct Properties { * @return Pair of string key representation and type erased property value. */ template - inline util::EnableIfAllProperties, Properties...> operator()( + inline util::EnableIfAllStringAny, Properties...> operator()( const std::string& device_name, Properties&&... configs) const { return {device_name, AnyMap{std::pair{configs}...}}; diff --git a/src/inference/src/ie_core.cpp b/src/inference/src/ie_core.cpp index 4d79faf70c4..f6fa491b688 100644 --- a/src/inference/src/ie_core.cpp +++ b/src/inference/src/ie_core.cpp @@ -1784,6 +1784,10 @@ void Core::set_property(const std::string& deviceName, const AnyMap& config) { } Any Core::get_property(const std::string& deviceName, const std::string& name) const { + return get_property(deviceName, name, AnyMap{}); +} + +Any Core::get_property(const std::string& deviceName, const std::string& name, const AnyMap& arguments) const { OPENVINO_ASSERT(deviceName.find("HETERO:") != 0, "You can only get_config of the HETERO itself (without devices). " "get_config is also possible for the individual devices before creating the HETERO on top."); @@ -1795,7 +1799,7 @@ Any Core::get_property(const std::string& deviceName, const std::string& name) c "get_config is also possible for the individual devices before creating the AUTO on top."); OV_CORE_CALL_STATEMENT({ - auto parsed = parseDeviceNameIntoConfig(deviceName); + auto parsed = parseDeviceNameIntoConfig(deviceName, arguments); if (ov::supported_properties == name) { try { return _impl->GetCPPPluginByName(parsed._deviceName).get_metric(name, parsed._config); @@ -1828,8 +1832,11 @@ Any Core::get_property(const std::string& deviceName, const std::string& name) c }); } -void Core::get_property(const std::string& deviceName, const std::string& name, ov::Any& to) const { - any_lexical_cast(get_property(deviceName, name), to); +void Core::get_property(const std::string& deviceName, + const std::string& name, + const AnyMap& arguments, + ov::Any& to) const { + any_lexical_cast(get_property(deviceName, name, arguments), to); } std::vector Core::get_available_devices() const { 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 5656baed0bb..7d01bdfdab8 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 @@ -61,6 +61,7 @@ using OVClassGetMetricTest_SUPPORTED_METRICS = OVClassBaseTestP; using OVClassGetMetricTest_SUPPORTED_CONFIG_KEYS = OVClassBaseTestP; using OVClassGetMetricTest_AVAILABLE_DEVICES = OVClassBaseTestP; using OVClassGetMetricTest_FULL_DEVICE_NAME = OVClassBaseTestP; +using OVClassGetMetricTest_FULL_DEVICE_NAME_with_DEVICE_ID = OVClassBaseTestP; using OVClassGetMetricTest_OPTIMIZATION_CAPABILITIES = OVClassBaseTestP; using OVClassGetMetricTest_DEVICE_GOPS = OVClassBaseTestP; using OVClassGetMetricTest_DEVICE_TYPE = OVClassBaseTestP; @@ -551,6 +552,21 @@ TEST_P(OVClassGetMetricTest_FULL_DEVICE_NAME, GetMetricAndPrintNoThrow) { OV_ASSERT_PROPERTY_SUPPORTED(ov::device::full_name); } +TEST_P(OVClassGetMetricTest_FULL_DEVICE_NAME_with_DEVICE_ID, GetMetricAndPrintNoThrow) { + ov::Core ie = createCoreWithTemplate(); + std::string t; + + if (supportsDeviceID(ie, deviceName)) { + auto device_ids = ie.get_property(deviceName, ov::available_devices); + ASSERT_GT(device_ids.size(), 0); + OV_ASSERT_NO_THROW(t = ie.get_property(deviceName, ov::device::full_name, ov::device::id(device_ids.front()))); + std::cout << "Device " << device_ids.front() << " " << ", Full device name: " << std::endl << t << std::endl; + OV_ASSERT_PROPERTY_SUPPORTED(ov::device::full_name); + } else { + GTEST_SKIP() << "Device id is not supported"; + } +} + TEST_P(OVClassGetMetricTest_OPTIMIZATION_CAPABILITIES, GetMetricAndPrintNoThrow) { ov::Core ie = createCoreWithTemplate(); std::vector t;