update parse_processor_info_macos for macOS ver 11 (#21517)

* 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
This commit is contained in:
Wanglei Shen 2023-12-09 14:10:28 +08:00 committed by GitHub
parent 06a27e7b31
commit 04c9a52b7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 75 additions and 52 deletions

View File

@ -157,14 +157,13 @@ void parse_processor_info_win(const char* base_ptr,
* @param[out] _sockets total number for sockets in system * @param[out] _sockets total number for sockets in system
* @param[out] _cores total number for physical CPU cores 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 * @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, void parse_processor_info_macos(const std::vector<std::pair<std::string, uint64_t>>& system_info_table,
int& _processors, int& _processors,
int& _numa_nodes, int& _numa_nodes,
int& _sockets, int& _sockets,
int& _cores, int& _cores,
std::vector<std::vector<int>>& _proc_type_table); std::vector<std::vector<int>>& _proc_type_table);
#endif #endif
} // namespace ov } // namespace ov

View File

@ -7,6 +7,7 @@
#include <vector> #include <vector>
#include "dev/threading/parallel_custom_arena.hpp" #include "dev/threading/parallel_custom_arena.hpp"
#include "openvino/core/except.hpp"
#include "openvino/runtime/system_conf.hpp" #include "openvino/runtime/system_conf.hpp"
#include "os/cpu_map_info.hpp" #include "os/cpu_map_info.hpp"
@ -28,17 +29,16 @@ CPU::CPU() {
} }
} }
if (!parse_processor_info_macos(system_info_table, _processors, _numa_nodes, _sockets, _cores, _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; _org_proc_type_table = _proc_type_table;
}
} }
int parse_processor_info_macos(const std::vector<std::pair<std::string, uint64_t>>& system_info_table, void parse_processor_info_macos(const std::vector<std::pair<std::string, uint64_t>>& system_info_table,
int& _processors, int& _processors,
int& _numa_nodes, int& _numa_nodes,
int& _sockets, int& _sockets,
int& _cores, int& _cores,
std::vector<std::vector<int>>& _proc_type_table) { std::vector<std::vector<int>>& _proc_type_table) {
_processors = 0; _processors = 0;
_numa_nodes = 0; _numa_nodes = 0;
_sockets = 0; _sockets = 0;
@ -51,7 +51,7 @@ int parse_processor_info_macos(const std::vector<std::pair<std::string, uint64_t
}); });
if (it == system_info_table.end()) { if (it == system_info_table.end()) {
return -1; OPENVINO_THROW("Unable to get number of cpus from macOS!");
} else { } else {
_processors = static_cast<int>(it->second); _processors = static_cast<int>(it->second);
} }
@ -63,63 +63,50 @@ int parse_processor_info_macos(const std::vector<std::pair<std::string, uint64_t
}); });
if (it == system_info_table.end()) { if (it == system_info_table.end()) {
_processors = 0; _cores = _processors;
return -1;
} else { } else {
_cores = static_cast<int>(it->second); _cores = static_cast<int>(it->second);
} }
_proc_type_table.resize(1, std::vector<int>(PROC_TYPE_TABLE_SIZE, 0));
_numa_nodes = 1; _numa_nodes = 1;
_sockets = 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(), it = std::find_if(system_info_table.begin(),
system_info_table.end(), system_info_table.end(),
[&](const std::pair<std::string, uint64_t>& item) { [&](const std::pair<std::string, uint64_t>& item) {
return item.first == "hw.optional.arm64"; return item.first == "hw.optional.arm64";
}); });
if (it == system_info_table.end()) { 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 {
it = std::find_if(system_info_table.begin(), it = std::find_if(system_info_table.begin(),
system_info_table.end(), system_info_table.end(),
[&](const std::pair<std::string, uint64_t>& item) { [&](const std::pair<std::string, uint64_t>& item) {
return item.first == "hw.perflevel0.physicalcpu"; return item.first == "hw.perflevel0.physicalcpu";
}); });
if (it == system_info_table.end()) { 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;
_proc_type_table[0][MAIN_CORE_PROC] = it->second; _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(), it = std::find_if(system_info_table.begin(),
system_info_table.end(), system_info_table.end(),
[&](const std::pair<std::string, uint64_t>& item) { [&](const std::pair<std::string, uint64_t>& item) {
return item.first == "hw.perflevel1.physicalcpu"; return item.first == "hw.perflevel1.physicalcpu";
}); });
if (it == system_info_table.end()) { if (it != system_info_table.end()) {
return 0; _proc_type_table[0][EFFICIENT_CORE_PROC] = it->second;
}
} else { } 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 } // namespace ov

View File

@ -52,7 +52,7 @@ public:
} }
}; };
MacOSCpuMapTestCase test_case_arm = { MacOSCpuMapTestCase test_case_arm_1 = {
8, // param[expected out]: total 8 logcial processors on this simulated platform 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 numa nodes on this simulated platform
1, // param[expected out]: total 1 sockets on this simulated platform 1, // param[expected out]: total 1 sockets on this simulated platform
@ -67,7 +67,32 @@ MacOSCpuMapTestCase test_case_arm = {
}, // param[in]: The system information table of this simulated platform }, // 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, 12,
1, 1,
1, 1,
@ -76,9 +101,21 @@ MacOSCpuMapTestCase test_case_x86 = {
{{"hw.ncpu", 12}, {"hw.physicalcpu", 6}}, {{"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) {} 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 #endif
} // namespace } // namespace