Skip to content

Commit

Permalink
update parse_processor_info_macos for macOS ver 11 (#21517)
Browse files Browse the repository at this point in the history
* update parse_processor_info_macos for wrong macos info

* update default setting

* update default setting

* update for comment

* fix typo

* update test data

* update init order
  • Loading branch information
wangleis authored Dec 9, 2023
1 parent 06a27e7 commit 04c9a52
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 52 deletions.
13 changes: 6 additions & 7 deletions src/inference/src/os/cpu_map_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,13 @@ void parse_processor_info_win(const char* base_ptr,
* @param[out] _sockets total number for sockets in system
* @param[out] _cores total number for physical CPU cores in system
* @param[out] _proc_type_table summary table of number of processors per type
* @return
*/
int parse_processor_info_macos(const std::vector<std::pair<std::string, uint64_t>>& system_info_table,
int& _processors,
int& _numa_nodes,
int& _sockets,
int& _cores,
std::vector<std::vector<int>>& _proc_type_table);
void parse_processor_info_macos(const std::vector<std::pair<std::string, uint64_t>>& system_info_table,
int& _processors,
int& _numa_nodes,
int& _sockets,
int& _cores,
std::vector<std::vector<int>>& _proc_type_table);
#endif

} // namespace ov
71 changes: 29 additions & 42 deletions src/inference/src/os/mac/mac_system_conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <vector>

#include "dev/threading/parallel_custom_arena.hpp"
#include "openvino/core/except.hpp"
#include "openvino/runtime/system_conf.hpp"
#include "os/cpu_map_info.hpp"

Expand All @@ -28,17 +29,16 @@ CPU::CPU() {
}
}

if (!parse_processor_info_macos(system_info_table, _processors, _numa_nodes, _sockets, _cores, _proc_type_table)) {
_org_proc_type_table = _proc_type_table;
}
parse_processor_info_macos(system_info_table, _processors, _numa_nodes, _sockets, _cores, _proc_type_table);
_org_proc_type_table = _proc_type_table;
}

int parse_processor_info_macos(const std::vector<std::pair<std::string, uint64_t>>& system_info_table,
int& _processors,
int& _numa_nodes,
int& _sockets,
int& _cores,
std::vector<std::vector<int>>& _proc_type_table) {
void parse_processor_info_macos(const std::vector<std::pair<std::string, uint64_t>>& system_info_table,
int& _processors,
int& _numa_nodes,
int& _sockets,
int& _cores,
std::vector<std::vector<int>>& _proc_type_table) {
_processors = 0;
_numa_nodes = 0;
_sockets = 0;
Expand All @@ -51,7 +51,7 @@ int parse_processor_info_macos(const std::vector<std::pair<std::string, uint64_t
});

if (it == system_info_table.end()) {
return -1;
OPENVINO_THROW("Unable to get number of cpus from macOS!");
} else {
_processors = static_cast<int>(it->second);
}
Expand All @@ -63,63 +63,50 @@ int parse_processor_info_macos(const std::vector<std::pair<std::string, uint64_t
});

if (it == system_info_table.end()) {
_processors = 0;
return -1;
_cores = _processors;
} else {
_cores = static_cast<int>(it->second);
}

_proc_type_table.resize(1, std::vector<int>(PROC_TYPE_TABLE_SIZE, 0));

_numa_nodes = 1;
_sockets = 1;

_proc_type_table[0][ALL_PROC] = _processors;
_proc_type_table[0][MAIN_CORE_PROC] = _cores;
_proc_type_table[0][HYPER_THREADING_PROC] = _processors - _cores;

it = std::find_if(system_info_table.begin(),
system_info_table.end(),
[&](const std::pair<std::string, uint64_t>& item) {
return item.first == "hw.optional.arm64";
});

