Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/bindings/js/node/tests/unit/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,9 @@ describe("ov basic tests.", () => {

it("Test importModelSync(stream, device, config: unsupported property) \
throws", () => {
const tmpDir = "/tmp";
assert.throws(
() => core.importModelSync(userStream, "CPU", { CACHE_DIR: tmpDir }),
/Unsupported property CACHE_DIR by CPU plugin./,
() => core.importModelSync(userStream, "CPU", { NPU_DEVICE_TOTAL_MEM_SIZE: 1024 }),
/Unsupported property NPU_DEVICE_TOTAL_MEM_SIZE by CPU plugin./,
);
});

Expand Down
122 changes: 23 additions & 99 deletions src/inference/src/dev/core_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,7 @@ ov::Parsed ov::parse_device_name_into_config(const std::string& device_name,

// remove core properties for HW devices
if (!ov::is_virtual_device(parsed.m_device_name)) {
// note: ov::cache_dir kept as plugin may require it
CoreConfig::remove_core_skip_cache_dir(parsed.m_config);
CoreConfig::remove_core(parsed.m_config);
}
return parsed;
}
Expand Down Expand Up @@ -764,22 +763,6 @@ ov::Plugin ov::CoreImpl::get_plugin(const std::string& plugin_name) const {
}
}
#endif
// TODO: remove this block of code once GPU removes support of ov::cache_dir
// also, remove device_supports_cache_dir at all
{
OPENVINO_SUPPRESS_DEPRECATED_START
if (device_supports_cache_dir(plugin)) {
auto cache_config = m_core_config.get_cache_config_for_device(plugin);
if (cache_config.m_cache_manager) {
desc.m_default_config[ov::cache_dir.name()] = cache_config.m_cache_dir;
}
} else if (desc.m_default_config.count(ov::cache_dir.name()) > 0) {
// Remove "CACHE_DIR" from config if it is not supported by plugin
desc.m_default_config.erase(ov::cache_dir.name());
}
OPENVINO_SUPPRESS_DEPRECATED_END
}

allowNotImplemented([&]() {
// Add device specific value to support device_name.device_id cases
{
Expand Down Expand Up @@ -852,7 +835,6 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model(const std::shared_ptr<
config_with_batch,
is_proxy_device(patched_device_name));
auto plugin = get_plugin(parsed.m_device_name);
// will consume ov::cache_dir if plugin not support it
const auto cache_manager =
parsed.m_core_config.get_cache_config_for_device(plugin, parsed.m_config).m_cache_manager;
auto res = import_compiled_model(plugin, {}, parsed.m_config, model);
Expand Down Expand Up @@ -900,7 +882,6 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model(const std::shared_ptr<
auto parsed =
parse_device_name_into_config(device_name, m_core_config, config_with_batch, is_proxy_device(device_name));
auto plugin = get_plugin(parsed.m_device_name);
// will consume ov::cache_dir if plugin not support it
const auto cache_manager =
parsed.m_core_config.get_cache_config_for_device(plugin, parsed.m_config).m_cache_manager;
auto res = import_compiled_model(plugin, context, parsed.m_config, model);
Expand Down Expand Up @@ -930,7 +911,6 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model(const std::string& mod
auto parsed = parse_device_config(device_name, m_core_config, config, false);
// in case of compile_model(file_name), we need to clear-up core-level properties
auto plugin = get_plugin(parsed.m_device_name);
// will consume ov::cache_dir if plugin not support it
const auto cache_manager =
parsed.m_core_config.get_cache_config_for_device(plugin, parsed.m_config).m_cache_manager;
auto compiled_model = import_compiled_model(plugin, {}, parsed.m_config, model_path);
Expand All @@ -939,7 +919,7 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model(const std::string& mod
// hint::compiled_blob is set and imported skip compilation
} else if (cache_manager && device_supports_model_caching(plugin, parsed.m_config) && !is_proxy_device(plugin)) {
// Skip caching for proxy plugin. HW plugin will load network from the cache
CoreConfig::remove_core_skip_cache_dir(parsed.m_config);
CoreConfig::remove_core(parsed.m_config);
CacheContent cache_content{cache_manager, parsed.m_core_config.get_enable_mmap(), model_path};
cache_content.m_blob_id =
ov::ModelCache::compute_hash(model_path, create_compile_config(plugin, parsed.m_config));
Expand All @@ -962,7 +942,6 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model(const std::string& mod
OV_ITT_SCOPED_TASK(ov::itt::domains::OV, "Core::compile_model::from_memory");
auto parsed = parse_device_name_into_config(device_name, m_core_config, config);
auto plugin = get_plugin(parsed.m_device_name);
// will consume ov::cache_dir if plugin not support it
const auto cache_manager =
parsed.m_core_config.get_cache_config_for_device(plugin, parsed.m_config).m_cache_manager;
auto compiled_model = import_compiled_model(plugin, {}, parsed.m_config);
Expand Down Expand Up @@ -1377,35 +1356,7 @@ void ov::CoreImpl::set_property_for_device(const ov::AnyMap& config, const std::
{
std::lock_guard<std::mutex> lock(get_mutex());
created_plugins.reserve(m_plugins.size());

// TODO: keep only:
// core_config.set_and_update(config);
// once GPU remove support of ov::cache_dir
// CoreConfg::set_and_update will drop CACHE_DIR from config map
// and updates core config with new ov::cache_dir
if (device_name.empty()) {
m_core_config.set_and_update(cfg_copy);
} else {
OPENVINO_SUPPRESS_DEPRECATED_START
auto cache_it = cfg_copy.find(ov::cache_dir.name());
if (cache_it != cfg_copy.end()) {
m_core_config.set_cache_dir_for_device((cache_it->second).as<std::string>(), clear_device_name);
cfg_copy.erase(cache_it);
}
OPENVINO_SUPPRESS_DEPRECATED_END
// apply and remove core properties
auto it = cfg_copy.find(ov::force_tbb_terminate.name());
if (it != cfg_copy.end()) {
auto flag = it->second.as<bool>();
ov::threading::executor_manager()->set_property({{it->first, flag}});
cfg_copy.erase(it);
}

it = cfg_copy.find(ov::enable_mmap.name());
if (it != cfg_copy.end()) {
cfg_copy.erase(it);
}
}
m_core_config.set_and_update(cfg_copy, clear_device_name);

if (!cfg_copy.empty()) {
auto base_desc = m_plugin_registry.find(clear_device_name);
Expand Down Expand Up @@ -1445,18 +1396,6 @@ void ov::CoreImpl::set_property_for_device(const ov::AnyMap& config, const std::
allowNotImplemented([&]() {
std::lock_guard<std::mutex> lock(get_mutex(plugin.first));
auto config_copy = cfg_copy;
// TODO: remove once GPU remove explicit support of ov::cache_dir
{
OPENVINO_SUPPRESS_DEPRECATED_START
if (device_supports_cache_dir(plugin.second)) {
config_copy[ov::cache_dir.name()] =
m_core_config.get_cache_config_for_device(plugin.second).m_cache_dir;
} else if (config_copy.count(ov::cache_dir.name()) > 0) {
// Remove "CACHE_DIR" from config if it is not supported by plugin
config_copy.erase(ov::cache_dir.name());
}
OPENVINO_SUPPRESS_DEPRECATED_END
}
// Add device specific value to support device_name.device_id cases
{
if (!parser.get_device_id().empty()) {
Expand Down Expand Up @@ -1519,14 +1458,6 @@ bool ov::CoreImpl::device_supports_model_caching(const ov::Plugin& plugin, const
: plugin.supports_model_caching();
}

bool ov::CoreImpl::device_supports_cache_dir(const ov::Plugin& plugin) const {
try {
return util::contains(plugin.get_property(ov::supported_properties), ov::cache_dir);
} catch (const ov::NotImplemented&) {
return false;
}
}

ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model_and_cache(ov::Plugin& plugin,
const std::shared_ptr<const ov::Model>& model,
const ov::AnyMap& parsedConfig,
Expand Down Expand Up @@ -1729,10 +1660,11 @@ void ov::CoreConfig::set(const ov::AnyMap& config) {
if (it != config.end()) {
std::lock_guard<std::mutex> lock(m_cache_config_mutex);
// fill global cache config
m_cache_config = CoreConfig::CacheConfig::create(it->second.as<std::string>());
const auto& cache_dir = it->second.as<std::string>();
m_cache_config = CoreConfig::CacheConfig::create(cache_dir);
// sets cache config per-device if it's not set explicitly before
for (auto& deviceCfg : m_devices_cache_config) {
deviceCfg.second = CoreConfig::CacheConfig::create(it->second.as<std::string>());
for (auto& device_cfg : m_devices_cache_config) {
device_cfg.second = CoreConfig::CacheConfig::create(cache_dir);
}
}

Expand All @@ -1749,8 +1681,18 @@ void ov::CoreConfig::set(const ov::AnyMap& config) {
}
}

void ov::CoreConfig::set_and_update(ov::AnyMap& config) {
set(config);
void ov::CoreConfig::set(const ov::AnyMap& config, const std::string& device_name) {
if (device_name.empty()) {
set(config);
} else if (const auto cache_dir_entry = config.find(ov::cache_dir.name()); cache_dir_entry != config.end()) {
std::lock_guard<std::mutex> lock(m_cache_config_mutex);
m_devices_cache_config[device_name] =
CoreConfig::CacheConfig::create(cache_dir_entry->second.as<std::string>());
}
}

void ov::CoreConfig::set_and_update(ov::AnyMap& config, const std::string& device_name) {
set(config, device_name);
remove_core(config);
}

Expand All @@ -1760,17 +1702,6 @@ void ov::CoreConfig::remove_core(ov::AnyMap& config) {
}
}

void ov::CoreConfig::remove_core_skip_cache_dir(ov::AnyMap& config) {
for (const auto& name : {ov::enable_mmap.name(), ov::force_tbb_terminate.name(), ov::cache_model_path.name()}) {
config.erase(name);
}
}

void ov::CoreConfig::set_cache_dir_for_device(const std::string& dir, const std::string& name) {
std::lock_guard<std::mutex> lock(m_cache_config_mutex);
m_devices_cache_config[name] = CoreConfig::CacheConfig::create(dir);
}

std::string ov::CoreConfig::get_cache_dir() const {
std::lock_guard<std::mutex> lock(m_cache_config_mutex);
return m_cache_config.m_cache_dir;
Expand All @@ -1783,18 +1714,11 @@ bool ov::CoreConfig::get_enable_mmap() const {
// Creating thread-safe copy of config including shared_ptr to ICacheManager
// Passing empty or not-existing name will return global cache config
ov::CoreConfig::CacheConfig ov::CoreConfig::get_cache_config_for_device(const ov::Plugin& plugin,
ov::AnyMap& parsedConfig) const {
const ov::AnyMap& config) const {
// cache_dir is enabled locally in compile_model only
if (parsedConfig.count(ov::cache_dir.name())) {
const auto& cache_dir_val = parsedConfig.at(ov::cache_dir.name()).as<std::string>();
const auto& tempConfig = CoreConfig::CacheConfig::create(cache_dir_val);
// if plugin does not explicitly support cache_dir, and if plugin is not virtual, we need to remove
// it from config
if (!util::contains(plugin.get_property(ov::supported_properties), ov::cache_dir) &&
!ov::is_virtual_device(plugin.get_name())) {
parsedConfig.erase(ov::cache_dir.name());
}
return tempConfig;
if (config.count(ov::cache_dir.name())) {
const auto& cache_dir = config.at(ov::cache_dir.name()).as<std::string>();
return CoreConfig::CacheConfig::create(cache_dir);
} else { // cache_dir is set to Core globally or for the specific device
return get_cache_config_for_device(plugin);
}
Expand Down
16 changes: 5 additions & 11 deletions src/inference/src/dev/core_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,26 @@ class CoreConfig final {
};

void set(const ov::AnyMap& config);
void set(const ov::AnyMap& config, const std::string& device_name);

/**
* @brief Removes core-level properties from config and triggers new state for core config
* @param config - config to be updated
* @param config config to be updated
* @param device_name device name for which config is applied (empty is for core-level)
*/
void set_and_update(ov::AnyMap& config);

OPENVINO_DEPRECATED("Don't use this method, it will be removed soon")
void set_cache_dir_for_device(const std::string& dir, const std::string& name);
void set_and_update(ov::AnyMap& config, const std::string& device_name);

std::string get_cache_dir() const;

bool get_enable_mmap() const;

CacheConfig get_cache_config_for_device(const ov::Plugin& plugin, ov::AnyMap& parsed_config) const;
CacheConfig get_cache_config_for_device(const ov::Plugin& plugin, const ov::AnyMap& parsed_config) const;

// Creating thread-safe copy of global config including shared_ptr to ICacheManager
CacheConfig get_cache_config_for_device(const ov::Plugin& plugin) const;

// remove core properties
static void remove_core(ov::AnyMap& config);
static void remove_core_skip_cache_dir(ov::AnyMap& config);

private:
mutable std::mutex m_cache_config_mutex{};
Expand Down Expand Up @@ -201,7 +199,6 @@ class CoreImpl : public ov::ICore, public std::enable_shared_from_this<ov::ICore
std::shared_ptr<ov::threading::ExecutorManager> m_executor_manager;
mutable std::unordered_set<std::string> m_opset_names;
mutable std::vector<Extension::Ptr> m_extensions;

std::map<std::string, PluginDescriptor> m_plugin_registry;

ov::SoPtr<ov::ICompiledModel> compile_model_and_cache(ov::Plugin& plugin,
Expand All @@ -222,9 +219,6 @@ class CoreImpl : public ov::ICore, public std::enable_shared_from_this<ov::ICore
bool device_supports_property(const ov::Plugin& plugin, const ov::PropertyName& key) const;
bool device_supports_internal_property(const ov::Plugin& plugin, const ov::PropertyName& key) const;

OPENVINO_DEPRECATED("Don't use this method, it will be removed soon")
bool device_supports_cache_dir(const ov::Plugin& plugin) const;

ov::AnyMap create_compile_config(const ov::Plugin& plugin, const ov::AnyMap& orig_config) const;
ov::AnyMap create_compile_config(const std::string& device_name, const ov::AnyMap& orig_config) const override {
return create_compile_config(get_plugin(device_name), orig_config);
Expand Down
4 changes: 3 additions & 1 deletion src/inference/src/dev/iplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ std::shared_ptr<ov::ICompiledModel> ov::IPlugin::compile_model(const std::string
OPENVINO_ASSERT(core);
const auto model = core->read_model(model_path, {}, properties);
auto local_properties = properties;
CoreConfig::remove_core_skip_cache_dir(local_properties);
if (!ov::is_virtual_device(get_device_name())) {
CoreConfig::remove_core(local_properties);
}
return compile_model(model, local_properties);
}

Expand Down
Loading
Loading