Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Split configuration for device and others in compile model #26977

Merged
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
e10f512
Split configuration for device and others
praasz Oct 9, 2024
32750d6
Fix call compile model with weights
praasz Oct 9, 2024
cdc5655
Remove modify core state in compile_model
praasz Oct 13, 2024
f9a2362
Remove not used variable
praasz Oct 13, 2024
b1387b2
Fix MSVC build error
praasz Oct 13, 2024
4f33336
Auto-Batch remove prop validation to meta device
praasz Oct 14, 2024
a6ad92e
Add missing supported properties in Template
praasz Oct 14, 2024
ce4a5a0
Add parse only properties in auto-batch
praasz Oct 14, 2024
d9e02b9
Merge remote-tracking branch 'origin/master' into split-config-in-com…
praasz Oct 14, 2024
945aab2
Template plugin sync supported properties
praasz Oct 14, 2024
a89eed8
CPU plugin sync supported properties
praasz Oct 14, 2024
0426bda
Hetero plugin sync supported properties
praasz Oct 14, 2024
8ae4d36
Make `parse_only_meta_device` member private
praasz Oct 14, 2024
1220a36
Merge branch 'master' into split-config-in-compile-model
praasz Oct 16, 2024
2a9b1e6
Merge branch 'master' into split-config-in-compile-model
praasz Oct 21, 2024
327c93a
Remove not used parameter in function
praasz Oct 22, 2024
82e337f
Merge branch 'master' into split-config-in-compile-model
praasz Oct 22, 2024
45e270d
Merge branch 'master' into split-config-in-compile-model
praasz Oct 23, 2024
ec5b0cf
Merge branch 'master' into split-config-in-compile-model
praasz Oct 25, 2024
837f633
Merge branch 'master' into split-config-in-compile-model
praasz Oct 28, 2024
cd5516b
Merge branch 'master' into split-config-in-compile-model
praasz Nov 12, 2024
803b5c3
Merge branch 'master' into split-config-in-compile-model
praasz Nov 14, 2024
b7e1ea7
Merge branch 'master' into split-config-in-compile-model
praasz Nov 15, 2024
d9dfae2
Merge branch 'master' into split-config-in-compile-model
praasz Nov 18, 2024
fabdba5
Merge branch 'master' into split-config-in-compile-model
praasz Nov 18, 2024
82b6c5c
Add kv_cache_precision as supported property by GPU
praasz Nov 20, 2024
982b9e8
Merge branch 'master' into split-config-in-compile-model
praasz Nov 21, 2024
c1ffd36
Merge branch 'master' into split-config-in-compile-model
praasz Nov 29, 2024
ce822f7
Merge branch 'master' into split-config-in-compile-model
praasz Dec 2, 2024
2772f3d
Filter core properties by using local core config
praasz Dec 10, 2024
46c05ba
Revert changes
praasz Dec 10, 2024
434b67f
Update `parseDeviceNameIntoConfig` to provide local core configuration
praasz Dec 11, 2024
78b5226
Merge remote-tracking branch 'origin/master' into split-config-in-com…
praasz Dec 11, 2024
c0b700b
Fix issues after merge
praasz Dec 11, 2024
7dc7b73
Clean core properties for HW devices in parseDeviceNameIntoConfig
praasz Dec 11, 2024
9c7f13a
Add comment about cache_dir removal from compile config
praasz Dec 11, 2024
511bb88
Re order code in core_impl.cpp
praasz Dec 11, 2024
ca0ba63
Merge branch 'master' into split-config-in-compile-model
praasz Dec 11, 2024
99508e5
Merge remote-tracking branch 'origin/master' into split-config-in-com…
praasz Dec 12, 2024
f182198
Explicitly remove copy assign operator for CoreConfig
praasz Dec 12, 2024
3370ef8
Merge branch 'master' into split-config-in-compile-model
praasz Dec 13, 2024
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
137 changes: 73 additions & 64 deletions src/inference/src/dev/core_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@

ov::ICore::~ICore() = default;

namespace ov {
namespace util {
template <class T = void, class... Args>
constexpr std::array<
typename std::conditional<std::is_void<T>::value, typename std::common_type<Args...>::type, T>::type,
sizeof...(Args)>
make_array(Args&&... args) {
return {std::forward<Args>(args)...};
}
} // namespace util
} // namespace ov

