@@ -18872,14 +18872,27 @@ void ggml_release_threadpool(struct ggml_compute_threadpool* threadpool) {
18872
18872
GGML_ALIGNED_FREE(threadpool);
18873
18873
}
18874
18874
18875
+ #ifndef GGML_USE_OPENMP
18876
+ // pause/resume must be called under mutex
18877
+ static void __ggml_pause_threadpool(struct ggml_compute_threadpool * threadpool) {
18878
+ GGML_PRINT_DEBUG("Pausing threadpool\n");
18879
+ threadpool->pause = true;
18880
+ ggml_cond_broadcast(&threadpool->cond);
18881
+ }
18882
+
18883
+ static void __ggml_resume_threadpool(struct ggml_compute_threadpool * threadpool) {
18884
+ GGML_PRINT_DEBUG("Resuming threadpool\n");
18885
+ threadpool->pause = false;
18886
+ ggml_cond_broadcast(&threadpool->cond);
18887
+ }
18888
+ #endif
18889
+
18875
18890
void ggml_pause_threadpool(struct ggml_compute_threadpool * threadpool) {
18876
18891
#ifndef GGML_USE_OPENMP
18877
18892
GGML_ASSERT(!threadpool->disposable);
18878
- GGML_PRINT_DEBUG("Pausing threadpool\n");
18879
18893
ggml_mutex_lock(&threadpool->mutex);
18880
18894
if (!threadpool->pause) {
18881
- threadpool->pause = true;
18882
- ggml_cond_broadcast(&threadpool->cond);
18895
+ __ggml_pause_threadpool(threadpool);
18883
18896
}
18884
18897
ggml_mutex_unlock(&threadpool->mutex);
18885
18898
#else
@@ -18890,12 +18903,9 @@ void ggml_pause_threadpool(struct ggml_compute_threadpool * threadpool) {
18890
18903
void ggml_resume_threadpool(struct ggml_compute_threadpool * threadpool) {
18891
18904
#ifndef GGML_USE_OPENMP
18892
18905
GGML_ASSERT(!threadpool->disposable);
18893
- GGML_PRINT_DEBUG("Resuming threadpool\n");
18894
-
18895
18906
ggml_mutex_lock(&threadpool->mutex);
18896
18907
if (threadpool->pause) {
18897
- threadpool->pause = false;
18898
- ggml_cond_broadcast(&threadpool->cond);
18908
+ __ggml_resume_threadpool(threadpool);
18899
18909
}
18900
18910
ggml_mutex_unlock(&threadpool->mutex);
18901
18911
#else
@@ -19237,7 +19247,7 @@ static struct ggml_compute_threadpool * ggml_create_threadpool_impl(
19237
19247
threadpool->n_barrier_passed = 0;
19238
19248
threadpool->current_chunk = 0;
19239
19249
threadpool->stop = false;
19240
- threadpool->pause = disposable ? false : true ;
19250
+ threadpool->pause = disposable ? false : tpp->paused ;
19241
19251
threadpool->new_work = false;
19242
19252
threadpool->workers = NULL;
19243
19253
threadpool->n_threads_max = tpp->n_threads;
@@ -19327,9 +19337,10 @@ enum ggml_status ggml_graph_compute(struct ggml_cgraph * cgraph, struct ggml_cpl
19327
19337
struct ggml_threadpool_params ttp = {
19328
19338
.mask_specified = false,
19329
19339
.n_threads = n_threads,
19330
- .prio = 1 ,
19340
+ .prio = 0 ,
19331
19341
.poll = false,
19332
- .strict_cpu = false
19342
+ .strict_cpu = false,
19343
+ .paused = false
19333
19344
};
19334
19345
19335
19346
threadpool = ggml_create_threadpool_impl(&ttp, true, cgraph, cplan);
@@ -19383,10 +19394,19 @@ enum ggml_status ggml_graph_compute(struct ggml_cgraph * cgraph, struct ggml_cpl
19383
19394
if (!threadpool->poll) {
19384
19395
ggml_mutex_lock(&threadpool->mutex);
19385
19396
threadpool->new_work = true;
19386
- ggml_cond_broadcast(&threadpool->cond);
19397
+ if (threadpool->pause) {
19398
+ __ggml_resume_threadpool(threadpool);
19399
+ } else {
19400
+ ggml_cond_broadcast(&threadpool->cond);
19401
+ }
19387
19402
ggml_mutex_unlock(&threadpool->mutex);
19388
19403
} else {
19389
19404
threadpool->new_work = true;
19405
+ if (threadpool->pause) {
19406
+ ggml_mutex_lock(&threadpool->mutex);
19407
+ __ggml_resume_threadpool(threadpool);
19408
+ ggml_mutex_unlock(&threadpool->mutex);
19409
+ }
19390
19410
}
19391
19411
}
19392
19412
// this is a work thread too
0 commit comments