add socket id initialization in MacOS (#18717)

This commit is contained in:
Wanglei Shen 2023-07-22 02:49:36 +08:00 committed by GitHub
parent 85ca561546
commit 0974cb10bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View File

@ -149,14 +149,16 @@ void parse_processor_info_win(const char* base_ptr,
#if defined(__APPLE__) #if defined(__APPLE__)
/** /**
* @brief Parse processors infomation on Linux * @brief Parse processors infomation on Linux
* @param[in] _processors total number for processors in system. * @param[out] _processors total number for processors in system.
* @param[out] _numa_nodes total number for sockets in system * @param[out] _numa_nodes 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 * @return
*/ */
int parse_processor_info_macos(int& _processors, int parse_processor_info_macos(int& _processors,
int& _numa_nodes, int& _numa_nodes,
int& _sockets,
int& _cores, int& _cores,
std::vector<std::vector<int>>& _proc_type_table); std::vector<std::vector<int>>& _proc_type_table);
#endif #endif

View File

@ -13,12 +13,13 @@
namespace ov { namespace ov {
CPU::CPU() { CPU::CPU() {
parse_processor_info_macos(_processors, _numa_nodes, _cores, _proc_type_table); parse_processor_info_macos(_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(int& _processors, int parse_processor_info_macos(int& _processors,
int& _numa_nodes, int& _numa_nodes,
int& _sockets,
int& _cores, int& _cores,
std::vector<std::vector<int>>& _proc_type_table) { std::vector<std::vector<int>>& _proc_type_table) {
uint64_t output = 0; uint64_t output = 0;
@ -42,22 +43,28 @@ int parse_processor_info_macos(int& _processors,
} }
_numa_nodes = 1; _numa_nodes = 1;
_sockets = 1;
if (sysctlbyname("hw.optional.arm64", &output, &size, NULL, 0) < 0) { if (sysctlbyname("hw.optional.arm64", &output, &size, NULL, 0) < 0) {
_proc_type_table.resize(1, std::vector<int>(PROC_TYPE_TABLE_SIZE, 0)); _proc_type_table.resize(1, std::vector<int>(PROC_TYPE_TABLE_SIZE, 0));
_proc_type_table[0][ALL_PROC] = _processors; _proc_type_table[0][ALL_PROC] = _processors;
_proc_type_table[0][MAIN_CORE_PROC] = _cores; _proc_type_table[0][MAIN_CORE_PROC] = _cores;
_proc_type_table[0][HYPER_THREADING_PROC] = _processors - _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 { } else {
if (sysctlbyname("hw.perflevel0.physicalcpu", &output, &size, NULL, 0) < 0) { if (sysctlbyname("hw.perflevel0.physicalcpu", &output, &size, NULL, 0) < 0) {
_processors = 0; _processors = 0;
_cores = 0; _cores = 0;
_numa_nodes = 0; _numa_nodes = 0;
_sockets = 0;
return -1; return -1;
} else { } else {
_proc_type_table.resize(1, std::vector<int>(PROC_TYPE_TABLE_SIZE, 0)); _proc_type_table.resize(1, std::vector<int>(PROC_TYPE_TABLE_SIZE, 0));
_proc_type_table[0][ALL_PROC] = _processors; _proc_type_table[0][ALL_PROC] = _processors;
_proc_type_table[0][MAIN_CORE_PROC] = output; _proc_type_table[0][MAIN_CORE_PROC] = output;
_proc_type_table[0][PROC_NUMA_NODE_ID] = 0;
_proc_type_table[0][PROC_SOCKET_ID] = 0;
} }
if (sysctlbyname("hw.perflevel1.physicalcpu", &output, &size, NULL, 0) < 0) { if (sysctlbyname("hw.perflevel1.physicalcpu", &output, &size, NULL, 0) < 0) {
@ -67,9 +74,6 @@ int parse_processor_info_macos(int& _processors,
} }
} }
_proc_type_table[0][PROC_NUMA_NODE_ID] = 0;
_proc_type_table[0][PROC_SOCKET_ID] = 0;
return 0; return 0;
} }