namespace {

#ifdef PROXY_PLUGIN_ENABLED
Expand Down Expand Up @@ -205,6 +217,14 @@ void clean_batch_properties(const std::string& deviceName, ov::AnyMap& config, c
}
}
}

constexpr bool keep_core = true;

static const auto core_properties_names =
ov::util::make_array(ov::cache_dir.name(), ov::enable_mmap.name(), ov::force_tbb_terminate.name());

static const auto auto_batch_properties_names =
ov::util::make_array(ov::auto_batch_timeout.name(), ov::hint::allow_auto_batching.name());
} // namespace

bool ov::is_config_applicable(const std::string& user_device_name, const std::string& subprop_device_name) {
Expand Down Expand Up @@ -304,8 +324,9 @@ ov::Parsed ov::parseDeviceNameIntoConfig(const std::string& deviceName,

// keep batch property only when called from query_supported_property
if (!keep_core_property) {
clean_batch_properties(updated_device_name, updated_config, ov::hint::allow_auto_batching);
clean_batch_properties(updated_device_name, updated_config, ov::auto_batch_timeout);
for (const auto& name : auto_batch_properties_names) {
clean_batch_properties(updated_device_name, updated_config, name);
}
}

return {std::move(updated_device_name), std::move(updated_config)};
Expand Down Expand Up @@ -663,8 +684,7 @@ ov::Plugin ov::CoreImpl::get_plugin(const std::string& pluginName) const {
{
OPENVINO_SUPPRESS_DEPRECATED_START
if (device_supports_cache_dir(plugin)) {
ov::AnyMap empty_map;
auto cacheConfig = coreConfig.get_cache_config_for_device(plugin, empty_map);
auto cacheConfig = coreConfig.get_cache_config_for_device(plugin);
if (cacheConfig._cacheManager) {
desc.defaultConfig[ov::cache_dir.name()] = cacheConfig._cacheDir;
}
Expand Down Expand Up @@ -737,13 +757,16 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model(const std::shared_ptr<
// if auto-batching is applicable, the below function will patch the device name and config accordingly:
auto model = apply_auto_batching(model_, deviceName, config_with_batch);

auto parsed = parseDeviceNameIntoConfig(deviceName, config_with_batch, is_proxy_device(device_name));
auto local_core_config = coreConfig;
auto parsed = parseDeviceNameIntoConfig(deviceName, config_with_batch, is_proxy_device(deviceName));
ilya-lavrenov marked this conversation as resolved.
Show resolved Hide resolved
local_core_config.set_and_update(parsed._config);
auto plugin = get_plugin(parsed._deviceName);

ov::SoPtr<ov::ICompiledModel> res;
auto cacheManager = coreConfig.get_cache_config_for_device(plugin, parsed._config)._cacheManager;
auto cacheManager = local_core_config.get_cache_config_for_device(plugin)._cacheManager;
// Skip caching for proxy plugin. HW plugin will load network from the cache
if (cacheManager && device_supports_model_caching(plugin) && !is_proxy_device(plugin)) {
CacheContent cacheContent{cacheManager};
CacheContent cacheContent{cacheManager, local_core_config.get_enable_mmap()};
cacheContent.blobId = ov::ModelCache::compute_hash(model, create_compile_config(plugin, parsed._config));
std::unique_ptr<CacheGuardEntry> lock = cacheGuard.get_hash_lock(cacheContent.blobId);
res = load_model_from_cache(cacheContent, plugin, parsed._config, ov::SoPtr<ov::IRemoteContext>{}, [&]() {
Expand All @@ -770,13 +793,16 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model(const std::shared_ptr<
// if auto-batching is applicable, the below function will patch the device name and config accordingly:
auto model = apply_auto_batching(model_, deviceName, config_with_batch);

auto local_core_config = coreConfig;
auto parsed = parseDeviceNameIntoConfig(deviceName, config_with_batch, is_proxy_device(deviceName));
local_core_config.set_and_update(parsed._config);
auto plugin = get_plugin(parsed._deviceName);

ov::SoPtr<ov::ICompiledModel> res;
auto cacheManager = coreConfig.get_cache_config_for_device(plugin, parsed._config)._cacheManager;
auto cacheManager = local_core_config.get_cache_config_for_device(plugin)._cacheManager;
// Skip caching for proxy plugin. HW plugin will load network from the cache
if (cacheManager && device_supports_model_caching(plugin) && !is_proxy_device(plugin)) {
CacheContent cacheContent{cacheManager};
CacheContent cacheContent{cacheManager, local_core_config.get_enable_mmap()};
cacheContent.blobId = ov::ModelCache::compute_hash(model, create_compile_config(plugin, parsed._config));
std::unique_ptr<CacheGuardEntry> lock = cacheGuard.get_hash_lock(cacheContent.blobId);
res = load_model_from_cache(cacheContent, plugin, parsed._config, context, [&]() {
Expand All @@ -792,21 +818,23 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model(const std::string& mod
const std::string& device_name,
const ov::AnyMap& config) const {
OV_ITT_SCOPE(FIRST_INFERENCE, ov::itt::domains::LoadTime, "Core::compile_model::Path");
auto parsed = parseDeviceNameIntoConfig(device_name, config);
auto parsed = parseDeviceNameIntoConfig(device_name, config, keep_core);
auto local_core_config = coreConfig;
// in case of compile_model(file_name), we need to clear-up core-level properties
local_core_config.set_and_update(parsed._config);
auto plugin = get_plugin(parsed._deviceName);
ov::SoPtr<ov::ICompiledModel> compiled_model;

auto cacheManager = coreConfig.get_cache_config_for_device(plugin, parsed._config)._cacheManager;

ov::SoPtr<ov::ICompiledModel> compiled_model;
auto cacheManager = local_core_config.get_cache_config_for_device(plugin)._cacheManager;
// Skip caching for proxy plugin. HW plugin will load network from the cache
if (cacheManager && device_supports_model_caching(plugin) && !is_proxy_device(plugin)) {
// Skip caching for proxy plugin. HW plugin will load network from the cache
CacheContent cacheContent{cacheManager, model_path};
CacheContent cacheContent{cacheManager, local_core_config.get_enable_mmap(), model_path};
cacheContent.blobId = ov::ModelCache::compute_hash(model_path, create_compile_config(plugin, parsed._config));
std::unique_ptr<CacheGuardEntry> lock = cacheGuard.get_hash_lock(cacheContent.blobId);
compiled_model =
load_model_from_cache(cacheContent, plugin, parsed._config, ov::SoPtr<ov::IRemoteContext>{}, [&]() {
auto model = read_model(model_path, std::string{});
auto model =
ov::util::read_model(model_path, std::string{}, extensions, local_core_config.get_enable_mmap());
return compile_model_and_cache(plugin, model, parsed._config, {}, cacheContent);
});
} else {
Expand All @@ -820,15 +848,16 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::compile_model(const std::string& mod
const std::string& device_name,
const ov::AnyMap& config) const {
OV_ITT_SCOPED_TASK(ov::itt::domains::OV, "Core::compile_model::from_memory");
auto parsed = parseDeviceNameIntoConfig(device_name, config);
// in case of compile_model(file_name), we need to clear-up core-level properties
auto parsed = parseDeviceNameIntoConfig(device_name, config, keep_core);
auto local_core_config = coreConfig;
local_core_config.set_and_update(parsed._config);
auto plugin = get_plugin(parsed._deviceName);
ov::SoPtr<ov::ICompiledModel> compiled_model;

auto cacheManager = coreConfig.get_cache_config_for_device(plugin, parsed._config)._cacheManager;
ov::SoPtr<ov::ICompiledModel> compiled_model;
auto cacheManager = local_core_config.get_cache_config_for_device(plugin)._cacheManager;
// Skip caching for proxy plugin. HW plugin will load network from the cache
if (cacheManager && device_supports_model_caching(plugin) && !is_proxy_device(plugin)) {
CacheContent cacheContent{cacheManager};
CacheContent cacheContent{cacheManager, local_core_config.get_enable_mmap()};
cacheContent.blobId =
ov::ModelCache::compute_hash(model_str, weights, create_compile_config(plugin, parsed._config));
std::unique_ptr<CacheGuardEntry> lock = cacheGuard.get_hash_lock(cacheContent.blobId);
Expand Down Expand Up @@ -948,7 +977,7 @@ ov::AnyMap ov::CoreImpl::get_supported_property(const std::string& full_device_n
// ov::device::priority cannot be shared, because it's specific for current virtual
// plugin. So, we need to remove ov::device::priorities from the list, because it's
// supposed to be set for current virtual plugin and cannot be propagated down
ov::AnyMap return_properties = user_properties;
auto return_properties = user_properties;
auto device_priorities_it = return_properties.find(ov::device::priorities.name());
if (device_priorities_it != return_properties.end()) {
return_properties.erase(device_priorities_it);
Expand All @@ -957,23 +986,17 @@ ov::AnyMap ov::CoreImpl::get_supported_property(const std::string& full_device_n
return return_properties;
}

static const std::vector<std::string> core_level_properties = {
ov::cache_dir.name(),
ov::force_tbb_terminate.name(),
// auto-batch properties are also treated as core-level
ov::auto_batch_timeout.name(),
ov::hint::allow_auto_batching.name(),
};

const auto flattened = ov::parseDeviceNameIntoConfig(full_device_name, user_properties, true);
const std::string& device_name = flattened._deviceName;
const auto flattened = parseDeviceNameIntoConfig(full_device_name, user_properties, keep_core_property);
const auto& flattened_config = flattened._config;
const auto& device_name = flattened._deviceName;

// virtual plugins should bypass core-level properties to HW plugins
// so, we need to report them as supported
std::vector<std::string> supported_config_keys;
if (keep_core_property) {
supported_config_keys = core_level_properties;
if (keep_core) {
auto last = supported_config_keys.end();
last = supported_config_keys.insert(last, core_properties_names.begin(), core_properties_names.end());
supported_config_keys.insert(last, auto_batch_properties_names.begin(), auto_batch_properties_names.end());
}

// try to search against OV API 2.0' mutable supported_properties
Expand Down Expand Up @@ -1160,8 +1183,7 @@ ov::Any ov::CoreImpl::get_property(const std::string& device_name,
if (parsed._deviceName.empty()) {
return get_property_for_core(name);
} else if (name == ov::cache_dir.name()) {
ov::AnyMap empty_map;
return coreConfig.get_cache_config_for_device(get_plugin(parsed._deviceName), empty_map)._cacheDir;
return coreConfig.get_cache_config_for_device(get_plugin(parsed._deviceName))._cacheDir;
}
return get_plugin(parsed._deviceName).get_property(name, parsed._config);
}
Expand Down Expand Up @@ -1299,9 +1321,7 @@ void ov::CoreImpl::set_property_for_device(const ov::AnyMap& configMap, const st
{
OPENVINO_SUPPRESS_DEPRECATED_START
if (device_supports_cache_dir(plugin.second)) {
ov::AnyMap empty_map = {};
configCopy[ov::cache_dir.name()] =
coreConfig.get_cache_config_for_device(plugin.second, empty_map)._cacheDir;
configCopy[ov::cache_dir.name()] = coreConfig.get_cache_config_for_device(plugin.second)._cacheDir;
} else if (configCopy.count(ov::cache_dir.name()) > 0) {
// Remove "CACHE_DIR" from config if it is not supported by plugin
configCopy.erase(ov::cache_dir.name());
Expand Down Expand Up @@ -1411,8 +1431,8 @@ ov::SoPtr<ov::ICompiledModel> ov::CoreImpl::load_model_from_cache(
try {
cacheContent.cacheManager->read_cache_entry(
cacheContent.blobId,
coreConfig.get_enable_mmap() && ov::util::contains(plugin.get_property(ov::internal::supported_properties),
ov::internal::caching_with_mmap),
cacheContent.mmap_enabled && ov::util::contains(plugin.get_property(ov::internal::supported_properties),
ov::internal::caching_with_mmap),
[&](std::istream& networkStream) {
OV_ITT_SCOPE(FIRST_INFERENCE,
ov::itt::domains::LoadTime,
Expand Down Expand Up @@ -1513,6 +1533,15 @@ ov::AnyMap ov::CoreImpl::create_compile_config(const ov::Plugin& plugin, const o
return compile_config;
}

ov::CoreImpl::CoreConfig::CoreConfig(const CoreConfig& other) {
{
std::lock_guard<std::mutex> lock(other._cacheConfigMutex);
_cacheConfig = other._cacheConfig;
_cacheConfigPerDevice = other._cacheConfigPerDevice;
}
_flag_enable_mmap = other._flag_enable_mmap;
ilya-lavrenov marked this conversation as resolved.
Show resolved Hide resolved
}

void ov::CoreImpl::CoreConfig::set_and_update(ov::AnyMap& config) {
auto it = config.find(ov::cache_dir.name());
if (it != config.end()) {
Expand Down Expand Up @@ -1555,30 +1584,10 @@ bool ov::CoreImpl::CoreConfig::get_enable_mmap() const {
return _flag_enable_mmap;
}

// Creating thread-safe copy of config including shared_ptr to ICacheManager
// Passing empty or not-existing name will return global cache config
ov::CoreImpl::CoreConfig::CacheConfig ov::CoreImpl::CoreConfig::get_cache_config_for_device(
const ov::Plugin& plugin,
ov::AnyMap& parsedConfig) 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) &&
!is_virtual_device(plugin.get_name())) {
parsedConfig.erase(ov::cache_dir.name());
}
return tempConfig;
} else { // cache_dir is set to Core globally or for the specific device
std::lock_guard<std::mutex> lock(_cacheConfigMutex);
if (_cacheConfigPerDevice.count(plugin.get_name()) > 0) {
return _cacheConfigPerDevice.at(plugin.get_name());
} else {
return _cacheConfig;
}
}
const ov::Plugin& plugin) const {
std::lock_guard<std::mutex> lock(_cacheConfigMutex);
return _cacheConfigPerDevice.count(plugin.get_name()) ? _cacheConfigPerDevice.at(plugin.get_name()) : _cacheConfig;
}

ov::CoreImpl::CoreConfig::CacheConfig ov::CoreImpl::CoreConfig::CacheConfig::create(const std::string& dir) {
Expand Down
17 changes: 12 additions & 5 deletions src/inference/src/dev/core_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class CoreImpl : public ov::ICore, public std::enable_shared_from_this<ov::ICore

class CoreConfig final {
public:
CoreConfig() = default;
CoreConfig(const CoreConfig& other);

struct CacheConfig {
std::string _cacheDir;
std::shared_ptr<ov::ICacheManager> _cacheManager;
Expand All @@ -83,9 +86,8 @@ class CoreImpl : public ov::ICore, public std::enable_shared_from_this<ov::ICore

bool 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
CacheConfig get_cache_config_for_device(const ov::Plugin& plugin, ov::AnyMap& parsedConfig) const;
// Creating thread-safe copy of global config including shared_ptr to ICacheManager
CacheConfig get_cache_config_for_device(const ov::Plugin& plugin) const;

private:
mutable std::mutex _cacheConfigMutex;
Expand All @@ -96,12 +98,15 @@ class CoreImpl : public ov::ICore, public std::enable_shared_from_this<ov::ICore

struct CacheContent {
explicit CacheContent(const std::shared_ptr<ov::ICacheManager>& cache_manager,
bool mmap_enabled = false,
const std::string model_path = {})
: cacheManager(cache_manager),
modelPath(model_path) {}
modelPath(model_path),
mmap_enabled{mmap_enabled} {}
std::shared_ptr<ov::ICacheManager> cacheManager;
std::string blobId = {};
std::string modelPath = {};
bool mmap_enabled = false;
};

// Core settings (cache config, etc)
Expand Down Expand Up @@ -291,7 +296,9 @@ class CoreImpl : public ov::ICore, public std::enable_shared_from_this<ov::ICore

ov::SoPtr<ov::IRemoteContext> create_context(const std::string& device_name, const AnyMap& args) const override;

ov::AnyMap get_supported_property(const std::string& device_name, const ov::AnyMap& config, const bool keep_core_property = true) const override;
ov::AnyMap get_supported_property(const std::string& device_name,
const ov::AnyMap& config,
const bool keep_core_property = true) const override;

ov::SoPtr<ov::IRemoteContext> get_default_context(const std::string& device_name) const override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,4 @@ TEST_F(AutoFuncTests, compiled_with_cache_enabled_batch_enabled) {
ASSERT_EQ(ov::test::utils::listFilesWithExt(cache_path, "blob").size(), 5);
core.set_property(ov::cache_dir(""));
#endif
}
}
2 changes: 1 addition & 1 deletion src/plugins/auto_batch/src/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ class Plugin : public ov::IPlugin {
mutable ov::AnyMap m_plugin_config;
};
} // namespace autobatch_plugin
} // namespace ov
} // namespace ov
1 change: 1 addition & 0 deletions src/plugins/intel_gpu/src/plugin/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ std::vector<ov::PropertyName> Plugin::get_supported_properties() const {
ov::PropertyName{ov::hint::dynamic_quantization_group_size.name(), PropertyMutability::RW},
ov::PropertyName{ov::hint::activations_scale_factor.name(), PropertyMutability::RW},
ov::PropertyName{ov::weights_path.name(), PropertyMutability::RW},
ov::PropertyName{ov::hint::kv_cache_precision.name(), PropertyMutability::RW},
};

return supported_properties;
Expand Down
Loading
Loading