Skip to content

Commit c05312d

Browse files
fmzfmz
authored and
fmz
committed
fix deadlock for cases where cgraph.n_nodes == 1
and fix --poll case
1 parent 0bb4bca commit c05312d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

ggml/src/ggml.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19190,7 +19190,14 @@ static thread_ret_t ggml_graph_compute_thread(void * data) {
1919019190
}
1919119191
}
1919219192

19193+
if (cgraph->n_nodes == 1) {
19194+
// We need a barrier before disabling new_work in case we have a trivial graph
19195+
ggml_barrier(state->threadpool);
19196+
}
19197+
1919319198
if (!state->threadpool->disposable && state->ith == 0) {
19199+
// Don't need a lock, because there is a barrier after this, and only after that
19200+
// do the secondary threads go into standby
1919419201
state->threadpool->new_work = false;
1919519202
}
1919619203

@@ -19432,6 +19439,8 @@ enum ggml_status ggml_graph_compute(struct ggml_cgraph * cgraph, struct ggml_cpl
1943219439
threadpool->new_work = true;
1943319440
ggml_cond_broadcast(&threadpool->cond);
1943419441
ggml_mutex_unlock(&threadpool->mutex);
19442+
} else {
19443+
threadpool->new_work = true;
1943519444
}
1943619445
}
1943719446
// this is a work thread too

0 commit comments

Comments
 (0)