Skip to content

Commit f5de781

Browse files
[CPU] New plugin config impl
1 parent ea05578 commit f5de781

35 files changed

+638
-981
lines changed

src/inference/CMakeLists.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ target_include_directories(${TARGET_NAME}_obj SYSTEM PRIVATE
8787
target_include_directories(${TARGET_NAME}_obj PRIVATE
8888
"${CMAKE_CURRENT_SOURCE_DIR}/src"
8989
$<TARGET_PROPERTY:openvino::runtime::dev,INTERFACE_INCLUDE_DIRECTORIES>
90+
$<TARGET_PROPERTY:openvino::shape_inference,INTERFACE_INCLUDE_DIRECTORIES>
9091
$<$<TARGET_EXISTS:openvino_proxy_plugin_obj>:$<TARGET_PROPERTY:openvino_proxy_plugin_obj,INTERFACE_INCLUDE_DIRECTORIES>>
9192
# for ov_plugins.hpp
9293
$<IF:$<AND:$<BOOL:${OV_GENERATOR_MULTI_CONFIG}>,$<VERSION_GREATER_EQUAL:${CMAKE_VERSION},3.20>>,${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>,${CMAKE_CURRENT_BINARY_DIR}>)
@@ -105,7 +106,7 @@ endif()
105106
# Create library file from object library
106107

107108
add_library(${TARGET_NAME} INTERFACE)
108-
target_link_libraries(${TARGET_NAME} INTERFACE openvino::runtime)
109+
target_link_libraries(${TARGET_NAME} INTERFACE openvino::runtime openvino::shape_inference)
109110
target_include_directories(${TARGET_NAME} INTERFACE $<BUILD_INTERFACE:${PUBLIC_HEADERS_DIR}>)
110111

111112
ov_add_clang_format_target(${TARGET_NAME}_clang FOR_SOURCES ${LIBRARY_SRC} ${LIBRARY_HEADERS} ${PUBLIC_HEADERS})
@@ -126,10 +127,11 @@ if (TBBBIND_2_5_FOUND)
126127
endif()
127128

128129
target_include_directories(${TARGET_NAME}_s PUBLIC
129-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>)
130+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
131+
$<TARGET_PROPERTY:openvino::shape_inference,INTERFACE_INCLUDE_DIRECTORIES>)
130132

131133
target_link_libraries(${TARGET_NAME}_s PRIVATE openvino::itt ${CMAKE_DL_LIBS}
132-
openvino::runtime::dev openvino::pugixml)
134+
openvino::runtime::dev openvino::pugixml openvino::shape_inference)
133135

134136
target_compile_definitions(${TARGET_NAME}_s PUBLIC USE_STATIC_IE)
135137

src/inference/dev_api/openvino/runtime/plugin_config.hpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ class OPENVINO_RUNTIME_API PluginConfig {
181181
m_options_map.emplace(name, ptr);
182182
}
183183

