Skip to content

Commit 08c4195

Browse files
Fix the issue of cpu affinity mask changed on a NUMA machine with SEQ (#25455)
### Details: - *Fix the issue of cpu affinity mask changed on a NUMA machine with SEQ* ### Tickets: - *CVS-143272*
1 parent 2aea2e0 commit 08c4195

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

src/inference/src/dev/threading/cpu_streams_executor.cpp

+34-16
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,6 @@ struct CPUStreamsExecutor::Impl {
8989
});
9090
}
9191
}
92-
#elif OV_THREAD == OV_THREAD_SEQ
93-
auto proc_type_table = get_org_proc_type_table();
94-
if (get_num_numa_nodes() > 1) {
95-
pin_current_thread_to_socket(_numaNodeId);
96-
} else if (proc_type_table.size() == 1 && proc_type_table[0][EFFICIENT_CORE_PROC] == 0 &&
97-
_impl->_config.get_cpu_pinning()) {
98-
CpuSet processMask;
99-
int ncpus = 0;
100-
std::tie(processMask, ncpus) = get_process_mask();
101-
if (nullptr != processMask) {
102-
pin_thread_to_vacant_core(_streamId + _impl->_config.get_thread_binding_offset(),
103-
_impl->_config.get_thread_binding_step(),
104-
ncpus,
105-
processMask);
106-
}
107-
}
10892
#endif
10993
}
11094
~Stream() {
@@ -226,6 +210,9 @@ struct CPUStreamsExecutor::Impl {
226210
std::unique_ptr<custom::task_arena> _taskArena;
227211
std::unique_ptr<Observer> _observer;
228212
std::vector<int> _cpu_ids;
213+
#elif OV_THREAD == OV_THREAD_SEQ
214+
CpuSet _mask = nullptr;
215+
int _ncpus = 0;
229216
#endif
230217
};
231218
// if the thread is created by CPUStreamsExecutor, the Impl::Stream of the thread is stored by tbb Class
@@ -429,7 +416,38 @@ struct CPUStreamsExecutor::Impl {
429416
task();
430417
}
431418
#else
419+
pin_stream_to_cpus();
432420
task();
421+
unpin_stream_to_cpus();
422+
#endif
423+
}
424+
425+
void pin_stream_to_cpus() {
426+
#if OV_THREAD == OV_THREAD_SEQ
427+
if (_config.get_cpu_pinning()) {
428+
auto stream = _streams.local();
429+
auto proc_type_table = get_org_proc_type_table();
430+
std::tie(stream->_mask, stream->_ncpus) = get_process_mask();
431+
if (get_num_numa_nodes() > 1) {
432+
pin_current_thread_to_socket(stream->_numaNodeId);
433+
} else if (proc_type_table.size() == 1 && proc_type_table[0][EFFICIENT_CORE_PROC] == 0) {
434+
if (nullptr != stream->_mask) {
435+
pin_thread_to_vacant_core(stream->_streamId + _config.get_thread_binding_offset(),
436+
_config.get_thread_binding_step(),
437+
stream->_ncpus,
438+
stream->_mask);
439+
}
440+
}
441+
}
442+
#endif
443+
}
444+
445+
void unpin_stream_to_cpus() {
446+
#if OV_THREAD == OV_THREAD_SEQ
447+
auto stream = _streams.local();
448+
if (stream->_mask) {
449+
pin_current_thread_by_mask(stream->_ncpus, stream->_mask);
450+
}
433451
#endif
434452
}
435453

0 commit comments

Comments
 (0)