From 1c55fd6b0ed50616aac4a21a6187b871abc83e66 Mon Sep 17 00:00:00 2001 From: slaren Date: Sat, 24 May 2025 21:24:43 +0200 Subject: [PATCH 1/2] ggml-cpu : set openmp wait policy to active if not set --- ggml/src/ggml-cpu/ggml-cpu.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ggml/src/ggml-cpu/ggml-cpu.c b/ggml/src/ggml-cpu/ggml-cpu.c index 46f75ad97cd61..bfdc020bb922c 100644 --- a/ggml/src/ggml-cpu/ggml-cpu.c +++ b/ggml/src/ggml-cpu/ggml-cpu.c @@ -3484,6 +3484,12 @@ void ggml_cpu_init(void) { const uint64_t t_end = ggml_time_us(); UNUSED(t_end); GGML_PRINT_DEBUG("%s: GELU, Quick GELU, SILU and EXP tables initialized in %f ms\n", __func__, (t_end - t_start)/1000.0); + +#ifdef GGML_USE_OPENMP + if (!getenv("OMP_WAIT_POLICY")) { + putenv("OMP_WAIT_POLICY=active"); + } +#endif } #if defined(__ARM_ARCH) From 9f85363331b771bdfe717a58caa21ae6a2c83ad5 Mon Sep 17 00:00:00 2001 From: slaren Date: Sat, 24 May 2025 21:46:58 +0200 Subject: [PATCH 2/2] set KMP_BLOCKTIME instead --- ggml/src/ggml-cpu/ggml-cpu.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ggml/src/ggml-cpu/ggml-cpu.c b/ggml/src/ggml-cpu/ggml-cpu.c index bfdc020bb922c..aa51dc21a5de4 100644 --- a/ggml/src/ggml-cpu/ggml-cpu.c +++ b/ggml/src/ggml-cpu/ggml-cpu.c @@ -3486,8 +3486,15 @@ void ggml_cpu_init(void) { GGML_PRINT_DEBUG("%s: GELU, Quick GELU, SILU and EXP tables initialized in %f ms\n", __func__, (t_end - t_start)/1000.0); #ifdef GGML_USE_OPENMP - if (!getenv("OMP_WAIT_POLICY")) { - putenv("OMP_WAIT_POLICY=active"); + //if (!getenv("OMP_WAIT_POLICY")) { + // // set the wait policy to active, so that OpenMP threads don't sleep + // putenv("OMP_WAIT_POLICY=active"); + //} + + if (!getenv("KMP_BLOCKTIME")) { + // set the time to wait before sleeping a thread + // this is less aggressive than setting the wait policy to active, but should achieve similar results in most cases + putenv("KMP_BLOCKTIME=200"); // 200ms } #endif }