added in some __ANDROID__ if def gates around numa code and forced GLIBC prior to 2.29 to use a syscall for getcpu instead of the wrapper
This commit is contained in:
parent
2890de4ecf
commit
458bd9b7f5
1 changed files with 15 additions and 6 deletions
21
ggml.c
21
ggml.c
|
@ -23,6 +23,9 @@
|
|||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
#include <signal.h>
|
||||
#if defined(__GLIBC__)
|
||||
#include <syscall.h>
|
||||
#endif
|
||||
|
||||
#ifdef GGML_USE_METAL
|
||||
#include <unistd.h>
|
||||
|
@ -1959,7 +1962,7 @@ struct ggml_numa_nodes {
|
|||
uint32_t n_nodes;
|
||||
uint32_t total_cpus; // hardware threads on system
|
||||
uint32_t current_node; // node on which main process is execting
|
||||
#if defined(__linux__) && !defined(__BIONIC__)
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
cpu_set_t cpuset; // cpuset from numactl
|
||||
#else
|
||||
uint32_t cpuset; // no NUMA support outside of Linux at this time. Use a portable datatype
|
||||
|
@ -1997,7 +2000,7 @@ inline static void ggml_critical_section_end(void) {
|
|||
atomic_fetch_sub(&g_state_barrier, 1);
|
||||
}
|
||||
|
||||
#if defined(__linux__) && !defined(__BIONIC__)
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
static cpu_set_t ggml_get_numa_affinity(void) {
|
||||
cpu_set_t cpuset;
|
||||
pthread_t thread;
|
||||
|
@ -2019,7 +2022,7 @@ void ggml_numa_init(enum ggml_numa_strategy numa_flag) {
|
|||
return;
|
||||
}
|
||||
|
||||
#if defined(__linux__) && !defined(__BIONIC__)
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
struct stat st;
|
||||
char path[256];
|
||||
int rv;
|
||||
|
@ -2051,9 +2054,15 @@ void ggml_numa_init(enum ggml_numa_strategy numa_flag) {
|
|||
|
||||
// figure out which node we're on
|
||||
uint current_cpu;
|
||||
int getcpu_ret = getcpu(¤t_cpu, &g_state.numa.current_node);
|
||||
int getcpu_ret = 0;
|
||||
#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 28)
|
||||
getcpu_ret = getcpu(¤t_cpu, &g_state.numa.current_node);
|
||||
#else
|
||||
// old glibc doesn't have a wrapper for this call. Fall back on direct syscall
|
||||
getcpu_ret = syscall(SYS_getcpu,¤t_cpu,&g_state.numa.current_node);
|
||||
#endif
|
||||
|
||||
if (g_state.numa.n_nodes < 1 || g_state.numa.total_cpus < 1 || getcpu_ret != 0) {
|
||||
if (g_state.numa.n_nodes < 1 || g_state.numa.total_cpus < 1 || getcpu_ret != 0 ) {
|
||||
g_state.numa.n_nodes = 0;
|
||||
return;
|
||||
}
|
||||
|
@ -16713,7 +16722,7 @@ typedef pthread_t ggml_thread_t;
|
|||
#endif
|
||||
|
||||
// Android's libc implementation "bionic" does not support setting affinity
|
||||
#if defined(__linux__) && !defined(__BIONIC__)
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
static void set_numa_thread_affinity(int thread_n) {
|
||||
if (!ggml_is_numa()) {
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue