Skip to content

Commit f86568f

Browse files
committed
auto numa selection and mem binding
1 parent af59981 commit f86568f

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15210,13 +15210,6 @@ static thread_ret_t ggml_graph_compute_thread(void * data) {
1521015210
#ifdef GGML_NUMA_MIRROR
1521115211
if (GGML_UNLIKELY(ggml_current_numa_node == -1)) {
1521215212
int thread_id = state->ith;
15213-
int total_threads = tp->n_threads_max;
15214-
15215-
ggml_current_numa_node = !!!(thread_id < (total_threads / 2));
15216-
15217-
struct bitmask* mask = numa_bitmask_alloc(numa_num_configured_nodes());
15218-
numa_bitmask_setbit(mask, ggml_current_numa_node);
15219-
numa_bind(mask);
1522015213

1522115214
bool cpumask[GGML_MAX_N_THREADS];
1522215215
memset(cpumask, 0, sizeof(bool) * GGML_MAX_N_THREADS);
@@ -15248,6 +15241,14 @@ static thread_ret_t ggml_graph_compute_thread(void * data) {
1524815241
sched_setaffinity(gettid(), sizeof(cpuset), &cpuset);
1524915242
}
1525015243

15244+
unsigned int numa_node = 0;
15245+
getcpu(NULL, &numa_node);
15246+
ggml_current_numa_node = numa_node;
15247+
15248+
struct bitmask* mask = numa_bitmask_alloc(numa_num_configured_nodes());
15249+
numa_bitmask_setbit(mask, ggml_current_numa_node);
15250+
numa_set_membind(mask);
15251+
1525115252
GGML_LOG_INFO("thread_id = %02d, node = %d, cpuid = %02d\n", thread_id, ggml_current_numa_node, cpuid);
1525215253
}
1525315254
#endif // GGML_NUMA_MIRROR

0 commit comments

Comments
 (0)