Skip to content

Commit cd855b3

Browse files
committed
Update cpuinfo utils to account for apple soc detection
Summary: For macbooks it also takes the path of just querying perfcores which should actually work for ios as well. Test Plan: Use internal util and validate the behavior is as expected Reviewers: Subscribers: Tasks: Tags:
1 parent 9f74777 commit cd855b3

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

extension/threadpool/cpuinfo_utils.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
#include <executorch/runtime/platform/assert.h>
1818

19+
#if defined(__APPLE__) && defined(__aarch64__)
20+
#include <sys/sysctl.h>
21+
#endif
22+
1923
namespace executorch::extension::cpuinfo {
2024

2125
// Ignore revisions (last digit (4 LSBs))
@@ -33,6 +37,11 @@ bool is_non_performant_core(const struct cpuinfo_uarch_info* uarch_info) {
3337
case cpuinfo_uarch_cortex_a53:
3438
case cpuinfo_uarch_cortex_a510:
3539
case cpuinfo_uarch_icestorm:
40+
case cpuinfo_uarch_blizzard:
41+
case cpuinfo_uarch_sawtooth:
42+
case cpuinfo_uarch_coll_sawtooth:
43+
case cpuinfo_uarch_tupai_sawtooth:
44+
case cpuinfo_uarch_tahiti_sawtooth:
3645
return true;
3746
// This can be so many other cores.
3847
// Need to update this to better account for slow cores
@@ -167,6 +176,18 @@ uint32_t get_num_performant_cores() {
167176
// In one plua 12 while it has 2 little cores, the topology
168177
// reported in /sys/devices/system/cpu/cpu* /topology/core_siblings_list
169178
// report wrong topology which results in wront configratuon
179+
#if defined(__aarch64__) && defined(__APPLE__)
180+
// Copied from ATen/ParallelCommon.cpp
181+
// On Apple Silicon there are efficient and performance core
182+
// Restrict parallel algorithms to performance cores by default
183+
int32_t num_cores = -1;
184+
size_t num_cores_len = sizeof(num_cores);
185+
if (sysctlbyname("hw.perflevel0.physicalcpu", &num_cores, &num_cores_len, nullptr, 0) == 0) {
186+
if (num_cores > 1) {
187+
return static_cast<uint32_t>(num_cores);
188+
}
189+
}
190+
#endif
170191
return _get_num_performant_cores();
171192
}
172193
}

0 commit comments

Comments
 (0)