enable cpu map for mac (#17499)
* enable cpu map for mac enable nstreams and nthreads setting for mac * keep streams=1 for M1 * add explicit type conversion * remove definition of static cpu * Update with master * separate branches for __APPLE__ and __EMSCRIPTEN__ * modify the implementation of is_cpu_map_available function --------- Co-authored-by: Wanglei Shen <wanglei.shen@intel.com>
This commit is contained in:
@@ -40,7 +40,14 @@ if(WIN32)
|
||||
file (GLOB LIBRARY_HEADERS
|
||||
${LIBRARY_HEADERS}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/os/win/*.hpp)
|
||||
elseif(NOT (APPLE OR EMSCRIPTEN))
|
||||
elseif(APPLE)
|
||||
file (GLOB LIBRARY_SRC
|
||||
${LIBRARY_SRC}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/os/mac/*.cpp)
|
||||
file (GLOB LIBRARY_HEADERS
|
||||
${LIBRARY_HEADERS}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/os/mac/*.hpp)
|
||||
elseif(NOT EMSCRIPTEN)
|
||||
file (GLOB LIBRARY_SRC
|
||||
${LIBRARY_SRC}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/os/lin/*.cpp)
|
||||
|
||||
@@ -148,7 +148,7 @@ struct CPUStreamsExecutor::Impl {
|
||||
? custom::info::core_types().back()
|
||||
: custom::info::core_types().front();
|
||||
if (_impl->_config._cpu_pinning) {
|
||||
# ifdef _WIN32
|
||||
# if defined(_WIN32) || defined(__APPLE__)
|
||||
_taskArena.reset(new custom::task_arena{custom::task_arena::constraints{}
|
||||
.set_core_type(selected_core_type)
|
||||
.set_max_concurrency(concurrency)});
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
// Copyright (C) 2018-2023 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "dev/threading/parallel_custom_arena.hpp"
|
||||
#include "openvino/runtime/system_conf.hpp"
|
||||
#include "streams_executor.hpp"
|
||||
|
||||
namespace ov {
|
||||
|
||||
CPU::CPU() {
|
||||
_num_threads = parallel_get_max_threads();
|
||||
parse_processor_info_macos(
|
||||
_processors,
|
||||
_numa_nodes,
|
||||
_cores,
|
||||
_proc_type_table);
|
||||
}
|
||||
|
||||
int parse_processor_info_macos(int& _processors,
|
||||
int& _numa_nodes,
|
||||
int& _cores,
|
||||
std::vector<std::vector<int>>& _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 = static_cast<int>(output);
|
||||
}
|
||||
|
||||
if (sysctlbyname("hw.physicalcpu", &output, &size, NULL, 0) < 0) {
|
||||
_processors = 0;
|
||||
return -1;
|
||||
} else {
|
||||
_cores = static_cast<int>(output);
|
||||
}
|
||||
|
||||
_numa_nodes = 1;
|
||||
|
||||
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[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<int>(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;
|
||||
}
|
||||
|
||||
} // namespace ov
|
||||
@@ -73,4 +73,19 @@ void parse_processor_info_win(const char* base_ptr,
|
||||
std::vector<std::vector<int>>& _cpu_mapping_table);
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
/**
|
||||
* @brief Parse processors infomation on Linux
|
||||
* @param[in] _processors total number for processors in system.
|
||||
* @param[out] _numa_nodes 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(int& _processors,
|
||||
int& _numa_nodes,
|
||||
int& _cores,
|
||||
std::vector<std::vector<int>>& _proc_type_table);
|
||||
#endif
|
||||
|
||||
} // namespace ov
|
||||
|
||||
@@ -163,7 +163,7 @@ CPU& cpu_info() {
|
||||
return cpu;
|
||||
}
|
||||
|
||||
#if defined(__APPLE__) || defined(__EMSCRIPTEN__)
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
// for Linux and Windows the getNumberOfCPUCores (that accounts only for physical cores) implementation is OS-specific
|
||||
// (see cpp files in corresponding folders), for __APPLE__ it is default :
|
||||
int get_number_of_cpu_cores(bool) {
|
||||
@@ -191,58 +191,39 @@ std::vector<std::vector<int>> reserve_available_cpus(const std::vector<std::vect
|
||||
}
|
||||
void set_cpu_used(const std::vector<int>& cpu_ids, const int used) {}
|
||||
|
||||
int parse_processor_info_macos(int& _processors,
|
||||
int& _numa_nodes,
|
||||
int& _cores,
|
||||
std::vector<std::vector<int>>& _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<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;
|
||||
} 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<int>(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;
|
||||
#elif defined(__APPLE__)
|
||||
// for Linux and Windows the getNumberOfCPUCores (that accounts only for physical cores) implementation is OS-specific
|
||||
// (see cpp files in corresponding folders), for __APPLE__ it is default :
|
||||
int get_number_of_cpu_cores(bool) {
|
||||
return parallel_get_max_threads();
|
||||
}
|
||||
# if !((OV_THREAD == OV_THREAD_TBB) || (OV_THREAD == OV_THREAD_TBB_AUTO))
|
||||
std::vector<int> get_available_numa_nodes() {
|
||||
return {-1};
|
||||
}
|
||||
# endif
|
||||
int get_number_of_logical_cpu_cores(bool) {
|
||||
return parallel_get_max_threads();
|
||||
}
|
||||
|
||||
bool is_cpu_map_available() {
|
||||
CPU& cpu = cpu_info();
|
||||
return cpu._proc_type_table.size() > 0;
|
||||
}
|
||||
|
||||
std::vector<std::vector<int>> get_proc_type_table() {
|
||||
CPU& cpu = cpu_info();
|
||||
std::lock_guard<std::mutex> lock{cpu._cpu_mutex};
|
||||
return cpu._proc_type_table;
|
||||
}
|
||||
|
||||
int get_num_numa_nodes() {
|
||||
return cpu_info()._numa_nodes;
|
||||
}
|
||||
std::vector<std::vector<int>> reserve_available_cpus(const std::vector<std::vector<int>> streams_info_table) {
|
||||
return {{-1}};
|
||||
}
|
||||
void set_cpu_used(const std::vector<int>& cpu_ids, const int used) {}
|
||||
|
||||
#else
|
||||
|
||||
|
||||
@@ -274,6 +274,7 @@ void Config::readProperties(const std::map<std::string, std::string> &prop) {
|
||||
#if defined(OPENVINO_ARCH_ARM) || defined(OPENVINO_ARCH_ARM64)
|
||||
// TODO: multi-stream execution has functional issues on ARM target
|
||||
streamExecutorConfig._streams = 1;
|
||||
streamExecutorConfig._streams_changed = true;
|
||||
#endif
|
||||
|
||||
CPU_DEBUG_CAP_ENABLE(applyDebugCapsProperties());
|
||||
|
||||
Reference in New Issue
Block a user