diff --git a/onnxruntime/core/platform/posix/env.cc b/onnxruntime/core/platform/posix/env.cc index 3d1c28a26c..e382e70799 100644 --- a/onnxruntime/core/platform/posix/env.cc +++ b/onnxruntime/core/platform/posix/env.cc @@ -36,8 +36,12 @@ limitations under the License. #include // for std::forward #include -#ifdef CPUINFO_SUPPORTED +// We can not use CPUINFO if it is not supported and we do not want to used +// it on certain platforms because of the binary size increase. +// We could use it to find out the number of physical cores for certain supported platforms +#if defined(CPUINFO_SUPPORTED) && !defined(__APPLE__) && !defined(__ANDROID__) && !defined(__wasm__) && !defined(_AIX) #include +#define ORT_USE_CPUINFO #endif #include "core/common/common.h" @@ -271,36 +275,31 @@ class PosixEnv : public Env { return new PosixThread(name_prefix, index, start_address, param, thread_options); } - // we are guessing the number of phys cores based on a popular HT case. + // we are guessing the number of phys cores based on a popular HT case (2 logical proc per core) static int DefaultNumCores() { return std::max(1, static_cast(std::thread::hardware_concurrency() / 2)); } // Return the number of physical cores int GetNumPhysicalCpuCores() const override { -#ifdef CPUINFO_SUPPORTED +#ifdef ORT_USE_CPUINFO if(cpuinfo_available_) { return narrow(cpuinfo_get_cores_count()); } -#endif - // We guess the number of cores +#endif // ORT_USE_CPUINFO return DefaultNumCores(); } std::vector GetThreadAffinityMasks() const override { std::vector ret; -#ifdef CPUINFO_SUPPORTED +#ifdef ORT_USE_CPUINFO if (cpuinfo_available_) { -#if !defined(__APPLE__) && !defined(__ANDROID__) && !defined(__wasm__) && !defined(_AIX) - // We currently do not implement affinity on more than 64 cores. auto num_phys_cores = cpuinfo_get_cores_count(); ret.reserve(num_phys_cores); for (uint32_t i = 0; i < num_phys_cores; ++i) { const auto* core = cpuinfo_get_core(i); LogicalProcessors th_aff; - // Processor count will never exceed 64 in a given group. - // TBD: Processor groups are currently not taken into account. th_aff.reserve(core->processor_count); auto log_proc_idx = core->processor_start; for (uint32_t count = 0; count < core->processor_count; count++, ++log_proc_idx) { @@ -309,9 +308,8 @@ class PosixEnv : public Env { } ret.push_back(std::move(th_aff)); } -#endif } -#endif // CPUINFO_SUPPORTED +#endif // Just the size of the thread-pool if(ret.empty()) { ret.resize(GetNumPhysicalCpuCores()); @@ -581,18 +579,16 @@ class PosixEnv : public Env { } private: + Telemetry telemetry_provider_; +#ifdef ORT_USE_CPUINFO PosixEnv() { -#ifdef CPUINFO_SUPPORTED cpuinfo_available_ = cpuinfo_initialize(); if(!cpuinfo_available_) { LOGS_DEFAULT(INFO) << "cpuinfo_initialize failed"; } -#endif } - Telemetry telemetry_provider_; -#ifdef CPUINFO_SUPPORTED bool cpuinfo_available_{false}; -#endif +#endif // ORT_USE_CPUINFO }; } // namespace