Skip to content

Commit 2659786

Browse files
Support machines with more than 1024 cores (#26303)
### Details: - *Because sizeof(cpu_set_t) is a fixed size of 128 bytes, that is the maximum CPU number is 1023. So `sched_getaffinity(0, sizeof(cpu_set_t), mask)` returns error on machines with more than 1024 cores. The solution is that passing in dynamic size to sched_getaffinity() until it returns successfully.* ### Tickets: - *#26140 --------- Co-authored-by: Wanglei Shen <wanglei.shen@intel.com>
1 parent a17efa6 commit 2659786

File tree

3 files changed

+11
-24
lines changed

3 files changed

+11
-24
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ bool pin_thread_to_vacant_core(int thrIdx,
8787
}
8888

8989
bool pin_current_thread_to_socket(int socket) {
90-
const int sockets = ov::get_available_numa_nodes().size();
91-
const int cores = ov::get_number_of_cpu_cores();
90+
auto proc_type_table = get_org_proc_type_table();
91+
const int sockets = proc_type_table.size() > 1 ? proc_type_table.size() - 1 : 1;
92+
const int cores = proc_type_table[0][MAIN_CORE_PROC];
9293
const int cores_per_socket = cores / sockets;
9394

9495
int ncpus = 0;

src/inference/src/os/lin/lin_system_conf.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <vector>
1313

1414
#include "dev/threading/parallel_custom_arena.hpp"
15+
#include "dev/threading/thread_affinity.hpp"
1516
#include "openvino/core/except.hpp"
1617
#include "openvino/runtime/system_conf.hpp"
1718
#include "os/cpu_map_info.hpp"
@@ -114,10 +115,11 @@ CPU::CPU() {
114115
};
115116

116117
auto check_valid_cpu = [&]() {
117-
cpu_set_t mask;
118-
CPU_ZERO(&mask);
118+
ov::threading::CpuSet mask;
119+
int ncpus = 0;
120+
std::tie(mask, ncpus) = ov::threading::get_process_mask();
119121

120-
if ((_processors == 0) || (sched_getaffinity(0, sizeof(cpu_set_t), &mask) == -1)) {
122+
if ((_processors == 0) || mask == nullptr) {
121123
return -1;
122124
}
123125

@@ -128,7 +130,7 @@ CPU::CPU() {
128130

129131
numa_node_list.assign(_sockets, std::vector<int>());
130132
for (int i = 0; i < _processors; i++) {
131-
if (CPU_ISSET(i, &mask)) {
133+
if (CPU_ISSET(i, mask)) {
132134
valid_cpu_mapping_table.emplace_back(_cpu_mapping_table[i]);
133135
if (_cpu_mapping_table[i][CPU_MAP_CORE_TYPE] == MAIN_CORE_PROC) {
134136
phy_core_list.emplace_back(_cpu_mapping_table[i][CPU_MAP_CORE_ID]);

src/inference/src/system_conf.cpp

+2-18
Original file line numberDiff line numberDiff line change
@@ -327,26 +327,10 @@ int get_org_numa_id(int numa_node_id) {
327327
# ifndef _WIN32
328328
int get_number_of_cpu_cores(bool bigCoresOnly) {
329329
CPU& cpu = cpu_info();
330-
unsigned numberOfProcessors = cpu._processors;
331330
unsigned totalNumberOfCpuCores = cpu._cores;
332331
OPENVINO_ASSERT(totalNumberOfCpuCores != 0, "Total number of cpu cores can not be 0.");
333-
cpu_set_t usedCoreSet, currentCoreSet, currentCpuSet;
334-
CPU_ZERO(&currentCpuSet);
335-
CPU_ZERO(&usedCoreSet);
336-
CPU_ZERO(&currentCoreSet);
337-
338-
sched_getaffinity(0, sizeof(currentCpuSet), &currentCpuSet);
339-
340-
for (unsigned processorId = 0u; processorId < numberOfProcessors; processorId++) {
341-
if (CPU_ISSET(processorId, &currentCpuSet)) {
342-
unsigned coreId = processorId % totalNumberOfCpuCores;
343-
if (!CPU_ISSET(coreId, &usedCoreSet)) {
344-
CPU_SET(coreId, &usedCoreSet);
345-
CPU_SET(processorId, &currentCoreSet);
346-
}
347-
}
348-
}
349-
int phys_cores = CPU_COUNT(&currentCoreSet);
332+
333+
int phys_cores = totalNumberOfCpuCores;
350334
# if (OV_THREAD == OV_THREAD_TBB || OV_THREAD == OV_THREAD_TBB_AUTO)
351335
auto core_types = custom::info::core_types();
352336
if (bigCoresOnly && core_types.size() > 1) /*Hybrid CPU*/ {

0 commit comments

Comments
 (0)