if (it == system_info_table.end()) {
_proc_type_table.resize(1, std::vector<int>(PROC_TYPE_TABLE_SIZE, 0));
_proc_type_table[0][ALL_PROC] = _processors;
_proc_type_table[0][MAIN_CORE_PROC] = _cores;
_proc_type_table[0][HYPER_THREADING_PROC] = _processors - _cores;
_proc_type_table[0][PROC_NUMA_NODE_ID] = 0;
_proc_type_table[0][PROC_SOCKET_ID] = 0;
} else {
if (it != system_info_table.end()) {
it = std::find_if(system_info_table.begin(),
system_info_table.end(),
[&](const std::pair<std::string, uint64_t>& item) {
return item.first == "hw.perflevel0.physicalcpu";
});

if (it == system_info_table.end()) {
_processors = 0;
_cores = 0;
_numa_nodes = 0;
_sockets = 0;
return -1;
} else {
_proc_type_table.resize(1, std::vector<int>(PROC_TYPE_TABLE_SIZE, 0));
_proc_type_table[0][ALL_PROC] = _processors;
if (it != system_info_table.end()) {
_proc_type_table[0][MAIN_CORE_PROC] = it->second;
_proc_type_table[0][PROC_NUMA_NODE_ID] = 0;
_proc_type_table[0][PROC_SOCKET_ID] = 0;
}

it = std::find_if(system_info_table.begin(),
system_info_table.end(),
[&](const std::pair<std::string, uint64_t>& item) {
return item.first == "hw.perflevel1.physicalcpu";
});
it = std::find_if(system_info_table.begin(),
system_info_table.end(),
[&](const std::pair<std::string, uint64_t>& item) {
return item.first == "hw.perflevel1.physicalcpu";
});

if (it == system_info_table.end()) {
return 0;
if (it != system_info_table.end()) {
_proc_type_table[0][EFFICIENT_CORE_PROC] = it->second;
}
} else {
_proc_type_table[0][EFFICIENT_CORE_PROC] = it->second;
_proc_type_table[0][EFFICIENT_CORE_PROC] = _cores / 2;
_proc_type_table[0][MAIN_CORE_PROC] = _cores - _proc_type_table[0][EFFICIENT_CORE_PROC];
}
}

return 0;
}

} // namespace ov
43 changes: 40 additions & 3 deletions src/inference/tests/unit/cpu_map_parser/parser_macos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class MacOSCpuMapParserTests : public ov::test::TestsCommon,
}
};

MacOSCpuMapTestCase test_case_arm = {
MacOSCpuMapTestCase test_case_arm_1 = {
8, // param[expected out]: total 8 logcial processors on this simulated platform
1, // param[expected out]: total 1 numa nodes on this simulated platform
1, // param[expected out]: total 1 sockets on this simulated platform
Expand All @@ -67,7 +67,32 @@ MacOSCpuMapTestCase test_case_arm = {
}, // param[in]: The system information table of this simulated platform
};

MacOSCpuMapTestCase test_case_x86 = {
MacOSCpuMapTestCase test_case_arm_2 = {
8,
1,
1,
8,
{{8, 4, 4, 0, 0, 0}},
{
{"hw.ncpu", 8},
{"hw.physicalcpu", 8},
{"hw.optional.arm64", 1},
},
};

MacOSCpuMapTestCase test_case_arm_3 = {
8,
1,
1,
8,
{{8, 4, 4, 0, 0, 0}},
{
{"hw.ncpu", 8},
{"hw.optional.arm64", 1},
},
};

MacOSCpuMapTestCase test_case_x86_1 = {
12,
1,
1,
Expand All @@ -76,9 +101,21 @@ MacOSCpuMapTestCase test_case_x86 = {
{{"hw.ncpu", 12}, {"hw.physicalcpu", 6}},
};

MacOSCpuMapTestCase test_case_x86_2 = {
12,
1,
1,
12,
{{12, 12, 0, 0, 0, 0}},
{{"hw.ncpu", 12}},
};

TEST_P(MacOSCpuMapParserTests, MacOS) {}

INSTANTIATE_TEST_SUITE_P(CPUMap, MacOSCpuMapParserTests, testing::Values(test_case_arm, test_case_x86));
INSTANTIATE_TEST_SUITE_P(
CPUMap,
MacOSCpuMapParserTests,
testing::Values(test_case_arm_1, test_case_arm_2, test_case_arm_3, test_case_x86_1, test_case_x86_2));

#endif
} // namespace

0 comments on commit 04c9a52

Please sign in to comment.