Skip to content

Commit 693b668

Browse files
threadpool: update calling thread prio and affinity only at start/resume
This avoids extra syscalls for each graph_compute()
1 parent db15f42 commit 693b668

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

ggml/src/ggml.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18898,6 +18898,12 @@ static void ggml_resume_threadpool_locked(struct ggml_compute_threadpool * threa
1889818898
GGML_PRINT_DEBUG("Resuming threadpool\n");
1889918899
threadpool->pause = false;
1890018900
ggml_cond_broadcast(&threadpool->cond);
18901+
18902+
// Update main thread prio and affinity to match the threadpool settings
18903+
ggml_thread_apply_thread_priority(threadpool->prio);
18904+
if (ggml_thread_cpumask_is_valid(threadpool->workers[0].cpumask)) {
18905+
ggml_thread_apply_affinity(threadpool->workers[0].cpumask);
18906+
}
1890118907
}
1890218908
#endif
1890318909

@@ -19324,6 +19330,14 @@ static struct ggml_compute_threadpool * ggml_create_threadpool_impl(
1932419330
}
1932519331

1932619332
ggml_thread_cpumask_next(tpp->cpumask, workers[0].cpumask, tpp->strict_cpu, &cpumask_iter);
19333+
19334+
if (!threadpool->pause) {
19335+
// Update main thread prio and affinity at the start, otherwise we'll do it in resume
19336+
ggml_thread_apply_thread_priority(threadpool->prio);
19337+
if (ggml_thread_cpumask_is_valid(threadpool->workers[0].cpumask)) {
19338+
ggml_thread_apply_affinity(threadpool->workers[0].cpumask);
19339+
}
19340+
}
1932719341
#endif // GGML_USE_OPENMP
1932819342

1932919343
return threadpool;
@@ -19380,12 +19394,6 @@ enum ggml_status ggml_graph_compute(struct ggml_cgraph * cgraph, struct ggml_cpl
1938019394
ggml_graph_compute_thread(&threadpool->workers[0]);
1938119395
}
1938219396
#else
19383-
// Update main thread prio and affinity to match the current threadpool
19384-
ggml_thread_apply_thread_priority(threadpool->prio);
19385-
if (ggml_thread_cpumask_is_valid(threadpool->workers[0].cpumask)) {
19386-
ggml_thread_apply_affinity(threadpool->workers[0].cpumask);
19387-
}
19388-
1938919397
// Kick all threads to start the new graph
1939019398
ggml_graph_compute_kickoff(threadpool);
1939119399

0 commit comments

Comments
 (0)