File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change 1111#include < thread>
1212#include < tuple>
1313
14+ #ifdef __APPLE__
15+ #include < pthread.h>
16+ #include < sys/qos.h>
17+ #endif
18+
1419namespace stan {
1520namespace math {
1621
@@ -20,6 +25,10 @@ namespace math {
2025 * hook ensures that each worker thread has an initialized AD tape
2126 * ready for use.
2227 *
28+ * On Apple Silicon, this also sets the thread QoS class to
29+ * USER_INITIATED so that macOS prefers scheduling compute threads
30+ * on performance cores rather than efficiency cores.
31+ *
2332 * Refer to
2433 * https://software.intel.com/content/www/us/en/develop/documentation/tbb-documentation/top/intel-threading-building-blocks-developer-reference/task-scheduler/taskschedulerobserver.html
2534 * for details on the observer concept.
@@ -37,6 +46,13 @@ class ad_tape_observer final : public tbb::task_scheduler_observer {
3746 ~ad_tape_observer () { observe (false ); }
3847
3948 void on_scheduler_entry (bool worker) {
49+ #ifdef __APPLE__
50+ #if defined(__arm64__) || defined(__aarch64__)
51+ // Set thread QoS to USER_INITIATED so macOS prefers scheduling
52+ // TBB worker threads on performance cores rather than efficiency cores.
53+ pthread_set_qos_class_self_np (QOS_CLASS_USER_INITIATED, 0 );
54+ #endif
55+ #endif
4056 std::lock_guard<std::mutex> thread_tape_map_lock (thread_tape_map_mutex_);
4157 const std::thread::id thread_id = std::this_thread::get_id ();
4258 if (thread_tape_map_.find (thread_id) == thread_tape_map_.end ()) {
You can’t perform that action at this time.
0 commit comments