Skip to content

Commit

Permalink
[CPU] New plugin config impl
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-gorokhov committed Dec 26, 2024
1 parent 53ac5aa commit aaf1bb8
Show file tree
Hide file tree
Showing 37 changed files with 1,770 additions and 891 deletions.
8 changes: 5 additions & 3 deletions src/inference/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ target_include_directories(${TARGET_NAME}_obj SYSTEM PRIVATE
target_include_directories(${TARGET_NAME}_obj PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/src"
$<TARGET_PROPERTY:openvino::runtime::dev,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:openvino::shape_inference,INTERFACE_INCLUDE_DIRECTORIES>
$<$<TARGET_EXISTS:openvino_proxy_plugin_obj>:$<TARGET_PROPERTY:openvino_proxy_plugin_obj,INTERFACE_INCLUDE_DIRECTORIES>>
# for ov_plugins.hpp
$<IF:$<AND:$<BOOL:${OV_GENERATOR_MULTI_CONFIG}>,$<VERSION_GREATER_EQUAL:${CMAKE_VERSION},3.20>>,${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>,${CMAKE_CURRENT_BINARY_DIR}>)
Expand All @@ -101,7 +102,7 @@ endif()
# Create library file from object library

add_library(${TARGET_NAME} INTERFACE)
target_link_libraries(${TARGET_NAME} INTERFACE openvino::runtime)
target_link_libraries(${TARGET_NAME} INTERFACE openvino::runtime openvino::shape_inference)
target_include_directories(${TARGET_NAME} INTERFACE $<BUILD_INTERFACE:${PUBLIC_HEADERS_DIR}>)

ov_add_clang_format_target(${TARGET_NAME}_clang FOR_SOURCES ${LIBRARY_SRC} ${LIBRARY_HEADERS} ${PUBLIC_HEADERS})
Expand All @@ -122,14 +123,15 @@ if (TBBBIND_2_5_FOUND)
endif()

target_include_directories(${TARGET_NAME}_s PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>)
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<TARGET_PROPERTY:openvino::shape_inference,INTERFACE_INCLUDE_DIRECTORIES>)

if(WIN32)
set_target_properties(${TARGET_NAME}_s PROPERTIES COMPILE_PDB_NAME ${TARGET_NAME}_s)
endif()

target_link_libraries(${TARGET_NAME}_s PRIVATE openvino::itt ${CMAKE_DL_LIBS}
openvino::runtime::dev openvino::pugixml)
openvino::runtime::dev openvino::pugixml openvino::shape_inference)

target_compile_definitions(${TARGET_NAME}_s PUBLIC USE_STATIC_IE)

Expand Down
16 changes: 10 additions & 6 deletions src/inference/dev_api/openvino/runtime/plugin_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "openvino/runtime/iremote_context.hpp"
#include "openvino/runtime/properties.hpp"
#include "openvino/core/except.hpp"
#include <iostream>

