From 2302e10d3e073eea3c7741ff06f593e7ca957907 Mon Sep 17 00:00:00 2001 From: Wanglei Shen Date: Mon, 22 May 2023 16:29:05 +0800 Subject: [PATCH] enable proc_type_table on MacOS for both ARM and x86 (#17427) * enable proc_type_table on MacOS for both ARM and x86 * fix code style issue * update for comments --- src/inference/src/system_conf.cpp | 53 +++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/inference/src/system_conf.cpp b/src/inference/src/system_conf.cpp index ec7b22a0824..d3698ceb71f 100644 --- a/src/inference/src/system_conf.cpp +++ b/src/inference/src/system_conf.cpp @@ -186,6 +186,59 @@ std::vector> reserve_available_cpus(const std::vector& cpu_ids, const int used) {} +int parse_processor_info_macos(int& _processors, + int& _numa_nodes, + int& _cores, + std::vector>& _proc_type_table) { + uint64_t output = 0; + size_t size = sizeof(output); + + _processors = 0; + _numa_nodes = 0; + _cores = 0; + + if (sysctlbyname("hw.ncpu", &output, &size, NULL, 0) < 0) { + return -1; + } else { + _processors = output; + } + + if (sysctlbyname("hw.physicalcpu", &output, &size, NULL, 0) < 0) { + _processors = 0; + return -1; + } else { + _cores = output; + } + + _numa_nodes = 1; + + if (sysctlbyname("hw.optional.arm64", &output, &size, NULL, 0) < 0) { + _proc_type_table.resize(1, std::vector(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; + } else { + if (sysctlbyname("hw.perflevel0.physicalcpu", &output, &size, NULL, 0) < 0) { + _processors = 0; + _cores = 0; + _numa_nodes = 0; + return -1; + } else { + _proc_type_table.resize(1, std::vector(PROC_TYPE_TABLE_SIZE, 0)); + _proc_type_table[0][ALL_PROC] = _processors; + _proc_type_table[0][MAIN_CORE_PROC] = output; + } + + if (sysctlbyname("hw.perflevel1.physicalcpu", &output, &size, NULL, 0) < 0) { + return 0; + } else { + _proc_type_table[0][EFFICIENT_CORE_PROC] = output; + } + } + + return 0; +} + #else # ifndef _WIN32