Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[CPU] Enable CPU pinning on windows in multiple sockets machine (#29283)

Sun Xiaoxiab69ec1ccb431
diff --git a/src/inference/dev_api/openvino/runtime/system_conf.hpp b/src/inference/dev_api/openvino/runtime/system_conf.hpp
index 882c46510cd..dad585183cd 100644
--- a/src/inference/dev_api/openvino/runtime/system_conf.hpp
+++ b/src/inference/dev_api/openvino/runtime/system_conf.hpp
@@ -188,6 +188,13 @@ OPENVINO_RUNTIME_API int get_num_numa_nodes();
*/
OPENVINO_RUNTIME_API int get_num_sockets();
+/**
+ * @brief Get numa node id of cpu_id
+ * @ingroup ov_dev_api_system_conf
+ * @return Numa node id
+ */
+OPENVINO_RUNTIME_API int get_numa_node_id(int cpu_id);
+
/**
* @brief Returns a table of number of processor types on Linux/Windows
* @ingroup ov_dev_api_system_conf
diff --git a/src/inference/src/dev/threading/cpu_streams_executor_internal.cpp b/src/inference/src/dev/threading/cpu_streams_executor_internal.cpp
index 3bd06f1f16a..a1d690e7019 100644
--- a/src/inference/src/dev/threading/cpu_streams_executor_internal.cpp
+++ b/src/inference/src/dev/threading/cpu_streams_executor_internal.cpp
@@ -57,10 +57,6 @@ void get_cur_stream_info(const int stream_id,
#if defined(__APPLE__)
pinning = false;
-#elif defined(_WIN32)
- if (proc_type_table.size() > 1) {
- pinning = false;
- }
#endif
if (pinning) {
stream_type = STREAM_WITH_OBSERVE;
diff --git a/src/inference/src/dev/threading/thread_affinity.cpp b/src/inference/src/dev/threading/thread_affinity.cpp
index 326e0d5ba1b..d96a4dcaee4 100644
--- a/src/inference/src/dev/threading/thread_affinity.cpp
+++ b/src/inference/src/dev/threading/thread_affinity.cpp
@@ -126,7 +126,19 @@ bool pin_thread_to_vacant_core(int thrIdx,
int ncores,
const CpuSet& procMask,
const std::vector<int>& cpu_ids) {
- return 0 != SetThreadAffinityMask(GetCurrentThread(), DWORD_PTR(1) << cpu_ids[thrIdx]);
+ auto proc_type_table = get_proc_type_table();
+ if (proc_type_table.size() > 1) {
+ int cores_in_numa = proc_type_table[1][MAIN_CORE_PROC] + proc_type_table[1][HYPER_THREADING_PROC];
+ GROUP_AFFINITY group;
+ group.Group = get_numa_node_id(cpu_ids[thrIdx]);
+ group.Mask = DWORD_PTR(1) << (cpu_ids[thrIdx] % cores_in_numa);
+ group.Reserved[0] = 0;
+ group.Reserved[1] = 0;
+ group.Reserved[2] = 0;
+ return 0 != SetThreadGroupAffinity(GetCurrentThread(), &group, NULL);
+ } else {
+ return 0 != SetThreadAffinityMask(GetCurrentThread(), DWORD_PTR(1) << cpu_ids[thrIdx]);
+ }
}
bool pin_current_thread_by_mask(int ncores, const CpuSet& procMask) {
DWORD_PTR mask = *procMask.get();
diff --git a/src/inference/src/system_conf.cpp b/src/inference/src/system_conf.cpp
index ec2dc8b4909..9149b86eb9c 100644
--- a/src/inference/src/system_conf.cpp
+++ b/src/inference/src/system_conf.cpp
@@ -277,6 +277,9 @@ int get_num_numa_nodes() {
int get_num_sockets() {
return -1;
}
+int get_numa_node_id(int cpu_id) {
+ return -1;
+}
void reserve_available_cpus(const std::vector<std::vector<int>> streams_info_table,
std::vector<std::vector<int>>& stream_processors,
const int cpu_status) {}
@@ -335,6 +338,9 @@ int get_num_numa_nodes() {
int get_num_sockets() {
return cpu_info()._sockets;
}
+int get_numa_node_id(int cpu_id) {
+ return -1;
+}
void reserve_available_cpus(const std::vector<std::vector<int>> streams_info_table,
std::vector<std::vector<int>>& stream_processors,
const int cpu_status) {}
@@ -459,6 +465,11 @@ int get_num_sockets() {
return cpu_info()._sockets;
}
+int get_numa_node_id(int cpu_id) {
+ CPU& cpu = cpu_info();
+ return cpu._cpu_mapping_table[cpu_id][CPU_MAP_NUMA_NODE_ID];
+}
+
void reserve_available_cpus(const std::vector<std::vector<int>> streams_info_table,
std::vector<std::vector<int>>& stream_processors,
const int cpu_status) {
diff --git a/src/inference/tests/unit/cpu_stream_info_test.cpp b/src/inference/tests/unit/cpu_stream_info_test.cpp
index 7b6fe01fc52..dfa3dfbb881 100644
--- a/src/inference/tests/unit/cpu_stream_info_test.cpp
+++ b/src/inference/tests/unit/cpu_stream_info_test.cpp
@@ -283,7 +283,6 @@ LinuxCpuStreamTypeCase _2sockets_72cores_binding_9streams = {
{1, ALL_PROC, 4, -1, -1},
{0, MAIN_CORE_PROC, 2, 0, 0},
{0, MAIN_CORE_PROC, 2, 1, 1}},
-# if defined(__linux__)
{
STREAM_WITH_OBSERVE,
STREAM_WITH_OBSERVE,
@@ -295,19 +294,6 @@ LinuxCpuStreamTypeCase _2sockets_72cores_binding_9streams = {
STREAM_WITH_OBSERVE,
STREAM_WITH_OBSERVE,
},
-# else
- {
- STREAM_WITH_NUMA_ID,
- STREAM_WITH_NUMA_ID,
- STREAM_WITH_NUMA_ID,
- STREAM_WITH_NUMA_ID,
- STREAM_WITH_NUMA_ID,
- STREAM_WITH_NUMA_ID,
- STREAM_WITH_NUMA_ID,
- STREAM_WITH_NUMA_ID,
- STREAM_WITHOUT_PARAM,
- },
-# endif
{4, 4, 4, 4, 4, 4, 4, 4, 4},
{
MAIN_CORE_PROC,
diff --git a/src/plugins/intel_cpu/src/cpu_map_scheduling.cpp b/src/plugins/intel_cpu/src/cpu_map_scheduling.cpp
index 214ef88c720..6440028ba0b 100644
--- a/src/plugins/intel_cpu/src/cpu_map_scheduling.cpp
+++ b/src/plugins/intel_cpu/src/cpu_map_scheduling.cpp
@@ -78,12 +78,7 @@ bool check_cpu_pinning(const bool cpu_pinning,
#if defined(__APPLE__)
result_value = false;
#elif defined(_WIN32)
- auto proc_type_table = get_proc_type_table();
- if (proc_type_table.size() == 1) {
- result_value = cpu_pinning_changed ? cpu_pinning : cpu_reservation;
- } else {
- result_value = false;
- }
+ result_value = cpu_pinning_changed ? cpu_pinning : cpu_reservation;
#else
// The following code disables pinning in case stream contains both Pcore and Ecore
auto hyper_cores_in_stream = [&]() {
diff --git a/src/plugins/intel_cpu/tests/unit/streams_info/cpu_pinning_test.cpp b/src/plugins/intel_cpu/tests/unit/streams_info/cpu_pinning_test.cpp
index 472aa2d96a2..3ed2a5fd6ed 100644
--- a/src/plugins/intel_cpu/tests/unit/streams_info/cpu_pinning_test.cpp
+++ b/src/plugins/intel_cpu/tests/unit/streams_info/cpu_pinning_test.cpp
@@ -131,7 +131,7 @@ CpuPinningTestCase cpu_pinning_win_mock_set_true_2 = {
},
{{48, 48, 0, 0, -1, -1}, {24, 24, 0, 0, 0, 0}, {24, 24, 0, 0, 1, 1}},
{{1, MAIN_CORE_PROC, 24, 0, 0}},
- false,
+ true,
};
CpuPinningTestCase cpu_pinning_win_mock_set_false = {
false,