1616
1717#include < executorch/runtime/platform/assert.h>
1818
19+ #if defined(__APPLE__) && defined(__aarch64__)
20+ #include < sys/sysctl.h>
21+ #endif
22+
1923namespace 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,23 @@ 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 (
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
170196 return _get_num_performant_cores ();
171197 }
172198}
0 commit comments