Skip to content

Commit

Permalink
Support machines with more than 1024 cores (#26303)
Browse files Browse the repository at this point in the history
### 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>
  • Loading branch information
sunxiaoxia2022 and wangleis authored Sep 25, 2024
1 parent a17efa6 commit 2659786
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
5 changes: 3 additions & 2 deletions src/inference/src/dev/threading/thread_affinity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ bool pin_thread_to_vacant_core(int thrIdx,
}

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

int ncpus = 0;
Expand Down
10 changes: 6 additions & 4 deletions src/inference/src/os/lin/lin_system_conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <vector>

#include "dev/threading/parallel_custom_arena.hpp"
#include "dev/threading/thread_affinity.hpp"
#include "openvino/core/except.hpp"
#include "openvino/runtime/system_conf.hpp"
#include "os/cpu_map_info.hpp"
Expand Down Expand Up @@ -114,10 +115,11 @@ CPU::CPU() {
};

auto check_valid_cpu = [&]() {
cpu_set_t mask;
CPU_ZERO(&mask);
ov::threading::CpuSet mask;
int ncpus = 0;
std::tie(mask, ncpus) = ov::threading::get_process_mask();

if ((_processors == 0) || (sched_getaffinity(0, sizeof(cpu_set_t), &mask) == -1)) {
if ((_processors == 0) || mask == nullptr) {
return -1;
}

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

numa_node_list.assign(_sockets, std::vector<int>());
for (int i = 0; i < _processors; i++) {
if (CPU_ISSET(i, &mask)) {
if (CPU_ISSET(i, mask)) {
valid_cpu_mapping_table.emplace_back(_cpu_mapping_table[i]);
if (_cpu_mapping_table[i][CPU_MAP_CORE_TYPE] == MAIN_CORE_PROC) {
phy_core_list.emplace_back(_cpu_mapping_table[i][CPU_MAP_CORE_ID]);
Expand Down
20 changes: 2 additions & 18 deletions src/inference/src/system_conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,26 +327,10 @@ int get_org_numa_id(int numa_node_id) {
# ifndef _WIN32
int get_number_of_cpu_cores(bool bigCoresOnly) {
CPU& cpu = cpu_info();
unsigned numberOfProcessors = cpu._processors;
unsigned totalNumberOfCpuCores = cpu._cores;
OPENVINO_ASSERT(totalNumberOfCpuCores != 0, "Total number of cpu cores can not be 0.");
cpu_set_t usedCoreSet, currentCoreSet, currentCpuSet;
CPU_ZERO(&currentCpuSet);
CPU_ZERO(&usedCoreSet);
CPU_ZERO(&currentCoreSet);

sched_getaffinity(0, sizeof(currentCpuSet), &currentCpuSet);

for (unsigned processorId = 0u; processorId < numberOfProcessors; processorId++) {
if (CPU_ISSET(processorId, &currentCpuSet)) {
unsigned coreId = processorId % totalNumberOfCpuCores;
if (!CPU_ISSET(coreId, &usedCoreSet)) {
CPU_SET(coreId, &usedCoreSet);
CPU_SET(processorId, &currentCoreSet);
}
}
}
int phys_cores = CPU_COUNT(&currentCoreSet);

int phys_cores = totalNumberOfCpuCores;
# if (OV_THREAD == OV_THREAD_TBB || OV_THREAD == OV_THREAD_TBB_AUTO)
auto core_types = custom::info::core_types();
if (bigCoresOnly && core_types.size() > 1) /*Hybrid CPU*/ {
Expand Down

0 comments on commit 2659786

Please sign in to comment.