Skip to content

Commit ee445f9

Browse files
authored
common: Set optimal default thread count for ppc ( linux as well as AIX) (ggml-org#25237)
1 parent f36e5c3 commit ee445f9

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

common/common.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
#include <pwd.h>
5656
#endif
5757

58+
#if defined(_AIX)
59+
#include <sys/systemcfg.h>
60+
#endif
61+
5862
#if defined(_MSC_VER)
5963
#pragma warning(disable: 4244 4267) // possible loss of data
6064
#endif
@@ -72,7 +76,16 @@ common_time_meas::~common_time_meas() {
7276
//
7377

7478
int32_t common_cpu_get_num_physical_cores() {
75-
#ifdef __linux__
79+
#if defined(_AIX)
80+
int32_t logical_cpus = _system_configuration.ncpus;
81+
int32_t smt_threads = _system_configuration.smt_threads;
82+
if (smt_threads > 0) {
83+
return static_cast<int32_t>(logical_cpus / smt_threads);
84+
}
85+
if (logical_cpus > 0) {
86+
return static_cast<int32_t>(logical_cpus);
87+
}
88+
#elif defined(__linux__)
7689
// enumerate the set of thread siblings, num entries is num cores
7790
std::unordered_set<std::string> siblings;
7891
for (uint32_t cpu=0; cpu < UINT32_MAX; ++cpu) {
@@ -202,6 +215,14 @@ int32_t common_cpu_get_num_math() {
202215
}
203216
}
204217
}
218+
#elif defined(__powerpc64__) || defined(__powerpc__)
219+
int32_t smt_factor = 1;
220+
int phy_cpus = common_cpu_get_num_physical_cores();
221+
int logical_cpus = sysconf(_SC_NPROCESSORS_ONLN);
222+
if (phy_cpus > 0 && logical_cpus > phy_cpus) {
223+
smt_factor = logical_cpus / phy_cpus;
224+
}
225+
return phy_cpus * std::min(smt_factor, 2);
205226
#endif
206227
return common_cpu_get_num_physical_cores();
207228
}

0 commit comments

Comments
 (0)