Skip to content

Commit 0aa98d7

Browse files
[CPU] Enable CPU pinning on windows in multiple sockets machine (#29283)
### Details: - *Enable CPU pinning on windows in multiple sockets machine* ### Tickets: - *CVS-163881*
1 parent d7c9986 commit 0aa98d7

File tree

7 files changed

+33
-26
lines changed

7 files changed

+33
-26
lines changed

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

+7
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@ OPENVINO_RUNTIME_API int get_num_numa_nodes();
188188
*/
189189
OPENVINO_RUNTIME_API int get_num_sockets();
190190

191+
/**
192+
* @brief Get numa node id of cpu_id
193+
* @ingroup ov_dev_api_system_conf
194+
* @return Numa node id
195+
*/
196+
OPENVINO_RUNTIME_API int get_numa_node_id(int cpu_id);
197+
191198
/**
192199
* @brief Returns a table of number of processor types on Linux/Windows
193200
* @ingroup ov_dev_api_system_conf

src/inference/src/dev/threading/cpu_streams_executor_internal.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ void get_cur_stream_info(const int stream_id,
5757

5858
#if defined(__APPLE__)
5959
pinning = false;
60-
#elif defined(_WIN32)
61-
if (proc_type_table.size() > 1) {
62-
pinning = false;
63-
}
6460
#endif
6561
if (pinning) {
6662
stream_type = STREAM_WITH_OBSERVE;

src/inference/src/dev/threading/thread_affinity.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,19 @@ bool pin_thread_to_vacant_core(int thrIdx,
126126
int ncores,
127127
const CpuSet& procMask,
128128
const std::vector<int>& cpu_ids) {
129-
return 0 != SetThreadAffinityMask(GetCurrentThread(), DWORD_PTR(1) << cpu_ids[thrIdx]);
129+
auto proc_type_table = get_proc_type_table();
130+
if (proc_type_table.size() > 1) {
131+
int cores_in_numa = proc_type_table[1][MAIN_CORE_PROC] + proc_type_table[1][HYPER_THREADING_PROC];
132+
GROUP_AFFINITY group;
133+
group.Group = get_numa_node_id(cpu_ids[thrIdx]);
134+
group.Mask = DWORD_PTR(1) << (cpu_ids[thrIdx] % cores_in_numa);
135+
group.Reserved[0] = 0;
136+
group.Reserved[1] = 0;
137+
group.Reserved[2] = 0;
138+
return 0 != SetThreadGroupAffinity(GetCurrentThread(), &group, NULL);
139+
} else {
140+
return 0 != SetThreadAffinityMask(GetCurrentThread(), DWORD_PTR(1) << cpu_ids[thrIdx]);
141+
}
130142
}
131143
bool pin_current_thread_by_mask(int ncores, const CpuSet& procMask) {
132144
DWORD_PTR mask = *procMask.get();

src/inference/src/system_conf.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ int get_num_numa_nodes() {
277277
int get_num_sockets() {
278278
return -1;
279279
}
280+
int get_numa_node_id(int cpu_id) {
281+
return -1;
282+
}
280283
void reserve_available_cpus(const std::vector<std::vector<int>> streams_info_table,
281284
std::vector<std::vector<int>>& stream_processors,
282285
const int cpu_status) {}
@@ -335,6 +338,9 @@ int get_num_numa_nodes() {
335338
int get_num_sockets() {
336339
return cpu_info()._sockets;
337340
}
341+
int get_numa_node_id(int cpu_id) {
342+
return -1;
343+
}
338344
void reserve_available_cpus(const std::vector<std::vector<int>> streams_info_table,
339345
std::vector<std::vector<int>>& stream_processors,
340346
const int cpu_status) {}
@@ -459,6 +465,11 @@ int get_num_sockets() {
459465
return cpu_info()._sockets;
460466
}
461467

468+
int get_numa_node_id(int cpu_id) {
469+
CPU& cpu = cpu_info();
470+
return cpu._cpu_mapping_table[cpu_id][CPU_MAP_NUMA_NODE_ID];
471+
}
472+
462473
void reserve_available_cpus(const std::vector<std::vector<int>> streams_info_table,
463474
std::vector<std::vector<int>>& stream_processors,
464475
const int cpu_status) {

src/inference/tests/unit/cpu_stream_info_test.cpp

-14
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ LinuxCpuStreamTypeCase _2sockets_72cores_binding_9streams = {
283283
{1, ALL_PROC, 4, -1, -1},
284284
{0, MAIN_CORE_PROC, 2, 0, 0},
285285
{0, MAIN_CORE_PROC, 2, 1, 1}},
286-
# if defined(__linux__)
287286
{
288287
STREAM_WITH_OBSERVE,
289288
STREAM_WITH_OBSERVE,
@@ -295,19 +294,6 @@ LinuxCpuStreamTypeCase _2sockets_72cores_binding_9streams = {
295294
STREAM_WITH_OBSERVE,
296295
STREAM_WITH_OBSERVE,
297296
},
298-
# else
299-
{
300-
STREAM_WITH_NUMA_ID,
301-
STREAM_WITH_NUMA_ID,
302-
STREAM_WITH_NUMA_ID,
303-
STREAM_WITH_NUMA_ID,
304-
STREAM_WITH_NUMA_ID,
305-
STREAM_WITH_NUMA_ID,
306-
STREAM_WITH_NUMA_ID,
307-
STREAM_WITH_NUMA_ID,
308-
STREAM_WITHOUT_PARAM,
309-
},
310-
# endif
311297
{4, 4, 4, 4, 4, 4, 4, 4, 4},
312298
{
313299
MAIN_CORE_PROC,

src/plugins/intel_cpu/src/cpu_map_scheduling.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,7 @@ bool check_cpu_pinning(const bool cpu_pinning,
7878
#if defined(__APPLE__)
7979
result_value = false;
8080
#elif defined(_WIN32)
81-
auto proc_type_table = get_proc_type_table();
82-
if (proc_type_table.size() == 1) {
83-
result_value = cpu_pinning_changed ? cpu_pinning : cpu_reservation;
84-
} else {
85-
result_value = false;
86-
}
81+
result_value = cpu_pinning_changed ? cpu_pinning : cpu_reservation;
8782
#else
8883
// The following code disables pinning in case stream contains both Pcore and Ecore
8984
auto hyper_cores_in_stream = [&]() {

src/plugins/intel_cpu/tests/unit/streams_info/cpu_pinning_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ CpuPinningTestCase cpu_pinning_win_mock_set_true_2 = {
131131
},
132132
{{48, 48, 0, 0, -1, -1}, {24, 24, 0, 0, 0, 0}, {24, 24, 0, 0, 1, 1}},
133133
{{1, MAIN_CORE_PROC, 24, 0, 0}},
134-
false,
134+
true,
135135
};
136136
CpuPinningTestCase cpu_pinning_win_mock_set_false = {
137137
false,

0 commit comments

Comments
 (0)