Skip to content

Commit

Permalink
[core] Split configuration for device and others in compile model (op…
Browse files Browse the repository at this point in the history
…envinotoolkit#26977)

### Details:
- The `ov::Core` compile model filter provided configuration and send
hardware devices configuration with supported properties only. There is
no exception if plugin not supported property added.
- Sync supported properties in plugins to proper filter in
`compile_model`
- Filtering device properties by `compile_model` will improve keep
supported properties by device up-to-date.

### Tickets:
 - CVS-153906

---------

Signed-off-by: Pawel Raasz <[email protected]>
Signed-off-by: Raasz, Pawel <[email protected]>
  • Loading branch information
praasz authored Dec 13, 2024
1 parent 59984e9 commit 747d0e7
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 125 deletions.
205 changes: 128 additions & 77 deletions src/inference/src/dev/core_impl.cpp

Large diffs are not rendered by default.

121 changes: 85 additions & 36 deletions src/inference/src/dev/core_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,91 @@ using CreatePluginEngineFunc = void(std::shared_ptr<::ov::IPlugin>&);

const std::string DEFAULT_DEVICE_NAME = "DEFAULT_DEVICE";

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

struct CacheConfig {
std::string _cacheDir;
std::shared_ptr<ov::ICacheManager> _cacheManager;

static CacheConfig create(const std::string& dir);
};

void set(const ov::AnyMap& config);

/**
* @brief Removes core-level properties from config and triggers new state for core config
* @param config - config to be updated
*/
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);

std::string get_cache_dir() const;

bool get_enable_mmap() const;

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;
CacheConfig _cacheConfig;
std::map<std::string, CacheConfig> _cacheConfigPerDevice;
bool _flag_enable_mmap = true;
};

struct Parsed {
std::string _deviceName;
AnyMap _config;
CoreConfig _core_config;
};

/**
* @brief Provides Parsed device name and configuration.
*
* Uses default core configuration updated with user properties from config.
* The core properties are removed from user configuration for HW devices only.
* @note The `CACHE_DIR` is not removed from compiled configuration.
*
* @param deviceName Device name to be parsed
* @param config User configuration to be parsed.
* @param keep_auto_batch_property If set keep auto batch properties in compile properties.
* @return Parsed:
* - device name
* - compile properties
* - core configuration
*/
Parsed parseDeviceNameIntoConfig(const std::string& deviceName,
const AnyMap& config = {},
const bool keep_auto_batch_property = false);

/**
* @brief Provides Parsed device name and configuration.
*
* Uses user core configuration which is updated with user properties from config.
* The core properties are removed from user configuration for HW devices only.
* @note The `CACHE_DIR` is not removed from compiled configuration.
*
* @param deviceName Device name to be parsed
* @param coreConfig Core configuration used as base for parsed output.
* @param config User configuration to be parsed.
* @param keep_auto_batch_property If set keep auto batch properties in compile properties.
* @return Parsed:
* - device name
* - compile properties
* - core configuration
*/
Parsed parseDeviceNameIntoConfig(const std::string& deviceName,
const CoreConfig& coreConfig,
const AnyMap& config = {},
const bool keep_core_property = false);
const bool keep_auto_batch_property = false);

/**
* @brief Checks whether config is applicable for device with 'device_name'
Expand Down Expand Up @@ -61,47 +138,17 @@ class CoreImpl : public ov::ICore, public std::enable_shared_from_this<ov::ICore
bool is_proxy_device(const ov::Plugin& plugin) const;
bool is_proxy_device(const std::string& dev_name) const;

class CoreConfig final {
public:
struct CacheConfig {
std::string _cacheDir;
std::shared_ptr<ov::ICacheManager> _cacheManager;

static CacheConfig create(const std::string& dir);
};

/**
* @brief Removes core-level properties from config and triggers new state for core config
* @param config - config to be updated
*/
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);

std::string get_cache_dir() const;

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;

private:
mutable std::mutex _cacheConfigMutex;
CacheConfig _cacheConfig;
std::map<std::string, CacheConfig> _cacheConfigPerDevice;
bool _flag_enable_mmap = true;
};

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 +338,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 @@ -608,6 +608,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
25 changes: 15 additions & 10 deletions src/plugins/template/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,18 @@ ov::Any ov::template_plugin::Plugin::get_property(const std::string& name, const
return ro_properties;
};
const auto& default_rw_properties = []() {
std::vector<ov::PropertyName> rw_properties{ov::device::id,
ov::enable_profiling,
ov::hint::performance_mode,
ov::hint::num_requests,
ov::hint::inference_precision,
ov::hint::execution_mode,
ov::num_streams,
ov::template_plugin::disable_transformations,
ov::log::level};
std::vector<ov::PropertyName> rw_properties{
ov::device::id,
ov::enable_profiling,
ov::hint::performance_mode,
ov::hint::num_requests,
ov::hint::inference_precision,
ov::hint::execution_mode,
ov::num_streams,
ov::template_plugin::disable_transformations,
ov::log::level,
ov::hint::model_priority,
};
return rw_properties;
};
if (ov::supported_properties == name) {
Expand All @@ -280,7 +283,9 @@ ov::Any ov::template_plugin::Plugin::get_property(const std::string& name, const
} else if (ov::internal::supported_properties == name) {
return decltype(ov::internal::supported_properties)::value_type{
ov::PropertyName{ov::internal::caching_properties.name(), ov::PropertyMutability::RO},
ov::PropertyName{ov::internal::exclusive_async_requests.name(), ov::PropertyMutability::RW}};
ov::PropertyName{ov::internal::exclusive_async_requests.name(), ov::PropertyMutability::RW},
ov::PropertyName{ov::inference_num_threads.name(), ov::PropertyMutability::RW},
ov::PropertyName{ov::internal::threads_per_stream.name(), ov::PropertyMutability::RW}};
} else if (ov::available_devices == name) {
// TODO: fill list of available devices
return decltype(ov::available_devices)::value_type{{""}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ TEST_P(InferRequestPropertiesTest, ReusableCPUStreamsExecutor) {
}
}
}

TEST_P(InferRequestPropertiesTest, ConfigHasUnsupportedPluginProperty) {
configuration.insert({ov::enable_mmap(false)});
if (target_device.find(ov::test::utils::DEVICE_AUTO) == std::string::npos &&
target_device.find(ov::test::utils::DEVICE_MULTI) == std::string::npos &&
target_device.find(ov::test::utils::DEVICE_HETERO) == std::string::npos &&
target_device.find(ov::test::utils::DEVICE_BATCH) == std::string::npos) {
OV_ASSERT_NO_THROW(core->set_property(target_device, configuration));
}
// Compile model to target plugins
execNet = core->compile_model(function, target_device, configuration);
OV_ASSERT_NO_THROW(execNet.create_infer_request());
}
} // namespace behavior
} // namespace test
} // namespace ov

0 comments on commit 747d0e7

Please sign in to comment.