16
16
17
17
#include < executorch/runtime/platform/assert.h>
18
18
19
+ #if defined(__APPLE__) && defined(__aarch64__)
20
+ #include < sys/sysctl.h>
21
+ #endif
22
+
19
23
namespace executorch ::extension::cpuinfo {
20
24
21
25
// Ignore revisions (last digit (4 LSBs))
@@ -33,6 +37,11 @@ bool is_non_performant_core(const struct cpuinfo_uarch_info* uarch_info) {
33
37
case cpuinfo_uarch_cortex_a53:
34
38
case cpuinfo_uarch_cortex_a510:
35
39
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:
36
45
return true ;
37
46
// This can be so many other cores.
38
47
// Need to update this to better account for slow cores
@@ -167,6 +176,23 @@ uint32_t get_num_performant_cores() {
167
176
// In one plua 12 while it has 2 little cores, the topology
168
177
// reported in /sys/devices/system/cpu/cpu* /topology/core_siblings_list
169
178
// 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 (
186
+ " hw.perflevel0.physicalcpu" ,
187
+ &num_cores,
188
+ &num_cores_len,
189
+ nullptr ,
190
+ 0 ) == 0 ) {
191
+ if (num_cores > 1 ) {
192
+ return static_cast <uint32_t >(num_cores);
193
+ }
194
+ }
195
+ #endif
170
196
return _get_num_performant_cores ();
171
197
}
172
198
}
0 commit comments