Add set_property without param device name. (#12354)
* Add get_property without device_name param. Signed-off-by: xipingya <xiping.yan@intel.com> * update * fix build error Signed-off-by: Yan, Xiping <xiping.yan@intel.com> * update test case for set/get property tbb Signed-off-by: Yan, Xiping <xiping.yan@intel.com> * Remove test_p, don't need parameter(deviceName). Signed-off-by: Yan, Xiping <xiping.yan@intel.com> * Add get_property for python API. Currently I don't know how to add relevant test case. Signed-off-by: Yan, Xiping <xiping.yan@intel.com> * Don't need this function. Signed-off-by: Yan, Xiping <xiping.yan@intel.com> * Remove return ov::Any, replace with throw a description. Signed-off-by: Yan, Xiping <xiping.yan@intel.com> * Add throw unsupported test for get_property without param deviceName. Signed-off-by: Yan, Xiping <xiping.yan@intel.com> * Add python test case for get_property. Test usage: $ python -m pytest ../src/bindings/python/tests/test_runtime/test_properties.py Signed-off-by: Yan, Xiping <xiping.yan@intel.com> * change == to is Signed-off-by: Yan, Xiping <xiping.yan@intel.com>
This commit is contained in:
parent
4e223c3d3e
commit
631cd160ee
@ -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,
|
||||
|
@ -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()) == "./"
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -190,6 +190,11 @@ class CoreImpl : public ie::ICore, public std::enable_shared_from_this<ie::ICore
|
||||
fillConfig(_cacheConfigPerDevice[name], dir);
|
||||
}
|
||||
|
||||
std::string get_cache_dir() const {
|
||||
std::lock_guard<std::mutex> 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);
|
||||
}
|
||||
|
||||
|
@ -388,18 +388,35 @@ TEST_P(OVClassSetDevicePriorityConfigTest, SetConfigAndCheckGetConfigNoThrow) {
|
||||
ASSERT_EQ(devicePriority, configuration[ov::device::priorities.name()].as<std::string>());
|
||||
}
|
||||
|
||||
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>(), 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
|
||||
|
Loading…
Reference in New Issue
Block a user