OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
Update latency mode threading on Pcore + LP Ecore platform (#33931)
Wanglei Shen30ba44470978
diff --git a/src/plugins/intel_cpu/src/cpu_streams_calculation.cpp b/src/plugins/intel_cpu/src/cpu_streams_calculation.cppindex f5d95c25e3d..410b7fc7385 100644--- a/src/plugins/intel_cpu/src/cpu_streams_calculation.cpp+++ b/src/plugins/intel_cpu/src/cpu_streams_calculation.cpp@@ -26,9 +26,11 @@#if (defined(OPENVINO_ARCH_ARM64) && defined(__linux__))# include "cpu/aarch64/cpu_isa_traits.hpp"#else-# include <oneapi/dnnl/dnnl.hpp>+# if !defined(OPENVINO_ARCH_RISCV64)+# include <oneapi/dnnl/dnnl.hpp>-# include "onednn/dnnl.h"+# include "onednn/dnnl.h"+# endif# include "openvino/runtime/performance_heuristics.hpp"#endif#include "cpu_map_scheduling.hpp"@@ -46,6 +48,265 @@ constexpr int TP_CPU_LIMIT = 32;namespace ov::intel_cpu {+namespace ThreadPreferenceConstants {++[[maybe_unused]] constexpr int INT8_EFFICIENCY_THRESHOLD = 4;+[[maybe_unused]] constexpr int FP32_EFFICIENCY_THRESHOLD = 2;++[[maybe_unused]] constexpr float ISA_THRESHOLD_SSE41 = 0.5F;+[[maybe_unused]] constexpr float ISA_THRESHOLD_AVX2 = 1.0F;+[[maybe_unused]] constexpr float ISA_THRESHOLD_VNNI = 2.0F;+[[maybe_unused]] constexpr float ISA_THRESHOLD_AMX = 4.0F;++[[maybe_unused]] constexpr float MEM_TOLERANCE_VERY_HIGH = 50.0F;+[[maybe_unused]] constexpr float MEM_TOLERANCE_HIGH = 4.5F;+[[maybe_unused]] constexpr float MEM_TOLERANCE_MEDIUM_HIGH = 2.5F;+[[maybe_unused]] constexpr float MEM_TOLERANCE_MEDIUM = 1.0F;+[[maybe_unused]] constexpr float MEM_TOLERANCE_MEDIUM_LOW = 0.5F;+[[maybe_unused]] constexpr float MEM_TOLERANCE_LOW = 0.2F;+[[maybe_unused]] constexpr float MEM_TOLERANCE_SECONDARY_LOW = 0.08F;+[[maybe_unused]] constexpr float MEM_TOLERANCE_VERY_LOW = 0.06F;++[[maybe_unused]] constexpr float CONV_RATIO_VERY_HIGH = 0.9F;+[[maybe_unused]] constexpr float CONV_RATIO_HIGH = 0.8F;+[[maybe_unused]] constexpr float CONV_RATIO_MEDIUM = 0.6F;+[[maybe_unused]] constexpr float CONV_RATIO_MEDIUM_LOW = 0.5F;+[[maybe_unused]] constexpr float CONV_RATIO_LOW = 0.46F;+[[maybe_unused]] constexpr float CONV_RATIO_MINIMAL = 0.28F;+[[maybe_unused]] constexpr float CONV_RATIO_VERY_LOW = 0.2F;+[[maybe_unused]] constexpr float CONV_RATIO_ULTRA_LOW = 0.1F;++[[maybe_unused]] constexpr float GEMM_RATIO_HIGH = 0.14F;+[[maybe_unused]] constexpr float GEMM_RATIO_LOW = 0.05F;++[[maybe_unused]] constexpr int ECORE_RATIO_THRESHOLD = 2;++[[maybe_unused]] constexpr int ARM64_THREADS_DEFAULT = 8;+[[maybe_unused]] constexpr int ARM64_THREADS_SVE = 16;++[[maybe_unused]] constexpr int ARM_THREADS_DEFAULT = 4;+[[maybe_unused]] constexpr int ARM_THREADS_HIGH = 8;++[[maybe_unused]] constexpr int APPLE_THREADS_MINIMAL = 1;+[[maybe_unused]] constexpr int APPLE_THREADS_LOW = 2;+[[maybe_unused]] constexpr int APPLE_THREADS_HIGH = 4;++} // namespace ThreadPreferenceConstants++namespace {++#if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64)+float get_isa_threshold_multiplier(dnnl::cpu_isa isa) {+ using namespace ThreadPreferenceConstants;+ switch (isa) {+ case dnnl::cpu_isa::sse41:+ return ISA_THRESHOLD_SSE41;+ case dnnl::cpu_isa::avx2:+ case dnnl::cpu_isa::avx512_core:+ return ISA_THRESHOLD_AVX2;+ case dnnl::cpu_isa::avx512_core_vnni:+ case dnnl::cpu_isa::avx2_vnni:+ case dnnl::cpu_isa::avx2_vnni_2:+ return ISA_THRESHOLD_VNNI;+ case dnnl::cpu_isa::avx512_core_amx:+ return ISA_THRESHOLD_AMX;+ default:+ return ISA_THRESHOLD_AVX2;+ }+}+#endif++bool should_use_all_cores_for_latency(int main_cores, int efficient_cores, bool int8_intensive) {+ using namespace ThreadPreferenceConstants;+ const int threshold = int8_intensive ? INT8_EFFICIENCY_THRESHOLD : FP32_EFFICIENCY_THRESHOLD;+ return main_cores * threshold <= efficient_cores;+}++bool should_use_ecores_for_llm(int efficient_cores, int main_cores) {+ using namespace ThreadPreferenceConstants;+ return efficient_cores > ECORE_RATIO_THRESHOLD * main_cores;+}++#if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64) || defined(OPENVINO_ARCH_RISCV64)+bool is_main_core_case_1(const ov::MemBandwidthPressure& tolerance) {+ using namespace ThreadPreferenceConstants;+ return tolerance.ratio_mem_limited_convs > CONV_RATIO_HIGH;+}++bool is_main_core_case_2(const ov::MemBandwidthPressure& tolerance) {+ using namespace ThreadPreferenceConstants;+ return tolerance.ratio_mem_limited_convs == 0.0F && tolerance.ratio_compute_convs == 0.0F &&+ tolerance.max_mem_tolerance >= MEM_TOLERANCE_HIGH;+}++bool is_main_core_case_3(const ov::MemBandwidthPressure& tolerance) {+ using namespace ThreadPreferenceConstants;+ return tolerance.ratio_mem_limited_convs == 0.0F && tolerance.ratio_compute_convs > 0.0F &&+ tolerance.ratio_compute_convs < 1.0F &&+ static_cast<float>(tolerance.total_light_convs) >+ CONV_RATIO_VERY_HIGH * static_cast<float>(tolerance.total_convs);+}++bool is_main_core_case_4(const ov::MemBandwidthPressure& tolerance) {+ using namespace ThreadPreferenceConstants;+ return tolerance.ratio_mem_limited_convs > 0.0F && tolerance.ratio_compute_convs > 0.0F &&+ static_cast<float>(tolerance.total_light_convs) > CONV_RATIO_LOW * static_cast<float>(tolerance.total_convs);+}++bool is_static_partitioner_case_1(const ov::MemBandwidthPressure& tolerance) {+ return tolerance.total_nodes == 0;+}++bool is_static_partitioner_case_2(const ov::MemBandwidthPressure& tolerance) {+ using namespace ThreadPreferenceConstants;+ return tolerance.total_convs > 0 && static_cast<float>(tolerance.total_light_convs) >+ CONV_RATIO_MEDIUM * static_cast<float>(tolerance.total_convs);+}++bool is_static_partitioner_case_3_with_lp_ecores(const ov::MemBandwidthPressure& tolerance) {+ using namespace ThreadPreferenceConstants;+ return tolerance.total_convs > 0 &&+ static_cast<float>(tolerance.total_light_convs) <=+ CONV_RATIO_MEDIUM * static_cast<float>(tolerance.total_convs) &&+ tolerance.ratio_compute_convs + tolerance.ratio_mem_limited_convs < CONV_RATIO_VERY_HIGH &&+ tolerance.ratio_mem_limited_convs < CONV_RATIO_VERY_LOW && tolerance.ratio_mem_limited_gemms == 0.0F &&+ ((tolerance.ratio_mem_limited_adds < CONV_RATIO_MINIMAL &&+ tolerance.max_mem_tolerance >= MEM_TOLERANCE_VERY_LOW) ||+ tolerance.ratio_compute_convs == 0 || tolerance.ratio_mem_limited_convs == 0);+}++bool is_static_partitioner_case_3_without_lp_ecores(const ov::MemBandwidthPressure& tolerance) {+ using namespace ThreadPreferenceConstants;+ return tolerance.total_convs > 0 &&+ static_cast<float>(tolerance.total_light_convs) <=+ CONV_RATIO_MEDIUM * static_cast<float>(tolerance.total_convs) &&+ tolerance.ratio_compute_convs + tolerance.ratio_mem_limited_convs < CONV_RATIO_VERY_HIGH &&+ tolerance.ratio_mem_limited_convs < CONV_RATIO_VERY_LOW && tolerance.ratio_mem_limited_gemms == 0.0F &&+ tolerance.ratio_mem_limited_adds < CONV_RATIO_MINIMAL &&+ tolerance.max_mem_tolerance >= MEM_TOLERANCE_VERY_LOW;+}++bool is_static_partitioner_case_4_with_lp_ecores(const ov::MemBandwidthPressure& tolerance) {+ using namespace ThreadPreferenceConstants;+ return tolerance.total_convs == 0 &&+ (tolerance.max_mem_tolerance > MEM_TOLERANCE_MEDIUM_HIGH ||+ static_cast<float>(tolerance.total_gemms) >= GEMM_RATIO_HIGH * static_cast<float>(tolerance.total_nodes));+}++bool is_static_partitioner_case_4_without_lp_ecores(const ov::MemBandwidthPressure& tolerance) {+ using namespace ThreadPreferenceConstants;+ return tolerance.total_convs == 0 &&+ static_cast<float>(tolerance.total_gemms) < GEMM_RATIO_LOW * static_cast<float>(tolerance.total_nodes);+}++bool is_static_partitioner_case_5(const ov::MemBandwidthPressure& tolerance) {+ using namespace ThreadPreferenceConstants;+ return tolerance.total_convs > 0 &&+ static_cast<float>(tolerance.total_light_convs) <=+ CONV_RATIO_MEDIUM * static_cast<float>(tolerance.total_convs) &&+ tolerance.ratio_compute_convs >= CONV_RATIO_VERY_HIGH * tolerance.ratio_mem_limited_convs &&+ tolerance.ratio_compute_convs == 1.0F && tolerance.ratio_mem_limited_adds == 1.0F &&+ static_cast<float>(tolerance.total_heavy_convs) >+ CONV_RATIO_ULTRA_LOW * static_cast<float>(tolerance.total_nodes);+}++void determine_tbb_partitioner_and_threads(Config& config,+ const std::vector<std::vector<int>>& proc_type_table,+ const ov::MemBandwidthPressure& tolerance,+ bool int8_intensive) {+ if (config.tbbPartitioner != TbbPartitioner::NONE) {+ return;+ }++ const bool has_lp_ecores = proc_type_table[0][LP_EFFICIENT_CORE_PROC] > 0;++ if (has_lp_ecores && int8_intensive && tolerance.total_convs > 0) {+ if (is_main_core_case_1(tolerance) || is_main_core_case_2(tolerance) || is_main_core_case_3(tolerance) ||+ is_main_core_case_4(tolerance)) {+ config.modelPreferThreadsLatency = proc_type_table[0][MAIN_CORE_PROC];+ config.tbbPartitioner = TbbPartitioner::STATIC;+ return;+ }+ }++ bool static_case_3 = has_lp_ecores ? is_static_partitioner_case_3_with_lp_ecores(tolerance)+ : is_static_partitioner_case_3_without_lp_ecores(tolerance);++ bool static_case_4 = has_lp_ecores ? is_static_partitioner_case_4_with_lp_ecores(tolerance)+ : is_static_partitioner_case_4_without_lp_ecores(tolerance);++ bool static_case_5 = has_lp_ecores && is_static_partitioner_case_5(tolerance);++ if (is_static_partitioner_case_1(tolerance) || is_static_partitioner_case_2(tolerance) || static_case_3 ||+ static_case_4 || static_case_5) {+ config.tbbPartitioner = TbbPartitioner::STATIC;+ } else {+ config.tbbPartitioner = TbbPartitioner::AUTO;+ }+}+#endif++[[maybe_unused]] bool is_network_compute_limited(const ov::MemBandwidthPressure& tolerance) {+ return tolerance.ratio_compute_convs == ov::MemBandwidthPressure::ALL ||+ tolerance.ratio_compute_deconvs == ov::MemBandwidthPressure::ALL;+}++[[maybe_unused]] bool is_below_isa_threshold(float max_tolerance, float memThresholdAssumeLimitedForISA) {+ return max_tolerance > memThresholdAssumeLimitedForISA;+}++[[maybe_unused]] bool is_below_general_threshold(float max_tolerance) {+ return max_tolerance > ov::MemBandwidthPressure::LIMITED;+}++#if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64) || defined(OPENVINO_ARCH_RISCV64)+bool is_lp_main_core_case_1(const ov::MemBandwidthPressure& tolerance) {+ using namespace ThreadPreferenceConstants;+ return tolerance.total_convs == 0 && tolerance.max_mem_tolerance > MEM_TOLERANCE_VERY_HIGH &&+ static_cast<float>(tolerance.total_gemms) < GEMM_RATIO_LOW * static_cast<float>(tolerance.total_nodes);+}++bool is_lp_main_core_case_2(const ov::MemBandwidthPressure& tolerance) {+ using namespace ThreadPreferenceConstants;+ return tolerance.total_convs > 0 && tolerance.total_gemms == 1 &&+ tolerance.max_mem_tolerance<MEM_TOLERANCE_MEDIUM_LOW&& static_cast<float>(+ tolerance.total_light_convs)> CONV_RATIO_HIGH *+ static_cast<float>(tolerance.total_convs);+}++bool is_lp_auto_case_1(const ov::MemBandwidthPressure& tolerance) {+ using namespace ThreadPreferenceConstants;+ return tolerance.max_mem_tolerance < MEM_TOLERANCE_MEDIUM && tolerance.ratio_compute_convs == 0 &&+ tolerance.ratio_mem_limited_convs == 0;+}++bool is_lp_auto_case_2(const ov::MemBandwidthPressure& tolerance) {+ using namespace ThreadPreferenceConstants;+ return tolerance.ratio_compute_convs + tolerance.ratio_mem_limited_convs >= 1.0F &&+ tolerance.ratio_mem_limited_deconvs < 1.0F;+}++bool is_lp_auto_case_3(const ov::MemBandwidthPressure& tolerance) {+ using namespace ThreadPreferenceConstants;+ return tolerance.total_convs > 52 && tolerance.ratio_compute_convs > 0 && tolerance.ratio_mem_limited_convs > 0 &&+ tolerance.ratio_mem_limited_convs < CONV_RATIO_VERY_LOW;+}++bool is_lp_auto_case_4(const ov::MemBandwidthPressure& tolerance) {+ using namespace ThreadPreferenceConstants;+ return tolerance.max_mem_tolerance < MEM_TOLERANCE_SECONDARY_LOW &&+ tolerance.ratio_compute_convs < CONV_RATIO_HIGH && tolerance.ratio_mem_limited_convs < CONV_RATIO_MEDIUM_LOW;+}++bool is_lp_auto_case_5(const ov::MemBandwidthPressure& tolerance) {+ using namespace ThreadPreferenceConstants;+ return tolerance.ratio_compute_convs > 0 && tolerance.ratio_compute_convs < CONV_RATIO_ULTRA_LOW &&+ tolerance.ratio_mem_limited_convs >= CONV_RATIO_VERY_LOW;+}+#endif++} // namespace+void sort_table_by_numa_node_id(int current_numa_node, std::vector<std::vector<int>>& proc_type_table) {if (proc_type_table.size() > 1) {for (size_t i = 1; i < proc_type_table.size(); i++) {@@ -267,6 +528,11 @@ std::vector<std::vector<int>> get_streams_info_table(} else {stream_info[PROC_TYPE] = ALL_PROC;n_threads_per_stream = proc_type_table[0][ALL_PROC] - proc_type_table[0][LP_EFFICIENT_CORE_PROC];+ if (proc_type_table[0][LP_EFFICIENT_CORE_PROC] > 0 &&+ proc_type_table[0][EFFICIENT_CORE_PROC] == 0) {+ n_threads_per_stream = std::max(model_prefer_threads, n_threads_per_stream);+ n_threads_per_stream = std::min(n_threads_per_stream, proc_type_table[0][ALL_PROC]);+ }}} else {n_threads_per_stream = proc_type_table[0][ALL_PROC] - proc_type_table[0][LP_EFFICIENT_CORE_PROC];@@ -604,240 +870,270 @@ std::vector<std::vector<int>> get_streams_rank_table(const std::vector<std::vectreturn rank_table;}-int get_model_prefer_threads(const int num_streams,+#if defined(OPENVINO_ARCH_ARM64) && defined(__linux__)+static void configure_arm64_linux_threads(Config& config,+ const std::vector<std::vector<int>>& proc_type_table,+ bool int8_intensive,+ bool is_LLM) {+ using namespace ThreadPreferenceConstants;+ config.modelPreferThreadsThroughput = ARM64_THREADS_DEFAULT;+ if (dnnl::impl::cpu::aarch64::mayiuse(dnnl::impl::cpu::aarch64::cpu_isa_t::sve_128)) {+ config.modelPreferThreadsThroughput = ARM64_THREADS_SVE;+ }++ const int main_cores = proc_type_table[0][MAIN_CORE_PROC];+ const int efficient_cores = proc_type_table[0][EFFICIENT_CORE_PROC];++ bool use_all_cores = should_use_all_cores_for_latency(main_cores, efficient_cores, int8_intensive);++ if (use_all_cores && (!is_LLM || should_use_ecores_for_llm(efficient_cores, main_cores))) {+ config.modelPreferThreadsLatency = main_cores + efficient_cores;+ } else {+ config.modelPreferThreadsLatency = main_cores;+ }+}+#endif++#if defined(OPENVINO_ARCH_ARM) && defined(__linux__)+void configure_arm_linux_threads(Config& config,+ const std::vector<std::vector<int>>& proc_type_table,+ const ov::MemBandwidthPressure& tolerance,+ bool int8_intensive,+ bool is_LLM) {+ using namespace ThreadPreferenceConstants;+ config.modelPreferThreadsThroughput = ARM_THREADS_DEFAULT;++ if (tolerance.max_mem_tolerance == ov::MemBandwidthPressure::UNKNOWN) {+ if (tolerance.ratio_compute_convs == ov::MemBandwidthPressure::ALL) {+ config.modelPreferThreadsThroughput = ARM_THREADS_HIGH;+ }+ } else if ((tolerance.max_mem_tolerance < ov::MemBandwidthPressure::LIMITED) &&+ ((tolerance.ratio_mem_limited_deconvs > ov::MemBandwidthPressure::LIMITED) ||+ (tolerance.ratio_mem_limited_gemms > ov::MemBandwidthPressure::LIMITED))) {+ config.modelPreferThreadsThroughput = ARM_THREADS_HIGH;+ }++ const int main_cores = proc_type_table[0][MAIN_CORE_PROC];+ const int efficient_cores = proc_type_table[0][EFFICIENT_CORE_PROC];++ bool use_all_cores = should_use_all_cores_for_latency(main_cores, efficient_cores, int8_intensive);++ if (use_all_cores && (!is_LLM || should_use_ecores_for_llm(efficient_cores, main_cores))) {+ config.modelPreferThreadsLatency = main_cores + efficient_cores;+ } else {+ config.modelPreferThreadsLatency = main_cores;+ }+}+#endif++#if (defined(OPENVINO_ARCH_ARM) || defined(OPENVINO_ARCH_ARM64)) && defined(__APPLE__)+void configure_apple_threads(Config& config,const std::vector<std::vector<int>>& proc_type_table,- const std::shared_ptr<ov::Model>& model,- Config& config) {- bool int8_intensive = ov::op::util::has_op_with_type<ov::op::v0::FakeQuantize>(model);- bool is_LLM = config.modelType != Config::ModelType::CNN;+ const ov::MemBandwidthPressure& tolerance,+ float memThresholdAssumeLimitedForISA,+ bool int8_intensive,+ bool is_LLM) {+ using namespace ThreadPreferenceConstants;+ const int main_cores = proc_type_table[0][MAIN_CORE_PROC];+ const int efficient_cores = proc_type_table[0][EFFICIENT_CORE_PROC];++ if ((proc_type_table.size() == 1) && (efficient_cores > 0)) {+ config.modelPreferThreadsLatency = main_cores > efficient_cores ? main_cores : proc_type_table[0][ALL_PROC];+ } else {+ bool use_all_cores = should_use_all_cores_for_latency(main_cores, efficient_cores, int8_intensive);++ if (use_all_cores && (!is_LLM || should_use_ecores_for_llm(efficient_cores, main_cores))) {+ config.modelPreferThreadsLatency = main_cores + efficient_cores;+ } else {+ config.modelPreferThreadsLatency = main_cores;+ }+ }++ config.modelPreferThreadsThroughput = APPLE_THREADS_MINIMAL;++ if (tolerance.max_mem_tolerance == ov::MemBandwidthPressure::UNKNOWN) {+ if (is_network_compute_limited(tolerance)) {+ config.modelPreferThreadsThroughput = APPLE_THREADS_HIGH;+ }+ } else if (is_below_isa_threshold(tolerance.max_mem_tolerance, memThresholdAssumeLimitedForISA)) {+ config.modelPreferThreadsThroughput = APPLE_THREADS_MINIMAL;+ } else if (is_below_general_threshold(tolerance.max_mem_tolerance)) {+ config.modelPreferThreadsThroughput = APPLE_THREADS_MINIMAL;+ } else if (tolerance.ratio_mem_limited_deconvs > ov::MemBandwidthPressure::LIMITED &&+ tolerance.ratio_compute_convs < ov::MemBandwidthPressure::ALL) {+ config.modelPreferThreadsThroughput = APPLE_THREADS_HIGH;+ } else if (tolerance.ratio_mem_limited_deconvs <= ov::MemBandwidthPressure::LIMITED &&+ tolerance.ratio_mem_limited_convs <= ov::MemBandwidthPressure::LIMITED &&+ tolerance.ratio_compute_convs > ov::MemBandwidthPressure::LIMITED) {+ config.modelPreferThreadsThroughput = APPLE_THREADS_LOW;+ }+}+#endif- auto default_prefer_threads_latency = [&]() {- const int int8_threshold = 4; // ~relative efficiency of the VNNI-intensive code for Big vs Little cores;- const int fp32_threshold = 2; // ~relative efficiency of the AVX2 fp32 code for Big vs Little cores;+#if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64) || defined(OPENVINO_ARCH_RISCV64)+void configure_x86_hybrid_threads(Config& config,+ const std::vector<std::vector<int>>& proc_type_table,+ const ov::MemBandwidthPressure& tolerance,+ bool int8_intensive,+ bool is_LLM) {+ const int main_cores = proc_type_table[0][MAIN_CORE_PROC];+ const int efficient_cores = proc_type_table[0][EFFICIENT_CORE_PROC];+ const int lp_efficient_cores = proc_type_table[0][LP_EFFICIENT_CORE_PROC];- bool use_all_cores = proc_type_table[0][MAIN_CORE_PROC] <= (proc_type_table[0][EFFICIENT_CORE_PROC] /- (int8_intensive ? int8_threshold : fp32_threshold));+ const bool is_hybrid_applicable = (main_cores < config.threads || config.threads == 0) &&+ (ov::get_number_of_blocked_cores() != 0 || lp_efficient_cores > 0) &&+ efficient_cores <= 2 * main_cores;- if (use_all_cores &&- (!is_LLM || proc_type_table[0][EFFICIENT_CORE_PROC] > 2 * proc_type_table[0][MAIN_CORE_PROC])) {- config.modelPreferThreadsLatency =- proc_type_table[0][MAIN_CORE_PROC] + proc_type_table[0][EFFICIENT_CORE_PROC];+ if (is_hybrid_applicable) {+ if (is_LLM) {+ config.modelPreferThreadsLatency = main_cores;} else {- config.modelPreferThreadsLatency = proc_type_table[0][MAIN_CORE_PROC];+ config.modelPreferThreadsLatency = main_cores + efficient_cores;+ determine_tbb_partitioner_and_threads(config, proc_type_table, tolerance, int8_intensive);}- return;- };+ } else {+ // Fall back to default latency preference logic+ bool use_all_cores = should_use_all_cores_for_latency(main_cores, efficient_cores, int8_intensive);++ if (use_all_cores && (!is_LLM || should_use_ecores_for_llm(efficient_cores, main_cores))) {+ config.modelPreferThreadsLatency = main_cores + efficient_cores;+ } else {+ config.modelPreferThreadsLatency = main_cores;+ }+ }+}- const int sockets = get_num_sockets();+void configure_x86_hybrid_lp_threads(Config& config,+ const std::vector<std::vector<int>>& proc_type_table,+ const ov::MemBandwidthPressure& tolerance) {+ const int main_cores = proc_type_table[0][MAIN_CORE_PROC];+ const int lp_efficient_cores = proc_type_table[0][LP_EFFICIENT_CORE_PROC];- if (-1 == config.modelPreferThreads) {- config.modelPreferThreads = 0;-#if (defined(OPENVINO_ARCH_ARM64) && defined(__linux__))- config.modelPreferThreadsThroughput = 8;- if (dnnl::impl::cpu::aarch64::mayiuse(dnnl::impl::cpu::aarch64::cpu_isa_t::sve_128)) {- config.modelPreferThreadsThroughput = 16;+ if (is_lp_auto_case_1(tolerance) || is_lp_auto_case_2(tolerance) || is_lp_auto_case_3(tolerance) ||+ is_lp_auto_case_4(tolerance) || is_lp_auto_case_5(tolerance)) {+ config.modelPreferThreadsLatency = main_cores + lp_efficient_cores;+ config.tbbPartitioner =+ config.tbbPartitioner == TbbPartitioner::NONE ? TbbPartitioner::AUTO : config.tbbPartitioner;+ } else {+ if (is_lp_main_core_case_1(tolerance) || is_lp_main_core_case_2(tolerance)) {+ config.modelPreferThreadsLatency = main_cores;+ } else {+ config.modelPreferThreadsLatency = main_cores + lp_efficient_cores;}- default_prefer_threads_latency();+ config.tbbPartitioner =+ config.tbbPartitioner == TbbPartitioner::NONE ? TbbPartitioner::STATIC : config.tbbPartitioner;+ }+}++void configure_x86_non_hybrid_threads(Config& config, const std::vector<std::vector<int>>& proc_type_table) {+ const int main_cores = proc_type_table[0][MAIN_CORE_PROC];+ const int efficient_cores = proc_type_table[0][EFFICIENT_CORE_PROC];++ config.modelPreferThreadsLatency = main_cores > 0 ? main_cores : efficient_cores;+}++void configure_x86_throughput_threads(Config& config,+ const std::vector<std::vector<int>>& proc_type_table,+ const ov::MemBandwidthPressure& tolerance,+ float memThresholdAssumeLimitedForISA) {+ config.modelPreferThreadsThroughput = 0;++ if (tolerance.max_mem_tolerance == ov::MemBandwidthPressure::UNKNOWN) {+ if (is_network_compute_limited(tolerance)) {+ config.modelPreferThreadsThroughput = 1;+ }+ } else if (is_below_isa_threshold(tolerance.max_mem_tolerance, memThresholdAssumeLimitedForISA)) {+ config.modelPreferThreadsThroughput = 1;+ } else if (is_below_general_threshold(tolerance.max_mem_tolerance)) {+ config.modelPreferThreadsThroughput = 2;+ }++ // Adjust for hyperthreading on non-hybrid systems+ if (config.modelPreferThreadsThroughput == 1 && proc_type_table[0][EFFICIENT_CORE_PROC] == 0 &&+ (proc_type_table[0][HYPER_THREADING_PROC] == proc_type_table[0][MAIN_CORE_PROC])) {+ config.modelPreferThreadsThroughput = 2;+ }+}+#endif++int get_model_prefer_threads(const int num_streams,+ const std::vector<std::vector<int>>& proc_type_table,+ const std::shared_ptr<ov::Model>& model,+ Config& config,+ int num_sockets,+ float isaSpecificThreshold) {+ if (num_sockets == -1) {+ num_sockets = get_num_sockets();+ }++ if (config.modelPreferThreads == -1) {+ const bool int8_intensive = ov::op::util::has_op_with_type<ov::op::v0::FakeQuantize>(model);+ const bool is_LLM = config.modelType != Config::ModelType::CNN;++ config.modelPreferThreads = 0;++#if defined(OPENVINO_ARCH_ARM64) && defined(__linux__)+ configure_arm64_linux_threads(config, proc_type_table, int8_intensive, is_LLM);+ (void)isaSpecificThreshold;#else- const auto isa = dnnl::get_effective_cpu_isa();- float isaSpecificThreshold = 1.0F;- switch (isa) {- case dnnl::cpu_isa::sse41:- isaSpecificThreshold = 0.5F;- break;- case dnnl::cpu_isa::avx2:- case dnnl::cpu_isa::avx512_core:- isaSpecificThreshold = 1.0F;- break;- case dnnl::cpu_isa::avx512_core_vnni:- case dnnl::cpu_isa::avx2_vnni:- case dnnl::cpu_isa::avx2_vnni_2:- isaSpecificThreshold = 2.0F;- break;- case dnnl::cpu_isa::avx512_core_amx:- isaSpecificThreshold = 4.0F;- break;- default:++ if (isaSpecificThreshold == -1) {+# if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64)+ isaSpecificThreshold = get_isa_threshold_multiplier(dnnl::get_effective_cpu_isa());+# elseisaSpecificThreshold = 1.0F;+# endif}- // the more "capable" the CPU in general, the more streams we may want to keep to keep it utilized+const float memThresholdAssumeLimitedForISA = ov::MemBandwidthPressure::LIMITED / isaSpecificThreshold;+# if defined(OPENVINO_ARCH_RISCV64)+ // oneDNN C++ API (dnnl::utils::get_cache_size) is not available on RISC-V;+ // use a fallback value for L2 cache size.+ const float L2_cache_size = 1.0F;+# elseconst float L2_cache_size = dnnl::utils::get_cache_size(2 /*level*/, true /*per core */);+# endifov::MemBandwidthPressure networkToleranceForLowCache =ov::mem_bandwidth_pressure_tolerance(model,L2_cache_size,memThresholdAssumeLimitedForISA,config.inferencePrecision);-# if (defined(OPENVINO_ARCH_ARM) && defined(__linux__))- config.modelPreferThreadsThroughput = 4;- if (networkToleranceForLowCache.max_mem_tolerance == ov::MemBandwidthPressure::UNKNOWN) {- if (networkToleranceForLowCache.ratio_compute_convs == ov::MemBandwidthPressure::ALL) {- config.modelPreferThreadsThroughput = 8;- }- } else if ((networkToleranceForLowCache.max_mem_tolerance < ov::MemBandwidthPressure::LIMITED) &&- ((networkToleranceForLowCache.ratio_mem_limited_deconvs > ov::MemBandwidthPressure::LIMITED) ||- (networkToleranceForLowCache.ratio_mem_limited_gemms > ov::MemBandwidthPressure::LIMITED))) {- config.modelPreferThreadsThroughput = 8;- }- default_prefer_threads_latency();--# elif ((defined(OPENVINO_ARCH_ARM) || defined(OPENVINO_ARCH_ARM64)) && defined(__APPLE__))- if ((proc_type_table.size() == 1) && (proc_type_table[0][EFFICIENT_CORE_PROC] > 0)) {- config.modelPreferThreadsLatency =- proc_type_table[0][MAIN_CORE_PROC] > proc_type_table[0][EFFICIENT_CORE_PROC]- ? proc_type_table[0][MAIN_CORE_PROC]- : proc_type_table[0][ALL_PROC];- } else {- default_prefer_threads_latency();- }- config.modelPreferThreadsThroughput = 1;- if (networkToleranceForLowCache.max_mem_tolerance == ov::MemBandwidthPressure::UNKNOWN) {- if ((networkToleranceForLowCache.ratio_compute_convs == ov::MemBandwidthPressure::ALL) ||- (networkToleranceForLowCache.ratio_compute_deconvs == ov::MemBandwidthPressure::ALL)) {- // all relevant layers (convs, etc) are compute-limited, the most aggressive val for #streams- config.modelPreferThreadsThroughput = 4;- } // otherwise (no recognized layers) falling back to the default value- } else if (networkToleranceForLowCache.max_mem_tolerance > memThresholdAssumeLimitedForISA) {- // network is below the ISA-specific threshold- config.modelPreferThreadsThroughput = 1;- } else if (networkToleranceForLowCache.max_mem_tolerance > ov::MemBandwidthPressure::LIMITED) {- // network is below general threshold- config.modelPreferThreadsThroughput = 1;- } else if (networkToleranceForLowCache.ratio_mem_limited_deconvs > ov::MemBandwidthPressure::LIMITED &&- networkToleranceForLowCache.ratio_compute_convs < ov::MemBandwidthPressure::ALL) {- config.modelPreferThreadsThroughput = 4;- } else if (networkToleranceForLowCache.ratio_mem_limited_deconvs <= ov::MemBandwidthPressure::LIMITED &&- networkToleranceForLowCache.ratio_mem_limited_convs <= ov::MemBandwidthPressure::LIMITED &&- networkToleranceForLowCache.ratio_compute_convs > ov::MemBandwidthPressure::LIMITED) {- config.modelPreferThreadsThroughput = 2;- }+# if defined(OPENVINO_ARCH_ARM) && defined(__linux__)+ configure_arm_linux_threads(config, proc_type_table, networkToleranceForLowCache, int8_intensive, is_LLM);++# elif (defined(OPENVINO_ARCH_ARM) || defined(OPENVINO_ARCH_ARM64)) && defined(__APPLE__)+ configure_apple_threads(config,+ proc_type_table,+ networkToleranceForLowCache,+ memThresholdAssumeLimitedForISA,+ int8_intensive,+ is_LLM);+# else- if (proc_type_table[0][EFFICIENT_CORE_PROC] > 0 && proc_type_table[0][MAIN_CORE_PROC] > 0) {- if ((proc_type_table[0][MAIN_CORE_PROC] < config.threads || config.threads == 0) &&- (ov::get_number_of_blocked_cores() || proc_type_table[0][LP_EFFICIENT_CORE_PROC] > 0) &&- proc_type_table[0][EFFICIENT_CORE_PROC] <= 2 * proc_type_table[0][MAIN_CORE_PROC]) {- if (is_LLM) {- config.modelPreferThreadsLatency = proc_type_table[0][MAIN_CORE_PROC];- } else {- config.modelPreferThreadsLatency =- proc_type_table[0][MAIN_CORE_PROC] + proc_type_table[0][EFFICIENT_CORE_PROC];- if (config.tbbPartitioner == TbbPartitioner::NONE) {- if (proc_type_table[0][LP_EFFICIENT_CORE_PROC] > 0 && int8_intensive &&- networkToleranceForLowCache.total_convs > 0) {- bool main_core_case_1 = networkToleranceForLowCache.ratio_mem_limited_convs > 0.8F;- bool main_core_case_2 = networkToleranceForLowCache.ratio_mem_limited_convs == 0.0F &&- networkToleranceForLowCache.ratio_compute_convs == 0.0F &&- networkToleranceForLowCache.max_mem_tolerance >= 4.5F;- bool main_core_case_3 =- networkToleranceForLowCache.ratio_mem_limited_convs == 0.0F &&- networkToleranceForLowCache.ratio_compute_convs > 0.0F &&- networkToleranceForLowCache.ratio_compute_convs < 1.0F &&- static_cast<float>(networkToleranceForLowCache.total_light_convs) >- 0.9F * static_cast<float>(networkToleranceForLowCache.total_convs);- bool main_core_case_4 =- networkToleranceForLowCache.ratio_mem_limited_convs > 0.0F &&- networkToleranceForLowCache.ratio_compute_convs > 0.0F &&- static_cast<float>(networkToleranceForLowCache.total_light_convs) >- 0.46F * static_cast<float>(networkToleranceForLowCache.total_convs);- if (main_core_case_1 || main_core_case_2 || main_core_case_3 || main_core_case_4) {- config.modelPreferThreadsLatency = proc_type_table[0][MAIN_CORE_PROC];- config.tbbPartitioner = TbbPartitioner::STATIC;- }- }- if (config.tbbPartitioner == TbbPartitioner::NONE) {- bool static_case_1 = networkToleranceForLowCache.total_nodes == 0;- bool static_case_2 = networkToleranceForLowCache.total_convs > 0 &&- static_cast<float>(networkToleranceForLowCache.total_light_convs) >- 0.6F * static_cast<float>(networkToleranceForLowCache.total_convs);- bool static_case_3 = false;- bool static_case_4 = false;- bool static_case_5 = false;- if (proc_type_table[0][LP_EFFICIENT_CORE_PROC] > 0) {- static_case_3 =- networkToleranceForLowCache.total_convs > 0 &&- static_cast<float>(networkToleranceForLowCache.total_light_convs) <=- 0.6F * static_cast<float>(networkToleranceForLowCache.total_convs) &&- networkToleranceForLowCache.ratio_compute_convs +- networkToleranceForLowCache.ratio_mem_limited_convs <- 0.9F &&- networkToleranceForLowCache.ratio_mem_limited_convs < 0.2F &&- networkToleranceForLowCache.ratio_mem_limited_gemms == 0.0F &&- ((networkToleranceForLowCache.ratio_mem_limited_adds < 0.28F &&- networkToleranceForLowCache.max_mem_tolerance >= 0.06F) ||- networkToleranceForLowCache.ratio_compute_convs == 0 ||- networkToleranceForLowCache.ratio_mem_limited_convs == 0);- static_case_4 =- networkToleranceForLowCache.total_convs == 0 &&- (networkToleranceForLowCache.max_mem_tolerance > 2.5F ||- static_cast<float>(networkToleranceForLowCache.total_gemms) >=- 0.14F * static_cast<float>(networkToleranceForLowCache.total_nodes));- static_case_5 =- networkToleranceForLowCache.total_convs > 0 &&- static_cast<float>(networkToleranceForLowCache.total_light_convs) <=- 0.6F * static_cast<float>(networkToleranceForLowCache.total_convs) &&- networkToleranceForLowCache.ratio_compute_convs >=- 0.9F * networkToleranceForLowCache.ratio_mem_limited_convs &&- networkToleranceForLowCache.ratio_compute_convs == 1.0F &&- networkToleranceForLowCache.ratio_mem_limited_adds == 1.0F &&- static_cast<float>(networkToleranceForLowCache.total_heavy_convs) >- 0.1F * static_cast<float>(networkToleranceForLowCache.total_nodes);- } else {- static_case_3 =- networkToleranceForLowCache.total_convs > 0 &&- static_cast<float>(networkToleranceForLowCache.total_light_convs) <=- 0.6F * static_cast<float>(networkToleranceForLowCache.total_convs) &&- networkToleranceForLowCache.ratio_compute_convs +- networkToleranceForLowCache.ratio_mem_limited_convs <- 0.9F &&- networkToleranceForLowCache.ratio_mem_limited_convs < 0.2F &&- networkToleranceForLowCache.ratio_mem_limited_gemms == 0.0F &&- networkToleranceForLowCache.ratio_mem_limited_adds < 0.28F &&- networkToleranceForLowCache.max_mem_tolerance >= 0.06F;- static_case_4 = networkToleranceForLowCache.total_convs == 0 &&- static_cast<float>(networkToleranceForLowCache.total_gemms) <- 0.05F * static_cast<float>(networkToleranceForLowCache.total_nodes);- }- if (static_case_1 || static_case_2 || static_case_3 || static_case_4 || static_case_5) {- config.tbbPartitioner = TbbPartitioner::STATIC;- } else {- config.tbbPartitioner = TbbPartitioner::AUTO;- }- }- }- }- } else {- default_prefer_threads_latency();- }+# if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64) || defined(OPENVINO_ARCH_RISCV64)+ const int main_cores = proc_type_table[0][MAIN_CORE_PROC];+ const int efficient_cores = proc_type_table[0][EFFICIENT_CORE_PROC];+ const int lp_efficient_cores = proc_type_table[0][LP_EFFICIENT_CORE_PROC];++ if (efficient_cores > 0 && main_cores > 0) {+ configure_x86_hybrid_threads(config, proc_type_table, networkToleranceForLowCache, int8_intensive, is_LLM);+ } else if (efficient_cores == 0 && main_cores * 2 <= lp_efficient_cores) {+ configure_x86_hybrid_lp_threads(config, proc_type_table, networkToleranceForLowCache);} else {- config.modelPreferThreadsLatency = proc_type_table[0][MAIN_CORE_PROC] > 0- ? proc_type_table[0][MAIN_CORE_PROC]- : proc_type_table[0][EFFICIENT_CORE_PROC];- }- config.modelPreferThreadsThroughput = 0;- if (networkToleranceForLowCache.max_mem_tolerance == ov::MemBandwidthPressure::UNKNOWN) {- if (any_of(ov::MemBandwidthPressure::ALL,- networkToleranceForLowCache.ratio_compute_convs,- networkToleranceForLowCache.ratio_compute_deconvs)) {- // all relevant layers (convs, etc) are compute-limited, the most aggressive val for #streams- config.modelPreferThreadsThroughput = 1;- } // otherwise (no recognized layers) falling back to the default value- } else if (networkToleranceForLowCache.max_mem_tolerance > memThresholdAssumeLimitedForISA) {- // network is below the ISA-specific threshold- config.modelPreferThreadsThroughput = 1;- } else if (networkToleranceForLowCache.max_mem_tolerance > ov::MemBandwidthPressure::LIMITED) {- // network is below general threshold- config.modelPreferThreadsThroughput = 2;- }- if (config.modelPreferThreadsThroughput == 1 && proc_type_table[0][EFFICIENT_CORE_PROC] == 0 &&- (proc_type_table[0][HYPER_THREADING_PROC] == proc_type_table[0][MAIN_CORE_PROC])) {- config.modelPreferThreadsThroughput = 2;+ configure_x86_non_hybrid_threads(config, proc_type_table);}+# endif++ configure_x86_throughput_threads(config,+ proc_type_table,+ networkToleranceForLowCache,+ memThresholdAssumeLimitedForISA);# endif#endif}- if (num_streams > sockets || num_streams == 0) {+ if (num_streams > num_sockets || num_streams == 0) {config.modelPreferThreads = config.modelPreferThreadsThroughput;} else {config.modelPreferThreads = config.modelPreferThreadsLatency;diff --git a/src/plugins/intel_cpu/src/cpu_streams_calculation.hpp b/src/plugins/intel_cpu/src/cpu_streams_calculation.hppindex b9f391e0d22..2f9e45c1669 100644--- a/src/plugins/intel_cpu/src/cpu_streams_calculation.hpp+++ b/src/plugins/intel_cpu/src/cpu_streams_calculation.hpp@@ -16,6 +16,7 @@#include "config.h"#include "openvino/core/model.hpp"+#include "openvino/runtime/performance_heuristics.hpp"#include "openvino/runtime/properties.hpp"namespace ov::intel_cpu {@@ -41,7 +42,7 @@ namespace ov::intel_cpu {* @param[in] input_perf_hint is performance hint set by user via ov::hint::performance_mode or the default value.* @param[in] hint_llm_distribution_policy is the distribution policy for Large language models* @param[in] proc_type_table is currently available candidate processors.- * - candidate processors have benn updated based on user input hints like ov::hint::scheduling_core_type+ * - candidate processors have been updated based on user input hints like ov::hint::scheduling_core_type* in previous function.* @return streams information table which will be used by StreamsExecutor.*/@@ -73,15 +74,19 @@ std::vector<std::vector<int>> get_streams_rank_table(const std::vector<std::vect* - input "0" mean function generate the optimal number of streams* - LATENCY hint equals 1 stream.* @param[in] proc_type_table candidate processors available at this time- * - candidate processors have benn updated based on properties like "Ecore only" in previous function+ * - candidate processors have been updated based on properties like "Ecore only" in previous function* @param[in] model model* @param[in] config intel cpu configuration+ * @param[in] num_sockets number of sockets for test case+ * @param[in] isaSpecificThreshold ISA parameter for test case* @return model_prefer_threads "0" means generating the optimal threads per stream based on platform*/int get_model_prefer_threads(int num_streams,const std::vector<std::vector<int>>& proc_type_table,const std::shared_ptr<ov::Model>& model,- Config& config);+ Config& config,+ int num_sockets = -1,+ float isaSpecificThreshold = -1.0F);/*** @brief Generate streams information according to processors type table@@ -92,7 +97,7 @@ int get_model_prefer_threads(int num_streams,* @param[in] config intel cpu configuration* @param[in] proc_type_table candidate processors available at current platform* @param[in] preferred_nthreads_per_stream is initial preferred number of threads per stream- * @return candidate processors have benn updated based on user input hints like ov::hint::scheduling_core_type and+ * @return candidate processors have been updated based on user input hints like ov::hint::scheduling_core_type and* ov::hint::enable_hyper_threading*/std::vector<std::vector<int>> generate_stream_info(int streams,@@ -117,4 +122,44 @@ void get_num_streams(int streams, const std::shared_ptr<ov::Model>& model, Confi* @param[in] proc_type_table summary table of number of processors per type*/void sort_table_by_numa_node_id(int current_numa_node, std::vector<std::vector<int>>& proc_type_table);++// Internal configure_* helpers are declared below and are publicly callable.+#if defined(OPENVINO_ARCH_ARM) && defined(__linux__)+void configure_arm_linux_threads(Config& config,+ const std::vector<std::vector<int>>& proc_type_table,+ const ov::MemBandwidthPressure& tolerance,+ bool int8_intensive,+ bool is_LLM);+#endif++#if (defined(OPENVINO_ARCH_ARM) || defined(OPENVINO_ARCH_ARM64)) && defined(__APPLE__)+void configure_apple_threads(Config& config,+ const std::vector<std::vector<int>>& proc_type_table,+ const ov::MemBandwidthPressure& tolerance,+ float memThresholdAssumeLimitedForISA,+ bool int8_intensive,+ bool is_LLM);+#endif++#if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64) || defined(OPENVINO_ARCH_RISCV64)+// Make internal hybrid configuration helper publicly callable+void configure_x86_hybrid_threads(Config& config,+ const std::vector<std::vector<int>>& proc_type_table,+ const ov::MemBandwidthPressure& tolerance,+ bool int8_intensive,+ bool is_LLM);++void configure_x86_hybrid_lp_threads(Config& config,+ const std::vector<std::vector<int>>& proc_type_table,+ const ov::MemBandwidthPressure& tolerance);++// Make x86 non-hybrid helper publicly callable+void configure_x86_non_hybrid_threads(Config& config, const std::vector<std::vector<int>>& proc_type_table);++// Make x86 throughput helper publicly callable+void configure_x86_throughput_threads(Config& config,+ const std::vector<std::vector<int>>& proc_type_table,+ const ov::MemBandwidthPressure& tolerance,+ float memThresholdAssumeLimitedForISA);+#endif} // namespace ov::intel_cpudiff --git a/src/plugins/intel_cpu/tests/unit/streams_info/model_prefer_threads.cpp b/src/plugins/intel_cpu/tests/unit/streams_info/model_prefer_threads.cppnew file mode 100644index 00000000000..1c4ce4f140f--- /dev/null+++ b/src/plugins/intel_cpu/tests/unit/streams_info/model_prefer_threads.cpp@@ -0,0 +1,419 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include <gtest/gtest.h>++#include <memory>++#include "common_test_utils/test_common.hpp"+#include "cpu_streams_calculation.hpp"+#include "openvino/opsets/opset8.hpp"+#include "openvino/runtime/performance_heuristics.hpp"+#include "openvino/runtime/threading/cpu_streams_info.hpp"++using namespace testing;+using namespace ov;+using namespace ov::intel_cpu;++#if defined(OPENVINO_ARCH_ARM) && defined(__linux__)+using ov::intel_cpu::configure_arm_linux_threads;+#endif+#if (defined(OPENVINO_ARCH_ARM) || defined(OPENVINO_ARCH_ARM64)) && defined(__APPLE__)+using ov::intel_cpu::configure_apple_threads;+#endif+#if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64) || defined(OPENVINO_ARCH_RISCV64)+using ov::intel_cpu::configure_x86_hybrid_threads;+using ov::intel_cpu::configure_x86_non_hybrid_threads;+using ov::intel_cpu::configure_x86_throughput_threads;+#endif++namespace {++static std::shared_ptr<ov::Model> make_dummy_model(bool with_fakequantize = false) {+ using namespace ov::opset8;+ auto input = std::make_shared<Parameter>(ov::element::f32, ov::Shape{1, 3, 16, 16});+ std::shared_ptr<ov::Node> data = input;+ if (with_fakequantize) {+ auto fq = std::make_shared<FakeQuantize>(+ data,+ std::make_shared<Constant>(ov::element::f32, ov::Shape{1}, std::vector<float>{0}),+ std::make_shared<Constant>(ov::element::f32, ov::Shape{1}, std::vector<float>{1}),+ std::make_shared<Constant>(ov::element::f32, ov::Shape{1}, std::vector<float>{0}),+ std::make_shared<Constant>(ov::element::f32, ov::Shape{1}, std::vector<float>{1}),+ 256);+ data = fq;+ }+ auto weights =+ std::make_shared<Constant>(ov::element::f32, ov::Shape{8, 3, 3, 3}, std::vector<float>(8 * 3 * 3 * 3, 1.0f));+ auto conv = std::make_shared<Convolution>(data,+ weights,+ ov::Strides{1, 1},+ ov::CoordinateDiff{0, 0},+ ov::CoordinateDiff{0, 0},+ ov::Strides{1, 1});+ auto result = std::make_shared<Result>(conv);+ return std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input});+}++class ModelPreferThreadsIntegrationTest : public ov::test::TestsCommon {};++TEST_F(ModelPreferThreadsIntegrationTest, int8_model_use_all_cores) {+ std::vector<std::vector<int>> proc_type_table = {{10, 2, 8, 0, 0, 0, 0}};+ auto model = make_dummy_model(true);+ Config config;+ config.modelType = Config::ModelType::CNN;+ config.modelPreferThreads = -1;+ int num_streams = 1;+ int num_sockets = proc_type_table.size() == 1 ? 1 : proc_type_table.size() - 1;+ float isaSpecificThreshold = 2.0f;+ int result =+ get_model_prefer_threads(num_streams, proc_type_table, model, config, num_sockets, isaSpecificThreshold);+ EXPECT_GE(config.modelPreferThreadsLatency, 10);+ EXPECT_EQ(result, config.modelPreferThreadsLatency);+}++TEST_F(ModelPreferThreadsIntegrationTest, llm_model_ecores_ratio) {+ std::vector<std::vector<int>> proc_type_table = {{14, 4, 10, 0, 0, 0, 0}};+ auto model = make_dummy_model();+ Config config;+ config.modelType = Config::ModelType::LLM;+ config.modelPreferThreads = -1;+ int num_streams = 1;+ int num_sockets = proc_type_table.size() == 1 ? 1 : proc_type_table.size() - 1;+ float isaSpecificThreshold = 2.0f;+ int result =+ get_model_prefer_threads(num_streams, proc_type_table, model, config, num_sockets, isaSpecificThreshold);+ EXPECT_GE(config.modelPreferThreadsLatency, 14);+ EXPECT_EQ(result, config.modelPreferThreadsLatency);+}++TEST_F(ModelPreferThreadsIntegrationTest, zero_cores_edge_case) {+ std::vector<std::vector<int>> proc_type_table = {{0, 0, 0, 0, 0, 0, 0}};+ auto model = make_dummy_model();+ Config config;+ config.modelType = Config::ModelType::CNN;+ config.modelPreferThreads = -1;+ int num_streams = 1;+ int num_sockets = proc_type_table.size() == 1 ? 1 : proc_type_table.size() - 1;+ float isaSpecificThreshold = 2.0f;+ int result =+ get_model_prefer_threads(num_streams, proc_type_table, model, config, num_sockets, isaSpecificThreshold);+ EXPECT_EQ(config.modelPreferThreadsLatency, 0);+ EXPECT_EQ(result, 0);+}++TEST_F(ModelPreferThreadsIntegrationTest, unknown_memtolerance_edge_case) {+ std::vector<std::vector<int>> proc_type_table = {{8, 8, 0, 0, 0, 0, 0}};+ auto model = make_dummy_model();+ Config config;+ config.modelType = Config::ModelType::CNN;+ config.modelPreferThreads = -1;+ int num_streams = 0;+ int num_sockets = proc_type_table.size() == 1 ? 1 : proc_type_table.size() - 1;+ float isaSpecificThreshold = 2.0f;+ int result =+ get_model_prefer_threads(num_streams, proc_type_table, model, config, num_sockets, isaSpecificThreshold);+ EXPECT_GE(config.modelPreferThreadsThroughput, 1);+ EXPECT_EQ(result, config.modelPreferThreadsThroughput);+}++#if defined(OPENVINO_ARCH_ARM64) && defined(__linux__)+TEST_F(ModelPreferThreadsIntegrationTest, arm64_linux_default_threads) {+ std::vector<std::vector<int>> proc_type_table = {{8, 8, 0, 0, 0, 0, 0}};+ auto model = make_dummy_model();+ Config config;+ config.modelType = Config::ModelType::CNN;+ config.modelPreferThreads = -1;+ int num_streams = 1;+ int result = get_model_prefer_threads(num_streams, proc_type_table, model, config, 1, 1.0f);+ EXPECT_EQ(config.modelPreferThreadsLatency, 8);+ EXPECT_EQ(result, config.modelPreferThreadsLatency);+}+#endif++TEST_F(ModelPreferThreadsIntegrationTest, num_streams_vs_sockets_boundary) {+ std::vector<std::vector<int>> proc_type_table = {{8, 8, 0, 0, 0, 0, 0}};+ auto model = make_dummy_model();+ Config config;+ config.modelType = Config::ModelType::CNN;+ config.modelPreferThreads = -1;+ // num_streams <= num_sockets -> latency path+ int num_sockets = proc_type_table.size() == 1 ? 1 : proc_type_table.size() - 1;+ float isaSpecificThreshold = 2.0f;+ int result = get_model_prefer_threads(1, proc_type_table, model, config, num_sockets, isaSpecificThreshold);+ EXPECT_EQ(result, config.modelPreferThreadsLatency);++ // num_streams > num_sockets -> throughput path+ result = get_model_prefer_threads(2, proc_type_table, model, config, num_sockets, isaSpecificThreshold);+ EXPECT_EQ(result, config.modelPreferThreadsThroughput);++ // num_streams == 0 -> throughput path regardless of num_sockets+ result = get_model_prefer_threads(0, proc_type_table, model, config, num_sockets, isaSpecificThreshold);+ EXPECT_EQ(result, config.modelPreferThreadsThroughput);+}++TEST_F(ModelPreferThreadsIntegrationTest, isaspecificthreshold_default_and_custom_coverage) {+ std::vector<std::vector<int>> proc_type_table = {{8, 8, 0, 0, 0, 0, 0}};+ auto model = make_dummy_model();++ Config default_isa_config;+ default_isa_config.modelType = Config::ModelType::CNN;+ default_isa_config.modelPreferThreads = -1;+ int result_default = get_model_prefer_threads(0, proc_type_table, model, default_isa_config, 1, -1.0f);+ EXPECT_EQ(result_default, default_isa_config.modelPreferThreadsThroughput);++ Config custom_isa_config_low;+ custom_isa_config_low.modelType = Config::ModelType::CNN;+ custom_isa_config_low.modelPreferThreads = -1;+ int result_isa_low = get_model_prefer_threads(0, proc_type_table, model, custom_isa_config_low, 1, 1.0f);+ EXPECT_EQ(result_isa_low, custom_isa_config_low.modelPreferThreadsThroughput);++ Config custom_isa_config_high;+ custom_isa_config_high.modelType = Config::ModelType::CNN;+ custom_isa_config_high.modelPreferThreads = -1;+ int result_isa_high = get_model_prefer_threads(0, proc_type_table, model, custom_isa_config_high, 1, 2.0f);+ EXPECT_EQ(result_isa_high, custom_isa_config_high.modelPreferThreadsThroughput);++ // Higher ISA threshold factor should not increase preferred throughput threads.+ EXPECT_LE(custom_isa_config_high.modelPreferThreadsThroughput, custom_isa_config_low.modelPreferThreadsThroughput);+}++TEST_F(ModelPreferThreadsIntegrationTest, num_sockets_default_and_custom_coverage) {+ std::vector<std::vector<int>> proc_type_table = {{8, 8, 0, 0, 0, 0, 0}};+ auto model = make_dummy_model();++ Config default_socket_config;+ default_socket_config.modelType = Config::ModelType::CNN;+ default_socket_config.modelPreferThreads = -1;+ int num_sockets = proc_type_table.size() == 1 ? 1 : proc_type_table.size() - 1;+ float isaSpecificThreshold = 2.0f;+ int result_default_socket =+ get_model_prefer_threads(1, proc_type_table, model, default_socket_config, num_sockets, isaSpecificThreshold);+ EXPECT_EQ(result_default_socket, default_socket_config.modelPreferThreadsLatency);++ Config custom_socket_config;+ custom_socket_config.modelType = Config::ModelType::CNN;+ custom_socket_config.modelPreferThreads = -1;+ int result_custom_socket =+ get_model_prefer_threads(2, proc_type_table, model, custom_socket_config, num_sockets, isaSpecificThreshold);+ EXPECT_EQ(result_custom_socket, custom_socket_config.modelPreferThreadsThroughput);+}++#if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64)++TEST_F(ModelPreferThreadsIntegrationTest, direct_x86_non_hybrid_zero_main) {+ Config config;+ std::vector<std::vector<int>> proc_type_table = {{4, 0, 4, 0, 0, 0, 0}};+ configure_x86_non_hybrid_threads(config, proc_type_table);+ EXPECT_EQ(config.modelPreferThreadsLatency, 4);+}++TEST_F(ModelPreferThreadsIntegrationTest, direct_x86_hybrid_llm_main_only) {+ Config config;+ std::vector<std::vector<int>> proc_type_table = {{13, 4, 8, 1, 0, 0, 0}};+ ov::MemBandwidthPressure tolerance;+ configure_x86_hybrid_threads(config, proc_type_table, tolerance, false, true);+ EXPECT_EQ(config.modelPreferThreadsLatency, 4);+}++TEST_F(ModelPreferThreadsIntegrationTest, direct_x86_hybrid_fallback_use_all) {+ Config config;+ config.threads = 0;+ std::vector<std::vector<int>> proc_type_table = {{12, 4, 8, 0, 0, 0, 0}};+ ov::MemBandwidthPressure tolerance;+ configure_x86_hybrid_threads(config, proc_type_table, tolerance, false, false);+ EXPECT_EQ(config.modelPreferThreadsLatency, 12);+}++TEST_F(ModelPreferThreadsIntegrationTest, direct_x86_throughput_ht_adjustment) {+ Config config;+ std::vector<std::vector<int>> proc_type_table = {{16, 8, 0, 0, 8, 0, 0}};+ ov::MemBandwidthPressure tolerance;+ tolerance.max_mem_tolerance = ov::MemBandwidthPressure::UNKNOWN;+ tolerance.ratio_compute_convs = ov::MemBandwidthPressure::ALL;++ configure_x86_throughput_threads(config, proc_type_table, tolerance, 1.0f);+ EXPECT_GE(config.modelPreferThreadsThroughput, 1);+}++TEST_F(ModelPreferThreadsIntegrationTest, direct_x86_hybrid_lp_auto_case) {+ Config config;+ std::vector<std::vector<int>> proc_type_table = {{12, 4, 0, 8, 0, 0, 0}};+ ov::MemBandwidthPressure tolerance;+ tolerance.max_mem_tolerance = 0.08f;+ tolerance.total_light_convs = 11;++ configure_x86_hybrid_lp_threads(config, proc_type_table, tolerance);+ EXPECT_EQ(config.modelPreferThreadsLatency, 12);+}++TEST_F(ModelPreferThreadsIntegrationTest, x86_non_hybrid_zero_main_use_efficient) {+ std::vector<std::vector<int>> proc_type_table = {{4, 0, 4, 0, 0, 0, 0}};+ auto model = make_dummy_model();+ Config config;+ config.modelType = Config::ModelType::CNN;+ config.modelPreferThreads = -1;+ int num_streams = 1;+ int num_sockets = proc_type_table.size() == 1 ? 1 : proc_type_table.size() - 1;+ float isaSpecificThreshold = 2.0f;+ int result =+ get_model_prefer_threads(num_streams, proc_type_table, model, config, num_sockets, isaSpecificThreshold);+ EXPECT_EQ(config.modelPreferThreadsLatency, 4);+ EXPECT_EQ(result, 4);+}++TEST_F(ModelPreferThreadsIntegrationTest, x86_hybrid_applicable_is_llm_main_only) {+ std::vector<std::vector<int>> proc_type_table = {{16, 4, 8, 4, 0, 0, 0}};+ auto model = make_dummy_model();+ Config config;+ config.modelType = Config::ModelType::LLM;+ config.modelPreferThreads = -1;+ int num_streams = 1;+ int num_sockets = proc_type_table.size() == 1 ? 1 : proc_type_table.size() - 1;+ float isaSpecificThreshold = 2.0f;+ int result =+ get_model_prefer_threads(num_streams, proc_type_table, model, config, num_sockets, isaSpecificThreshold);+ EXPECT_EQ(config.modelPreferThreadsLatency, 4);+ EXPECT_EQ(result, 4);+}++TEST_F(ModelPreferThreadsIntegrationTest, x86_hybrid_fallback_use_all_cores) {+ std::vector<std::vector<int>> proc_type_table = {{12, 4, 8, 0, 0, 0, 0}};+ auto model = make_dummy_model();+ Config config;+ config.modelType = Config::ModelType::CNN;+ config.threads = 1;+ config.modelPreferThreads = -1;+ int num_streams = 1;+ int num_sockets = proc_type_table.size() == 1 ? 1 : proc_type_table.size() - 1;+ float isaSpecificThreshold = 2.0f;+ int result =+ get_model_prefer_threads(num_streams, proc_type_table, model, config, num_sockets, isaSpecificThreshold);+ EXPECT_EQ(config.modelPreferThreadsLatency, 12);+ EXPECT_EQ(result, 12);+}++TEST_F(ModelPreferThreadsIntegrationTest, x86_throughput_hyper_threading_adjustment) {+ std::vector<std::vector<int>> proc_type_table = {{16, 8, 0, 0, 8, 0, 0}};+ auto model = make_dummy_model();+ Config config;+ config.modelType = Config::ModelType::CNN;+ config.modelPreferThreads = -1;+ int num_streams = 0;+ int num_sockets = proc_type_table.size() == 1 ? 1 : proc_type_table.size() - 1;+ float isaSpecificThreshold = 2.0f;+ int result =+ get_model_prefer_threads(num_streams, proc_type_table, model, config, num_sockets, isaSpecificThreshold);+ EXPECT_GE(config.modelPreferThreadsThroughput, 1);+ EXPECT_EQ(result, config.modelPreferThreadsThroughput);+}++TEST_F(ModelPreferThreadsIntegrationTest, x86_non_hybrid_main_cores_only) {+ std::vector<std::vector<int>> proc_type_table = {{8, 8, 0, 0, 0, 0, 0}};+ auto model = make_dummy_model();+ Config config;+ config.modelType = Config::ModelType::CNN;+ config.modelPreferThreads = -1;+ int num_streams = 1;+ int num_sockets = proc_type_table.size() == 1 ? 1 : proc_type_table.size() - 1;+ float isaSpecificThreshold = 2.0f;+ int result =+ get_model_prefer_threads(num_streams, proc_type_table, model, config, num_sockets, isaSpecificThreshold);+ EXPECT_EQ(config.modelPreferThreadsLatency, 8);+ EXPECT_EQ(result, config.modelPreferThreadsLatency);+}++TEST_F(ModelPreferThreadsIntegrationTest, x86_hybrid_int8_use_all_cores) {+ std::vector<std::vector<int>> proc_type_table = {{12, 4, 8, 0, 0, 0, 0}};+ auto model = make_dummy_model();+ Config config;+ config.modelType = Config::ModelType::CNN;+ config.modelPreferThreads = -1;+ int num_streams = 1;+ int num_sockets = proc_type_table.size() == 1 ? 1 : proc_type_table.size() - 1;+ float isaSpecificThreshold = 2.0f;+ int result =+ get_model_prefer_threads(num_streams, proc_type_table, model, config, num_sockets, isaSpecificThreshold);+ EXPECT_GE(config.modelPreferThreadsLatency, 12);+ EXPECT_EQ(result, config.modelPreferThreadsLatency);+}++TEST_F(ModelPreferThreadsIntegrationTest, x86_hybrid_fp32_main_cores_only) {+ std::vector<std::vector<int>> proc_type_table = {{8, 4, 4, 0, 0, 0, 0}};+ auto model = make_dummy_model();+ Config config;+ config.modelType = Config::ModelType::CNN;+ config.modelPreferThreads = -1;+ int num_streams = 1;+ int num_sockets = proc_type_table.size() == 1 ? 1 : proc_type_table.size() - 1;+ float isaSpecificThreshold = 2.0f;+ int result =+ get_model_prefer_threads(num_streams, proc_type_table, model, config, num_sockets, isaSpecificThreshold);+ EXPECT_EQ(config.modelPreferThreadsLatency, 4);+ EXPECT_EQ(result, config.modelPreferThreadsLatency);+}++#endif++#if defined(OPENVINO_ARCH_ARM) && defined(__linux__)+TEST_F(ModelPreferThreadsIntegrationTest, arm_linux_throughput_unknown_and_mem_limited) {+ std::vector<std::vector<int>> proc_type_table = {{8, 4, 4, 0, 0, 0, 0}};+ auto model = make_dummy_model();+ Config config;+ config.modelType = Config::ModelType::CNN;+ config.modelPreferThreads = -1;++ int result = get_model_prefer_threads(0, proc_type_table, model, config, 1, 2.0f);+ EXPECT_GE(config.modelPreferThreadsThroughput, 1);+ EXPECT_EQ(result, config.modelPreferThreadsThroughput);+}++TEST_F(ModelPreferThreadsIntegrationTest, direct_arm_linux_throughput_branches) {+ Config config;+ std::vector<std::vector<int>> proc_type_table = {{8, 4, 4, 0, 0, 0, 0}};+ ov::MemBandwidthPressure tolerance;+ // UNKNOWN should allow high throughput when compute-limited+ tolerance.max_mem_tolerance = ov::MemBandwidthPressure::UNKNOWN;+ configure_arm_linux_threads(config, proc_type_table, tolerance, false, false);+ EXPECT_GE(config.modelPreferThreadsThroughput, 1);+}+#endif++#if (defined(OPENVINO_ARCH_ARM) || defined(OPENVINO_ARCH_ARM64)) && defined(__APPLE__)+TEST_F(ModelPreferThreadsIntegrationTest, apple_size_one_special_latency_choice) {+ std::vector<std::vector<int>> proc_type_table = {{10, 6, 4, 0, 0, 0, 0}};+ auto model = make_dummy_model();+ Config config;+ config.modelType = Config::ModelType::CNN;+ config.modelPreferThreads = -1;+ int result = get_model_prefer_threads(1, proc_type_table, model, config, 1, 1.0f);+ EXPECT_EQ(config.modelPreferThreadsLatency, 6);+ EXPECT_EQ(result, 6);+}++TEST_F(ModelPreferThreadsIntegrationTest, apple_latency_and_throughput) {+ std::vector<std::vector<int>> proc_type_table = {{8, 4, 4, 0, 0, 0, 0}};+ auto model = make_dummy_model();+ Config config;+ config.modelType = Config::ModelType::CNN;+ config.modelPreferThreads = -1;+ int num_streams = 1;+ int result = get_model_prefer_threads(num_streams, proc_type_table, model, config, 1, 1.0f);+ EXPECT_GE(config.modelPreferThreadsLatency, 4);+ EXPECT_EQ(result, config.modelPreferThreadsLatency);+}++TEST_F(ModelPreferThreadsIntegrationTest, direct_apple_special_latency_and_throughput) {+ Config config;+ std::vector<std::vector<int>> proc_type_table = {{10, 6, 4, 0, 0, 0, 0}};+ ov::MemBandwidthPressure tolerance;+ float isaThreshold = 1.0f;+ configure_apple_threads(config, proc_type_table, tolerance, isaThreshold, false, false);+ // MAIN > EFFICIENT -> latency equals main+ EXPECT_EQ(config.modelPreferThreadsLatency, 6);+}++#endif++} // namespace\ No newline at end of filediff --git a/src/plugins/intel_cpu/tests/unit/streams_info/streams_info_table_test.cpp b/src/plugins/intel_cpu/tests/unit/streams_info/streams_info_table_test.cppindex ca03d826b12..0cef080e60a 100644--- a/src/plugins/intel_cpu/tests/unit/streams_info/streams_info_table_test.cpp+++ b/src/plugins/intel_cpu/tests/unit/streams_info/streams_info_table_test.cpp@@ -2510,6 +2510,43 @@ StreamsCalculationTestCase _1sockets_mock_latency_9 = {{0, EFFICIENT_CORE_PROC, 8, 0, 0},{0, LP_EFFICIENT_CORE_PROC, 4, 0, 0}},};+StreamsCalculationTestCase _1sockets_mock_latency_10 = {+ 1,+ false,+ 0,+ 0,+ 2,+ "LATENCY",+ {},+ {{6, 2, 0, 4, 0, 0, 0}},+ {{1, MAIN_CORE_PROC, 2, 0, 0}},+};+StreamsCalculationTestCase _1sockets_mock_latency_11 = {+ 1,+ false,+ 0,+ 0,+ 6,+ "LATENCY",+ {},+ {{6, 2, 0, 4, 0, 0, 0}},+ {{1, ALL_PROC, 6, 0, 0},+ {0, MAIN_CORE_PROC, 2, 0, 0},+ {0, LP_EFFICIENT_CORE_PROC, 4, 0, 0}},+};+StreamsCalculationTestCase _1sockets_mock_latency_12 = {+ 1,+ false,+ 4,+ 0,+ 6,+ "LATENCY",+ {},+ {{6, 2, 0, 4, 0, 0, 0}},+ {{1, ALL_PROC, 4, 0, 0},+ {0, MAIN_CORE_PROC, 2, 0, 0},+ {0, LP_EFFICIENT_CORE_PROC, 2, 0, 0}},+};StreamsCalculationTestCase _2sockets_mock_latency_35 = {1,false,@@ -3026,6 +3063,9 @@ INSTANTIATE_TEST_SUITE_P(StreamsInfoTable,_1sockets_mock_latency_7,_1sockets_mock_latency_8,_1sockets_mock_latency_9,+ _1sockets_mock_latency_10,+ _1sockets_mock_latency_11,+ _1sockets_mock_latency_12,_1sockets_mock_TP_1,_1sockets_mock_TP_2));