184+
// TODO: move to protected
185+
template <typename T, PropertyMutability mutability>
186+
bool is_set_by_user(const ov::Property<T, mutability>& property) const {
187+
return m_user_properties.find(property.name()) != m_user_properties.end();
188+
}
189+
184190
protected:
185191
template <typename OptionType>
186192
class GlobalOptionInitializer {
@@ -203,13 +209,10 @@ class OPENVINO_RUNTIME_API PluginConfig {
203209
void apply_config_options(std::string_view device_name, std::filesystem::path config_path = "");
204210
virtual void finalize_impl(const IRemoteContext* context) {}
205211

206-
template <typename T, PropertyMutability mutability>
207-
bool is_set_by_user(const ov::Property<T, mutability>& property) const {
208-
return m_user_properties.find(property.name()) != m_user_properties.end();
209-
}
210-
212+
protected:
211213
ConfigOptionBase* get_option_ptr(const std::string& name) const {
212214
auto it = m_options_map.find(name);
215+
// TODO: print more meaningful error message
213216
OPENVINO_ASSERT(it != m_options_map.end(), "Option not found: ", name);
214217
OPENVINO_ASSERT(it->second != nullptr, "Option is invalid: ", name);
215218

src/inference/include/openvino/runtime/properties.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ namespace streams {
12301230
* @ingroup ov_runtime_cpp_prop_api
12311231
*/
12321232
struct Num {
1233-
using Base = std::tuple<int32_t>; //!< NumStreams is representable as int32_t
1233+
// using Base = std::tuple<int32_t>; //!< NumStreams is representable as int32_t
12341234

12351235
constexpr Num() : num{-1} {};
12361236

src/plugins/intel_cpu/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ if(WIN32)
160160
endif()
161161

162162
if(ENABLE_CPU_DEBUG_CAPS)
163+
add_definitions(-DENABLE_DEBUG_CAPS)
163164
add_definitions(-DCPU_DEBUG_CAPS)
164165
endif()
165166

@@ -370,11 +371,11 @@ if(BUILD_SHARED_LIBS)
370371
PRIVATE
371372
$<TARGET_PROPERTY:openvino::runtime::dev,INTERFACE_INCLUDE_DIRECTORIES>
372373
$<TARGET_PROPERTY:openvino::itt,INTERFACE_INCLUDE_DIRECTORIES>
373-
$<TARGET_PROPERTY:openvino::shape_inference,INTERFACE_INCLUDE_DIRECTORIES>
374374
$<TARGET_PROPERTY:openvino::snippets,INTERFACE_INCLUDE_DIRECTORIES>
375375
$<TARGET_PROPERTY:openvino::reference,INTERFACE_INCLUDE_DIRECTORIES>
376376
PUBLIC
377377
${CMAKE_CURRENT_SOURCE_DIR}/src
378+
$<TARGET_PROPERTY:openvino::shape_inference,INTERFACE_INCLUDE_DIRECTORIES>
378379
$<TARGET_PROPERTY:openvino::conditional_compilation,INTERFACE_INCLUDE_DIRECTORIES>)
379380

380381
target_include_directories(${TARGET_NAME}_obj SYSTEM PUBLIC $<TARGET_PROPERTY:dnnl,INCLUDE_DIRECTORIES>)

src/plugins/intel_cpu/src/compiled_model.cpp

+23-94
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,17 @@ CompiledModel::CompiledModel(const std::shared_ptr<ov::Model>& model,
5555
m_cfg{std::move(cfg)},
5656
m_name{model->get_name()},
5757
m_loaded_from_cache(loaded_from_cache),
58-
m_sub_memory_manager(std::move(sub_memory_manager)) {
58+
m_sub_memory_manager(std::move(sub_memory_manager)),
59+
m_model_name(model->get_friendly_name()) {
5960
m_mutex = std::make_shared<std::mutex>();
6061
const auto& core = m_plugin->get_core();
6162
if (!core) {
6263
OPENVINO_THROW("Unable to get API version. Core is unavailable");
6364
}
6465

66+
6567
IStreamsExecutor::Config executor_config;
66-
if (m_cfg.exclusiveAsyncRequests) {
68+
if (m_cfg.get_exclusive_async_requests()) {
6769
// special case when all InferRequests are muxed into a single queue
6870
m_task_executor = m_plugin->get_executor_manager()->get_executor("CPU");
6971
} else {
@@ -162,7 +164,7 @@ CompiledModel::GraphGuard::Lock CompiledModel::get_graph() const {
162164
GraphContext::Ptr ctx;
163165
{
164166
std::lock_guard<std::mutex> lock{*m_mutex.get()};
165-
auto isQuantizedFlag = (m_cfg.lpTransformsMode == Config::On) &&
167+
auto isQuantizedFlag = (m_cfg.get_enable_lp_transformations()) &&
166168
ov::pass::low_precision::LowPrecision::isFunctionQuantized(m_model);
167169
ctx = std::make_shared<GraphContext>(m_cfg,
168170
m_socketWeights[socketId],
@@ -229,16 +231,16 @@ ov::Any CompiledModel::get_property(const std::string& name) const {
229231
return m_loaded_from_cache;
230232
}
231233

232-
Config engConfig = get_graph()._graph.getConfig();
233-
auto option = engConfig._config.find(name);
234-
if (option != engConfig._config.end()) {
235-
return option->second;
236-
}
234+
// Config engConfig = get_graph()._graph.getConfig();
235+
// auto option = engConfig._config.find(name);
236+
// if (option != engConfig._config.end()) {
237+
// return option->second;
238+
// }
237239

238-
// @todo Can't we just use local copy (_cfg) instead?
239-
auto graphLock = get_graph();
240-
const auto& graph = graphLock._graph;
241-
const auto& config = graph.getConfig();
240+
// // @todo Can't we just use local copy (_cfg) instead?
241+
// auto graphLock = get_graph();
242+
// const auto& graph = graphLock._graph;
243+
// const auto& config = graph.getConfig();
242244

243245
auto RO_property = [](const std::string& propertyName) {
244246
return ov::PropertyName(propertyName, ov::PropertyMutability::RO);
@@ -277,98 +279,25 @@ ov::Any CompiledModel::get_property(const std::string& name) const {
277279
}
278280

279281
if (name == ov::model_name) {
280-
// @todo Does not seem ok to 'dump()' the whole graph everytime in order to get a name
281-
const std::string modelName = graph.dump()->get_friendly_name();
282-
return decltype(ov::model_name)::value_type(modelName);
282+
return decltype(ov::model_name)::value_type {m_model_name};
283+
}
284+
if (name == ov::loaded_from_cache) {
285+
return decltype(ov::loaded_from_cache)::value_type {m_loaded_from_cache};
283286
}
284287
if (name == ov::optimal_number_of_infer_requests) {
285-
const auto streams = config.streamExecutorConfig.get_streams();
286-
return static_cast<decltype(ov::optimal_number_of_infer_requests)::value_type>(
288+
const auto streams = m_cfg.streamExecutorConfig.get_streams();
289+
return decltype(ov::optimal_number_of_infer_requests)::value_type(
287290
streams > 0 ? streams : 1); // ov::optimal_number_of_infer_requests has no negative values
288291
}
289-
if (name == ov::num_streams) {
290-
const auto streams = config.streamExecutorConfig.get_streams();
291-
return decltype(ov::num_streams)::value_type(
292-
streams); // ov::num_streams has special negative values (AUTO = -1, NUMA = -2)
293-
}
294-
if (name == ov::inference_num_threads) {
295-
const auto num_threads = config.streamExecutorConfig.get_threads();
296-
return static_cast<decltype(ov::inference_num_threads)::value_type>(num_threads);
297-
}
298-
if (name == ov::enable_profiling.name()) {
299-
const bool perfCount = config.collectPerfCounters;
300-
return static_cast<decltype(ov::enable_profiling)::value_type>(perfCount);
301-
}
302-
if (name == ov::hint::inference_precision) {
303-
return decltype(ov::hint::inference_precision)::value_type(config.inferencePrecision);
304-
}
305-
if (name == ov::hint::performance_mode) {
306-
return static_cast<decltype(ov::hint::performance_mode)::value_type>(config.hintPerfMode);
307-
}
308-
if (name == ov::log::level) {
309-
return static_cast<decltype(ov::log::level)::value_type>(config.logLevel);
310-
}
311-
if (name == ov::hint::enable_cpu_pinning.name()) {
312-
const bool use_pin = config.enableCpuPinning;
313-
return static_cast<decltype(ov::hint::enable_cpu_pinning)::value_type>(use_pin);
314-
}
315-
if (name == ov::hint::enable_cpu_reservation.name()) {
316-
const bool use_reserve = config.enableCpuReservation;
317-
return static_cast<decltype(ov::hint::enable_cpu_reservation)::value_type>(use_reserve);
318-
}
319-
if (name == ov::hint::scheduling_core_type) {
320-
const auto stream_mode = config.schedulingCoreType;
321-
return stream_mode;
322-
}
323-
if (name == ov::hint::model_distribution_policy) {
324-
const auto& distribution_policy = config.modelDistributionPolicy;
325-
return distribution_policy;
326-
}
327-
if (name == ov::hint::enable_hyper_threading.name()) {
328-
const bool use_ht = config.enableHyperThreading;
329-
return static_cast<decltype(ov::hint::enable_hyper_threading)::value_type>(use_ht);
330-
}
331-
if (name == ov::hint::execution_mode) {
332-
return config.executionMode;
333-
}
334-
if (name == ov::hint::num_requests) {
335-
return static_cast<decltype(ov::hint::num_requests)::value_type>(config.hintNumRequests);
336-
}
337292
if (name == ov::execution_devices) {
338293
return decltype(ov::execution_devices)::value_type{m_plugin->get_device_name()};
339294
}
340-
if (name == ov::intel_cpu::denormals_optimization) {
341-
return static_cast<decltype(ov::intel_cpu::denormals_optimization)::value_type>(
342-
config.denormalsOptMode == Config::DenormalsOptMode::DO_On);
343-
}
344-
if (name == ov::intel_cpu::sparse_weights_decompression_rate) {
345-
return static_cast<decltype(ov::intel_cpu::sparse_weights_decompression_rate)::value_type>(
346-
config.fcSparseWeiDecompressionRate);
347-
}
348-
if (name == ov::hint::dynamic_quantization_group_size) {
349-
return static_cast<decltype(ov::hint::dynamic_quantization_group_size)::value_type>(
350-
config.fcDynamicQuantizationGroupSize);
351-
}
352-
if (name == ov::hint::kv_cache_precision) {
353-
return decltype(ov::hint::kv_cache_precision)::value_type(config.kvCachePrecision);
354-
}
355-
if (name == ov::key_cache_precision) {
356-
return decltype(ov::key_cache_precision)::value_type(config.keyCachePrecision);
357-
}
358-
if (name == ov::value_cache_precision) {
359-
return decltype(ov::value_cache_precision)::value_type(config.valueCachePrecision);
360-
}
361-
if (name == ov::key_cache_group_size) {
362-
return static_cast<decltype(ov::key_cache_group_size)::value_type>(config.keyCacheGroupSize);
363-
}
364-
if (name == ov::value_cache_group_size) {
365-
return static_cast<decltype(ov::value_cache_group_size)::value_type>(config.valueCacheGroupSize);
366-
}
367-
OPENVINO_THROW("Unsupported property: ", name);
295+
296+
return m_cfg.get_property(name);
368297
}
369298

370299
void CompiledModel::export_model(std::ostream& modelStream) const {
371-
ModelSerializer serializer(modelStream, m_cfg.cacheEncrypt);
300+
ModelSerializer serializer(modelStream, m_cfg.get_cache_encryption_callbacks().encrypt);
372301
serializer << m_model;
373302
}
374303

src/plugins/intel_cpu/src/compiled_model.h

+2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ class CompiledModel : public ov::ICompiledModel {
100100
std::vector<std::shared_ptr<CompiledModel>> m_sub_compiled_models;
101101
std::shared_ptr<SubMemoryManager> m_sub_memory_manager = nullptr;
102102
bool m_has_sub_compiled_models = false;
103+
104+
std::string m_model_name;
103105
};
104106

105107
// This class provides safe access to the internal CompiledModel structures and helps to decouple SyncInferRequest and

0 commit comments

Comments
 (0)