Skip to content

Commit 14d7eee

Browse files
authored
Update ggml-cpu.c
By directly specifying the cpumask boolean values, I can select to bind 4 or 3 cores within an AMD CCD (8-core complex), and persistently pin the thread pool threads to these cores.
1 parent 34c961b commit 14d7eee

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

ggml/src/ggml-cpu/ggml-cpu.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15398,6 +15398,9 @@ static struct ggml_threadpool * ggml_threadpool_new_impl(
1539815398
for (int j = 0; j < tpp->n_threads; j++) {
1539915399
workers[j].threadpool = threadpool;
1540015400
workers[j].ith = j;
15401+
memset(workers[j].cpumask, 0, GGML_MAX_N_THREADS);
15402+
//workers[j].cpumask[(j/3)*8+(j%3)*2]=1;
15403+
workers[j].cpumask[j*2] = 1;
1540115404
}
1540215405

1540315406
threadpool->workers = workers;
@@ -15412,15 +15415,15 @@ static struct ggml_threadpool * ggml_threadpool_new_impl(
1541215415
int32_t cpumask_iter = 0;
1541315416

1541415417
for (int j = 1; j < tpp->n_threads; j++) {
15415-
ggml_thread_cpumask_next(tpp->cpumask, workers[j].cpumask, tpp->strict_cpu, &cpumask_iter);
15418+
//ggml_thread_cpumask_next(tpp->cpumask, workers[j].cpumask, tpp->strict_cpu, &cpumask_iter);
1541615419

1541715420
int32_t rc = ggml_thread_create(&workers[j].thrd, NULL, ggml_graph_compute_secondary_thread, &workers[j]);
1541815421
GGML_ASSERT(rc == 0);
1541915422
}
1542015423

15421-
ggml_thread_cpumask_next(tpp->cpumask, workers[0].cpumask, tpp->strict_cpu, &cpumask_iter);
15424+
//ggml_thread_cpumask_next(tpp->cpumask, workers[0].cpumask, tpp->strict_cpu, &cpumask_iter);
1542215425

15423-
if (!threadpool->pause) {
15426+
if (true || !threadpool->pause) {
1542415427
// Update main thread prio and affinity at the start, otherwise we'll do it in resume
1542515428
ggml_thread_apply_priority(threadpool->prio);
1542615429
if (ggml_thread_cpumask_is_valid(threadpool->workers[0].cpumask)) {
@@ -15495,7 +15498,7 @@ enum ggml_status ggml_graph_compute(struct ggml_cgraph * cgraph, struct ggml_cpl
1549515498
#endif
1549615499

1549715500
// don't leave affinity set on the main thread
15498-
clear_numa_thread_affinity();
15501+
// clear_numa_thread_affinity();
1549915502

1550015503
enum ggml_status ret = threadpool->ec;
1550115504

0 commit comments

Comments
 (0)