From 87d31e9662802ff1ab22c66fa3d461787132d4a3 Mon Sep 17 00:00:00 2001 From: Xuan Son Nguyen Date: Fri, 6 Sep 2024 16:15:27 +0200 Subject: [PATCH 1/3] ggml : fix missing cpu_set_t on emscripten --- ggml/src/ggml.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c index c98ca32bd45bf..cdd5ebee4616f 100644 --- a/ggml/src/ggml.c +++ b/ggml/src/ggml.c @@ -19556,7 +19556,8 @@ static bool ggml_thread_apply_priority(int32_t prio) { return true; } -#else // posix? +#elif ((defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)) && !defined(__EMSCRIPTEN__)) +// TODO: this may not work on BSD, to be verified static bool ggml_thread_apply_affinity(const bool * mask) { cpu_set_t cpuset; @@ -19611,6 +19612,18 @@ static bool ggml_thread_apply_priority(int32_t prio) { return true; } +#else // unsupported platforms + +static bool ggml_thread_apply_affinity(const bool * mask) { + UNUSED(mask); + return true; +} + +static bool ggml_thread_apply_priority(int32_t prio) { + UNUSED(prio); + return true; +} + #endif static bool ggml_thread_cpumask_is_valid(const bool * mask) { From c4a1276ba73697aff02f7cd3d958d5c8f302714b Mon Sep 17 00:00:00 2001 From: Xuan Son Nguyen Date: Fri, 6 Sep 2024 16:23:29 +0200 Subject: [PATCH 2/3] better version --- ggml/src/ggml.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c index cdd5ebee4616f..8764632cf6247 100644 --- a/ggml/src/ggml.c +++ b/ggml/src/ggml.c @@ -19556,7 +19556,7 @@ static bool ggml_thread_apply_priority(int32_t prio) { return true; } -#elif ((defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)) && !defined(__EMSCRIPTEN__)) +#elif (defined(__gnu_linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)) // TODO: this may not work on BSD, to be verified static bool ggml_thread_apply_affinity(const bool * mask) { @@ -19572,14 +19572,7 @@ static bool ggml_thread_apply_affinity(const bool * mask) { } } -#ifdef __ANDROID__ - err = sched_setaffinity(0, sizeof(cpuset), &cpuset); - if (err < 0) { - err = errno; - } -#else err = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset); -#endif if (err != 0) { fprintf(stderr, "warn: failed to set affinity mask 0x%llx : %s (%d)\n", (unsigned long long)mask, strerror(err), err); return false; From 89e70fe3ae985b63f5ebc9b5f47848d1b53d3f2e Mon Sep 17 00:00:00 2001 From: Xuan Son Nguyen Date: Fri, 6 Sep 2024 17:58:21 +0200 Subject: [PATCH 3/3] bring back android part --- ggml/src/ggml.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c index 8764632cf6247..9dc12a0207921 100644 --- a/ggml/src/ggml.c +++ b/ggml/src/ggml.c @@ -19556,7 +19556,7 @@ static bool ggml_thread_apply_priority(int32_t prio) { return true; } -#elif (defined(__gnu_linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)) +#elif defined(__gnu_linux__) // TODO: this may not work on BSD, to be verified static bool ggml_thread_apply_affinity(const bool * mask) { @@ -19572,7 +19572,14 @@ static bool ggml_thread_apply_affinity(const bool * mask) { } } +#ifdef __ANDROID__ + err = sched_setaffinity(0, sizeof(cpuset), &cpuset); + if (err < 0) { + err = errno; + } +#else err = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset); +#endif if (err != 0) { fprintf(stderr, "warn: failed to set affinity mask 0x%llx : %s (%d)\n", (unsigned long long)mask, strerror(err), err); return false;