#ifndef COUNT_N
#define COUNT_N(_1, _2, _3, _4, _5, N, ...) N
Expand Down Expand Up @@ -133,8 +134,10 @@ struct ConfigOption : public ConfigOptionBase {
constexpr static const auto visibility = visibility_;

void set_any(const ov::Any any) override {
if (validator)
if (validator) {
// TODO: is very any way to print option name here?
OPENVINO_ASSERT(validator(any.as<T>()), "Invalid value: ", any.as<std::string>());
}
value = any.as<T>();
}

Expand Down Expand Up @@ -220,18 +223,19 @@ class OPENVINO_RUNTIME_API PluginConfig {

bool visit_attributes(ov::AttributeVisitor& visitor);

protected:
virtual void apply_rt_info(std::shared_ptr<IRemoteContext> context, const ov::RTMap& rt_info) {}
virtual void apply_debug_options(std::shared_ptr<IRemoteContext> context);
virtual void finalize_impl(std::shared_ptr<IRemoteContext> context) {}

template <typename T, PropertyMutability mutability>
bool is_set_by_user(const ov::Property<T, mutability>& property) const {
return m_user_properties.find(property.name()) != m_user_properties.end();
}

protected:
virtual void apply_rt_info(std::shared_ptr<IRemoteContext> context, const ov::RTMap& rt_info) {}
virtual void apply_debug_options(std::shared_ptr<IRemoteContext> context);
virtual void finalize_impl(std::shared_ptr<IRemoteContext> context) {}

ConfigOptionBase* get_option_ptr(const std::string& name) const {
auto it = m_options_map.find(name);
// TODO: print more meaningful error message
OPENVINO_ASSERT(it != m_options_map.end(), "Option not found: ", name);
OPENVINO_ASSERT(it->second != nullptr, "Option is invalid: ", name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#pragma once

#include "openvino/runtime/properties.hpp"
#include "ov_optional.hpp"

namespace ov {

Expand Down Expand Up @@ -45,7 +46,7 @@ namespace intel_cpu {
* ie.set_property(ov::denormals_optimization(false)); // disable denormals optimization
* @endcode
*/
static constexpr Property<bool> denormals_optimization{"CPU_DENORMALS_OPTIMIZATION"};
static constexpr Property<ov::optional<bool>> denormals_optimization{"CPU_DENORMALS_OPTIMIZATION"};

/**
* @brief This property defines threshold for sparse weights decompression feature activation
Expand Down
2 changes: 1 addition & 1 deletion src/inference/include/openvino/runtime/properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ namespace streams {
* @ingroup ov_runtime_cpp_prop_api
*/
struct Num {
using Base = std::tuple<int32_t>; //!< NumStreams is representable as int32_t
// using Base = std::tuple<int32_t>; //!< NumStreams is representable as int32_t

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

Expand Down
9 changes: 8 additions & 1 deletion src/inference/src/dev/plugin_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,14 @@ void PluginConfig::set_user_property(const ov::AnyMap& config, OptionVisibility

for (auto& kv : config) {
auto& name = kv.first;
auto& val = kv.second;
auto val = kv.second;

// [WA] ov::Any cannot be casted from int to streams::Num
// Can be reproduced with CpuExecNetworkCheckModelStreamsHasHigherPriorityThanThroughputHint test
// Should be fixed before the merge
if (name == ov::num_streams.name()) {
val = val.as<std::string>();
}

auto option = get_option_ptr(name);
if ((allowed_visibility & option->get_visibility()) != option->get_visibility()) {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/intel_cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,11 @@ if(BUILD_SHARED_LIBS)
PRIVATE
$<TARGET_PROPERTY:openvino::runtime::dev,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:openvino::itt,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:openvino::shape_inference,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:openvino::snippets,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:openvino::reference,INTERFACE_INCLUDE_DIRECTORIES>
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
$<TARGET_PROPERTY:openvino::shape_inference,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:openvino::conditional_compilation,INTERFACE_INCLUDE_DIRECTORIES>)

target_include_directories(${TARGET_NAME}_obj SYSTEM PUBLIC $<TARGET_PROPERTY:dnnl,INCLUDE_DIRECTORIES>)
Expand Down
95 changes: 20 additions & 75 deletions src/plugins/intel_cpu/src/compiled_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ CompiledModel::CompiledModel(const std::shared_ptr<ov::Model>& model,
m_cfg{cfg},
m_name{model->get_name()},
m_loaded_from_cache(loaded_from_cache),
m_sub_memory_manager(sub_memory_manager) {
m_sub_memory_manager(sub_memory_manager),
m_model_name(model->get_friendly_name()) {
m_mutex = std::make_shared<std::mutex>();
const auto& core = m_plugin->get_core();
if (!core)
OPENVINO_THROW("Unable to get API version. Core is unavailable");

IStreamsExecutor::Config executor_confg;
if (cfg.exclusiveAsyncRequests) {
if (cfg.get_exclusive_async_requests()) {
// special case when all InferRequests are muxed into a single queue
m_task_executor = m_plugin->get_executor_manager()->get_executor("CPU");
} else {
Expand Down Expand Up @@ -156,7 +157,7 @@ CompiledModel::GraphGuard::Lock CompiledModel::get_graph() const {
GraphContext::Ptr ctx;
{
std::lock_guard<std::mutex> lock{*m_mutex.get()};
auto isQuantizedFlag = (m_cfg.lpTransformsMode == Config::On) &&
auto isQuantizedFlag = (m_cfg.get_lp_transforms_mode()) &&
ov::pass::low_precision::LowPrecision::isFunctionQuantized(m_model);

ctx = std::make_shared<GraphContext>(m_cfg,
Expand Down Expand Up @@ -219,16 +220,16 @@ ov::Any CompiledModel::get_property(const std::string& name) const {
return m_loaded_from_cache;
}

Config engConfig = get_graph()._graph.getConfig();
auto option = engConfig._config.find(name);
if (option != engConfig._config.end()) {
return option->second;
}
// Config engConfig = get_graph()._graph.getConfig();
// auto option = engConfig._config.find(name);
// if (option != engConfig._config.end()) {
// return option->second;
// }

// @todo Can't we just use local copy (_cfg) instead?
auto graphLock = get_graph();
const auto& graph = graphLock._graph;
const auto& config = graph.getConfig();
// // @todo Can't we just use local copy (_cfg) instead?
// auto graphLock = get_graph();
// const auto& graph = graphLock._graph;
// const auto& config = graph.getConfig();

auto RO_property = [](const std::string& propertyName) {
return ov::PropertyName(propertyName, ov::PropertyMutability::RO);
Expand Down Expand Up @@ -266,78 +267,22 @@ ov::Any CompiledModel::get_property(const std::string& name) const {
}

if (name == ov::model_name) {
// @todo Does not seem ok to 'dump()' the whole graph everytime in order to get a name
const std::string modelName = graph.dump()->get_friendly_name();
return decltype(ov::model_name)::value_type(modelName);
return decltype(ov::model_name)::value_type {m_model_name};
} else if (name == ov::loaded_from_cache) {
return decltype(ov::loaded_from_cache)::value_type {m_loaded_from_cache};
} else if (name == ov::optimal_number_of_infer_requests) {
const auto streams = config.streamExecutorConfig.get_streams();
const auto streams = m_cfg.streamExecutorConfig.get_streams();
return decltype(ov::optimal_number_of_infer_requests)::value_type(
streams > 0 ? streams : 1); // ov::optimal_number_of_infer_requests has no negative values
} else if (name == ov::num_streams) {
const auto streams = config.streamExecutorConfig.get_streams();
return decltype(ov::num_streams)::value_type(
streams); // ov::num_streams has special negative values (AUTO = -1, NUMA = -2)
OPENVINO_SUPPRESS_DEPRECATED_START
} else if (name == ov::affinity) {
const auto affinity = config.threadBindingType;
switch (affinity) {
case IStreamsExecutor::ThreadBindingType::NONE:
return ov::Affinity::NONE;
case IStreamsExecutor::ThreadBindingType::CORES:
return ov::Affinity::CORE;
case IStreamsExecutor::ThreadBindingType::NUMA:
return ov::Affinity::NUMA;
case IStreamsExecutor::ThreadBindingType::HYBRID_AWARE:
return ov::Affinity::HYBRID_AWARE;
}
return ov::Affinity::NONE;
OPENVINO_SUPPRESS_DEPRECATED_END
} else if (name == ov::inference_num_threads) {
const auto num_threads = config.streamExecutorConfig.get_threads();
return decltype(ov::inference_num_threads)::value_type(num_threads);
} else if (name == ov::enable_profiling.name()) {
const bool perfCount = config.collectPerfCounters;
return decltype(ov::enable_profiling)::value_type(perfCount);
} else if (name == ov::hint::inference_precision) {
return decltype(ov::hint::inference_precision)::value_type(config.inferencePrecision);
} else if (name == ov::hint::performance_mode) {
return decltype(ov::hint::performance_mode)::value_type(config.hintPerfMode);
} else if (name == ov::log::level) {
return decltype(ov::log::level)::value_type(config.logLevel);
} else if (name == ov::hint::enable_cpu_pinning.name()) {
const bool use_pin = config.enableCpuPinning;
return decltype(ov::hint::enable_cpu_pinning)::value_type(use_pin);
} else if (name == ov::hint::scheduling_core_type) {
const auto stream_mode = config.schedulingCoreType;
return stream_mode;
} else if (name == ov::hint::model_distribution_policy) {
const auto& distribution_policy = config.modelDistributionPolicy;
return distribution_policy;
} else if (name == ov::hint::enable_hyper_threading.name()) {
const bool use_ht = config.enableHyperThreading;
return decltype(ov::hint::enable_hyper_threading)::value_type(use_ht);
} else if (name == ov::hint::execution_mode) {
return config.executionMode;
} else if (name == ov::hint::num_requests) {
return decltype(ov::hint::num_requests)::value_type(config.hintNumRequests);
} else if (name == ov::execution_devices) {
return decltype(ov::execution_devices)::value_type{m_plugin->get_device_name()};
} else if (name == ov::intel_cpu::denormals_optimization) {
return decltype(ov::intel_cpu::denormals_optimization)::value_type(config.denormalsOptMode ==
Config::DenormalsOptMode::DO_On);
} else if (name == ov::intel_cpu::sparse_weights_decompression_rate) {
return decltype(ov::intel_cpu::sparse_weights_decompression_rate)::value_type(
config.fcSparseWeiDecompressionRate);
} else if (name == ov::hint::dynamic_quantization_group_size) {
return decltype(ov::hint::dynamic_quantization_group_size)::value_type(config.fcDynamicQuantizationGroupSize);
} else if (name == ov::hint::kv_cache_precision) {
return decltype(ov::hint::kv_cache_precision)::value_type(config.kvCachePrecision);
}
OPENVINO_THROW("Unsupported property: ", name);

return m_cfg.get_property(name);
}

void CompiledModel::export_model(std::ostream& modelStream) const {
ModelSerializer serializer(modelStream, m_cfg.cacheEncrypt);
ModelSerializer serializer(modelStream, m_cfg.get_cache_encryption_callbacks().encrypt);
serializer << m_model;
}

Expand Down
2 changes: 2 additions & 0 deletions src/plugins/intel_cpu/src/compiled_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ class CompiledModel : public ov::ICompiledModel {
std::vector<std::shared_ptr<CompiledModel>> m_sub_compiled_models;
std::shared_ptr<SubMemoryManager> m_sub_memory_manager = nullptr;
bool m_has_sub_compiled_models = false;

std::string m_model_name;
};

// This class provides safe access to the internal CompiledModel structures and helps to decouple SyncInferRequest and
Expand Down
Loading

0 comments on commit aaf1bb8

Please sign in to comment.