| 16525 | // Android's libc implementation "bionic" does not support setting affinity |
| 16526 | #if defined(__linux__) && !defined(__BIONIC__) |
| 16527 | static void set_numa_thread_affinity(int thread_n, int n_threads) { |
| 16528 | if (!ggml_is_numa()) { |
| 16529 | return; |
| 16530 | } |
| 16531 | |
| 16532 | // run thread on node_num thread_n / (threads per node) |
| 16533 | const int node_num = thread_n / ((n_threads + g_state.numa.n_nodes - 1) / g_state.numa.n_nodes); |
| 16534 | struct ggml_numa_node * node = &g_state.numa.nodes[node_num]; |
| 16535 | size_t setsize = CPU_ALLOC_SIZE(g_state.numa.total_cpus); |
| 16536 | |
| 16537 | cpu_set_t * cpus = CPU_ALLOC(g_state.numa.total_cpus); |
| 16538 | CPU_ZERO_S(setsize, cpus); |
| 16539 | for (size_t i = 0; i < node->n_cpus; ++i) { |
| 16540 | CPU_SET_S(node->cpus[i], setsize, cpus); |
| 16541 | } |
| 16542 | |
| 16543 | int rv = pthread_setaffinity_np(pthread_self(), setsize, cpus); |
| 16544 | if (rv) { |
| 16545 | fprintf(stderr, "warning: pthread_setaffinity_np() failed: %s\n", |
| 16546 | strerror(rv)); |
| 16547 | } |
| 16548 | |
| 16549 | CPU_FREE(cpus); |
| 16550 | } |
| 16551 | |
| 16552 | static void clear_numa_thread_affinity(void) { |
| 16553 | if (!ggml_is_numa()) { |
no test coverage detected