From 09a6325de56856490ae9046bf0030ceedc04028a Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Tue, 12 Sep 2023 13:33:09 +0300 Subject: [PATCH] ggml : use sched_yield when using BLAS + add comment --- ggml.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ggml.c b/ggml.c index 3f72379c..dcdebd24 100644 --- a/ggml.c +++ b/ggml.c @@ -17283,10 +17283,18 @@ static thread_ret_t ggml_graph_compute_thread(void * data) { } else { // wait for other threads to finish const int last = node_n; - do { - //sched_yield(); + while (true) { + // TODO: this sched_yield can have significant impact on the performance - either positive or negative + // depending on the workload and the operating system. + // since it is not clear what is the best approach, it should potentially become user-configurable + // ref: https://github.com/ggerganov/ggml/issues/291 +#if defined(GGML_USE_ACCELERATE) || defined(GGML_USE_OPENBLAS) + sched_yield(); +#endif + node_n = atomic_load(&state->shared->node_n); - } while (node_n == last); + if (node_n != last) break; + }; } // check if we should stop