diff --git a/src/bindings/python/src/pyopenvino/core/core.cpp b/src/bindings/python/src/pyopenvino/core/core.cpp index ea363ab69b2..aa2754b8234 100644 --- a/src/bindings/python/src/pyopenvino/core/core.cpp +++ b/src/bindings/python/src/pyopenvino/core/core.cpp @@ -110,6 +110,21 @@ void regclass_Core(py::module m) { :rtype: object )"); + cls.def( + "get_property", + [](ov::Core& self, const std::string& property) -> py::object { + return Common::utils::from_ov_any(self.get_property(property)); + }, + py::arg("property"), + R"( + Gets properties dedicated to Core behaviour. + + :param property: Property or name of Property. + :type property: str + :return: Extracted information from property. + :rtype: object + )"); + cls.def( "compile_model", [](ov::Core& self, diff --git a/src/bindings/python/tests/test_runtime/test_properties.py b/src/bindings/python/tests/test_runtime/test_properties.py index a60b8d29c63..b2ddc1a7e9e 100644 --- a/src/bindings/python/tests/test_runtime/test_properties.py +++ b/src/bindings/python/tests/test_runtime/test_properties.py @@ -79,6 +79,10 @@ def test_properties_core(properties_to_set): core = Core() core.set_property(properties_to_set) + # RW properties without device name + assert core.get_property(properties.cache_dir()) == "./" + assert core.get_property(properties.force_tbb_terminate()) is False + # RW properties assert core.get_property("CPU", properties.enable_profiling()) is True assert core.get_property("CPU", properties.cache_dir()) == "./" diff --git a/src/inference/include/openvino/runtime/core.hpp b/src/inference/include/openvino/runtime/core.hpp index d6ab0989e4b..a542ce17da0 100644 --- a/src/inference/include/openvino/runtime/core.hpp +++ b/src/inference/include/openvino/runtime/core.hpp @@ -519,6 +519,18 @@ public: */ Any get_property(const std::string& device_name, const std::string& name, const AnyMap& arguments) const; + /** + * @brief Gets properties related to core behaviour. + * + * The method extracts information that can be set via the set_property method. + * + * @param name Property name. + * @return Value of a property corresponding to the property name. + */ + Any get_property(const std::string& name) const { + return get_property(std::string(), name); + } + /** * @brief Gets properties related to device behaviour. * diff --git a/src/inference/src/ie_core.cpp b/src/inference/src/ie_core.cpp index 799b0b8e318..98e547e0701 100644 --- a/src/inference/src/ie_core.cpp +++ b/src/inference/src/ie_core.cpp @@ -190,6 +190,11 @@ class CoreImpl : public ie::ICore, public std::enable_shared_from_this lock(_cacheConfigMutex); + return _cacheConfig._cacheDir; + } + // Creating thread-safe copy of config including shared_ptr to ICacheManager // Passing empty or not-existing name will return global cache config CacheConfig getCacheConfigForDevice(const std::string& device_name, @@ -885,22 +890,34 @@ public: SetConfigForPlugins(any_copy(properties), device_name); } - Any get_property(const std::string& deviceName, const std::string& name, const AnyMap& arguments) const override { - 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."); - OPENVINO_ASSERT(deviceName.find("MULTI:") != 0, - "You can only get_config of the MULTI itself (without devices). " - "get_config is also possible for the individual devices before creating the MULTI on top."); - OPENVINO_ASSERT(deviceName.find("AUTO:") != 0, - "You can only get_config of the AUTO itself (without devices). " - "get_config is also possible for the individual devices before creating the AUTO on top."); - + Any get_property_for_core(const std::string& name) const { if (name == ov::force_tbb_terminate.name()) { const auto flag = executorManager()->getTbbFlag(); return decltype(ov::force_tbb_terminate)::value_type(flag); + } else if (name == ov::cache_dir.name()) { + return ov::Any(coreConfig.get_cache_dir()); } - auto parsed = parseDeviceNameIntoConfig(deviceName, arguments); + + IE_THROW() << "Exception is thrown while trying to call get_property with unsupported property: '" << name + << "'"; + } + + Any get_property(const std::string& device_name, const std::string& name, const AnyMap& arguments) const override { + OPENVINO_ASSERT(device_name.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."); + OPENVINO_ASSERT(device_name.find("MULTI:") != 0, + "You can only get_config of the MULTI itself (without devices). " + "get_config is also possible for the individual devices before creating the MULTI on top."); + OPENVINO_ASSERT(device_name.find("AUTO:") != 0, + "You can only get_config of the AUTO itself (without devices). " + "get_config is also possible for the individual devices before creating the AUTO on top."); + + if (device_name.empty()) { + return get_property_for_core(name); + } + + auto parsed = parseDeviceNameIntoConfig(device_name, arguments); return GetCPPPluginByName(parsed._deviceName).get_property(name, parsed._config); } 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 3754fb57a28..4cfbf3473e5 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 @@ -388,18 +388,35 @@ TEST_P(OVClassSetDevicePriorityConfigTest, SetConfigAndCheckGetConfigNoThrow) { ASSERT_EQ(devicePriority, configuration[ov::device::priorities.name()].as()); } -TEST_P(OVClassSetTBBForceTerminatePropertyTest, SetConfigNoThrow) { +TEST(OVClassBasicTest, SetCacheDirPropertyCoreNoThrow) { + ov::Core ie = createCoreWithTemplate(); + + // Cache_dir property test + ov::Any value; + OV_ASSERT_NO_THROW(ie.set_property(ov::cache_dir("./tmp_cache_dir"))); + OV_ASSERT_NO_THROW(value = ie.get_property(ov::cache_dir.name())); + EXPECT_EQ(value.as(), std::string("./tmp_cache_dir")); +} + +TEST(OVClassBasicTest, SetTBBForceTerminatePropertyCoreNoThrow) { ov::Core ie = createCoreWithTemplate(); bool value = true; OV_ASSERT_NO_THROW(ie.set_property(ov::force_tbb_terminate(false))); - OV_ASSERT_NO_THROW(value = ie.get_property(deviceName, ov::force_tbb_terminate)); + OV_ASSERT_NO_THROW(value = ie.get_property(ov::force_tbb_terminate.name())); EXPECT_EQ(value, false); OV_ASSERT_NO_THROW(ie.set_property(ov::force_tbb_terminate(true))); - OV_ASSERT_NO_THROW(value = ie.get_property(deviceName, ov::force_tbb_terminate)); + OV_ASSERT_NO_THROW(value = ie.get_property(ov::force_tbb_terminate.name())); EXPECT_EQ(value, true); } +TEST(OVClassBasicTest, GetUnsupportedPropertyCoreThrow) { + ov::Core ie = createCoreWithTemplate(); + + // Unsupported property test + ASSERT_THROW(ie.get_property("unsupported_property"), ov::Exception); +} + TEST_P(OVClassSetLogLevelConfigTest, SetConfigNoThrow) { ov::Core ie = createCoreWithTemplate(); // log level