|
18 | 18 |
|
19 | 19 | #include <cpuinfo.h>
|
20 | 20 |
|
| 21 | +// At most one mode should be set. |
| 22 | +#if ( \ |
| 23 | + defined(EXECUTORCH_THREADPOOL_SIZE) && \ |
| 24 | + defined(EXECUTORCH_THREADPOOL_USE_ALL_LOGICAL_CORES) || \ |
| 25 | + defined(EXECUTORCH_THREADPOOL_SIZE) && \ |
| 26 | + defined(EXECUTORCH_THREADPOOL_USE_PERFORMANCE_CORES) || \ |
| 27 | + defined(EXECUTORCH_THREADPOOL_USE_ALL_LOGICAL_CORES) && \ |
| 28 | + defined(EXECUTORCH_THREADPOOL_USE_PERFORMANCE_CORES)) |
| 29 | +#error Multiple \ |
| 30 | + threadpool size specifiers are set.At most one of \ |
| 31 | + EXECUTORCH_THREADPOOL_SIZE, \ |
| 32 | + EXECUTORCH_THREADPOOL_USE_ALL_LOGICAL_CORES, \ |
| 33 | + and EXECUTORCH_THREADPOOL_USE_PERFORMANCE_CORES may be defined. |
| 34 | +#endif |
| 35 | + |
| 36 | +// Default to EXECUTORCH_THREADPOOL_USE_PERFORMANCE_CORES if no mode is set. |
| 37 | +#if !defined(EXECUTORCH_THREADPOOL_SIZE) && \ |
| 38 | + !defined(EXECUTORCH_THREADPOOL_USE_ALL_LOGICAL_CORES) && \ |
| 39 | + !defined(EXECUTORCH_THREADPOOL_USE_PERFORMANCE_CORES) |
| 40 | +#define EXECUTORCH_THREADPOOL_USE_PERFORMANCE_CORES 1 |
| 41 | +#endif |
| 42 | + |
21 | 43 | namespace executorch::extension::threadpool {
|
22 | 44 |
|
23 | 45 | #if !(defined(WIN32))
|
@@ -105,16 +127,15 @@ ThreadPool* get_threadpool() {
|
105 | 127 | // Choose the number of threads according to the EXECUTORCH_THREADPOOL_SIZE
|
106 | 128 | // value. See the description in threadpool.h.
|
107 | 129 |
|
108 |
| -#if defined(EXECUTORCH_THREADPOOL_SIZE) && ((EXECUTORCH_THREADPOOL_SIZE) > 0) |
| 130 | +#ifdef EXECUTORCH_THREADPOOL_SIZE |
109 | 131 | // Use an explicit threadpool size.
|
110 |
| - int num_threads = EXECUTORCH_THREADPOOL_SIZE; |
111 |
| -#elif defined(EXECUTORCH_THREADPOOL_SIZE) && \ |
112 |
| - ((EXECUTORCH_THREADPOOL_SIZE) == -1) |
| 132 | + static int num_threads = EXECUTORCH_THREADPOOL_SIZE; |
| 133 | +#elif defined(EXECUTORCH_THREADPOOL_USE_ALL_LOGICAL_CORES) |
113 | 134 | // Use threads=cores.
|
114 |
| - int num_threads = cpuinfo_get_processors_count(); |
| 135 | + static int num_threads = cpuinfo_get_processors_count(); |
115 | 136 | #else
|
116 |
| - // Use a performance heuristic. |
117 |
| - int num_threads = |
| 137 | + // Set threads equal to the number of performance cores. |
| 138 | + static int num_threads = |
118 | 139 | ::executorch::extension::cpuinfo::get_num_performant_cores();
|
119 | 140 | #endif
|
120 | 141 |
|
|
0 commit comments