Skip to content

Commit 3da969d

Browse files
authored
fix CPU affinity check issues (#32596)
### Details: - *fix issue in using numactl on platform with offline CPUs* - *fix numa node parser for platform with offline CUPs* ### Tickets: - *#32574
1 parent 4736942 commit 3da969d

File tree

2 files changed

+45
-23
lines changed

2 files changed

+45
-23
lines changed

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

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ CPU::CPU() {
163163

164164
numa_node_list.assign(_sockets, std::vector<int>());
165165
for (int i = 0; i < _processors; i++) {
166-
if (CPU_ISSET(i, mask)) {
166+
if (CPU_ISSET(_cpu_mapping_table[i][CPU_MAP_PROCESSOR_ID], mask)) {
167167
valid_cpu_mapping_table.emplace_back(_cpu_mapping_table[i]);
168168
if (_cpu_mapping_table[i][CPU_MAP_CORE_TYPE] == MAIN_CORE_PROC) {
169169
phy_core_list.emplace_back(_cpu_mapping_table[i][CPU_MAP_CORE_ID]);
@@ -340,33 +340,28 @@ void parse_node_info_linux(const std::vector<std::string> node_info_table,
340340
int core_1 = 0;
341341
int core_2 = 0;
342342
std::string::size_type pos = 0;
343-
std::string::size_type endpos = 0;
343+
std::string::size_type endpos_1 = 0;
344+
std::string::size_type endpos_2 = 0;
344345
std::string sub_str = "";
345346

346-
if (((endpos = one_info.find('-', pos)) == std::string::npos) &&
347-
((endpos = one_info.find(',', pos)) != std::string::npos)) {
348-
while (endpos != std::string::npos) {
347+
while (pos != std::string::npos) {
348+
endpos_1 = one_info.find(',', pos);
349+
endpos_2 = one_info.find('-', pos);
350+
if ((endpos_1 < endpos_2) || (endpos_1 == std::string::npos && endpos_2 == std::string::npos)) {
349351
sub_str = one_info.substr(pos);
350352
core_1 = std::stoi(sub_str);
351353
nodes_table.push_back({core_1, core_1, node_index});
352-
endpos = one_info.find(',', pos);
353-
pos = endpos + 1;
354+
} else if (endpos_2 != std::string::npos) {
355+
sub_str = one_info.substr(pos, endpos_2 - pos);
356+
core_1 = std::stoi(sub_str);
357+
sub_str = one_info.substr(endpos_2 + 1);
358+
core_2 = std::stoi(sub_str);
359+
nodes_table.push_back({core_1, core_2, node_index});
354360
}
355-
} else {
356-
while (endpos != std::string::npos) {
357-
if ((endpos = one_info.find('-', pos)) != std::string::npos) {
358-
sub_str = one_info.substr(pos, endpos - pos);
359-
core_1 = std::stoi(sub_str);
360-
sub_str = one_info.substr(endpos + 1);
361-
core_2 = std::stoi(sub_str);
362-
nodes_table.push_back({core_1, core_2, node_index});
363-
pos = one_info.find(',', endpos);
364-
if (pos == std::string::npos) {
365-
break;
366-
} else {
367-
pos = pos + 1;
368-
}
369-
}
361+
if (endpos_1 == std::string::npos) {
362+
break;
363+
} else {
364+
pos = endpos_1 + 1;
370365
}
371366
}
372367
node_index++;

src/inference/tests/unit/cpu_map_parser/cache_parser_linux.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,32 @@ LinuxCpuMapTestCase cache_mock_1 = {
17051705
{},
17061706
};
17071707

1708+
LinuxCpuMapTestCase cache_mock_2 = {
1709+
5,
1710+
1,
1711+
1,
1712+
5,
1713+
{{5, 5, 0, 0, 0, 0, 0}},
1714+
{
1715+
{0, 0, 0, 0, MAIN_CORE_PROC, 0, -1},
1716+
{2, 0, 0, 1, MAIN_CORE_PROC, 1, -1},
1717+
{3, 0, 0, 2, MAIN_CORE_PROC, 2, -1},
1718+
{4, 0, 0, 3, MAIN_CORE_PROC, 3, -1},
1719+
{7, 0, 0, 4, MAIN_CORE_PROC, 4, -1},
1720+
},
1721+
{
1722+
{"0", "0", "0,2-4,7"},
1723+
{"", "", ""},
1724+
{"2", "2", "0,2-4,7"},
1725+
{"3", "3", "0,2-4,7"},
1726+
{"4", "4", "0,2-4,7"},
1727+
{"", "", ""},
1728+
{"", "", ""},
1729+
{"7", "7", "0,2-4,7"},
1730+
},
1731+
{{"0,2-4,7"}},
1732+
};
1733+
17081734
TEST_P(LinuxCpuMapCacheParserTests, LinuxCache) {}
17091735

17101736
INSTANTIATE_TEST_SUITE_P(CPUMap,
@@ -1737,7 +1763,8 @@ INSTANTIATE_TEST_SUITE_P(CPUMap,
17371763
cache_1sockets_4cores_2,
17381764
cache_VM_cache_0,
17391765
cache_mock_0,
1740-
cache_mock_1));
1766+
cache_mock_1,
1767+
cache_mock_2));
17411768

17421769
TEST_P(LinuxGetCpuMapFromCoresTests, LinuxCore) {}
17431770

0 commit comments

Comments
 (0)