From 14d7eeebaf36847a53eef5ecb885fa61c9d558ae Mon Sep 17 00:00:00 2001 From: zts9989 Date: Fri, 21 Mar 2025 13:08:03 +0800 Subject: [PATCH] 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. --- ggml/src/ggml-cpu/ggml-cpu.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ggml/src/ggml-cpu/ggml-cpu.c b/ggml/src/ggml-cpu/ggml-cpu.c index f2ab4c5d69582..05d11d0ef818b 100644 --- a/ggml/src/ggml-cpu/ggml-cpu.c +++ b/ggml/src/ggml-cpu/ggml-cpu.c @@ -15398,6 +15398,9 @@ static struct ggml_threadpool * ggml_threadpool_new_impl( for (int j = 0; j < tpp->n_threads; j++) { workers[j].threadpool = threadpool; workers[j].ith = j; + memset(workers[j].cpumask, 0, GGML_MAX_N_THREADS); + //workers[j].cpumask[(j/3)*8+(j%3)*2]=1; + workers[j].cpumask[j*2] = 1; } threadpool->workers = workers; @@ -15412,15 +15415,15 @@ static struct ggml_threadpool * ggml_threadpool_new_impl( int32_t cpumask_iter = 0; for (int j = 1; j < tpp->n_threads; j++) { - ggml_thread_cpumask_next(tpp->cpumask, workers[j].cpumask, tpp->strict_cpu, &cpumask_iter); + //ggml_thread_cpumask_next(tpp->cpumask, workers[j].cpumask, tpp->strict_cpu, &cpumask_iter); int32_t rc = ggml_thread_create(&workers[j].thrd, NULL, ggml_graph_compute_secondary_thread, &workers[j]); GGML_ASSERT(rc == 0); } - ggml_thread_cpumask_next(tpp->cpumask, workers[0].cpumask, tpp->strict_cpu, &cpumask_iter); + //ggml_thread_cpumask_next(tpp->cpumask, workers[0].cpumask, tpp->strict_cpu, &cpumask_iter); - if (!threadpool->pause) { + if (true || !threadpool->pause) { // Update main thread prio and affinity at the start, otherwise we'll do it in resume ggml_thread_apply_priority(threadpool->prio); 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 #endif // don't leave affinity set on the main thread - clear_numa_thread_affinity(); + // clear_numa_thread_affinity(); enum ggml_status ret = threadpool->ec;