Skip to content

Commit bebe99c

Browse files
fmzfmz
authored and
fmz
committed
fix deadlock for cases where cgraph.n_nodes == 1
and fix --poll case
1 parent 8a39d75 commit bebe99c

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
@@ -19169,7 +19169,14 @@ static thread_ret_t ggml_graph_compute_thread(void * data) {
1916919169
}
1917019170
}
1917119171

19172+
if (cgraph->n_nodes == 1) {
19173+
// We need a barrier before disabling new_work in case we have a trivial graph
19174+
ggml_barrier(state->threadpool);
19175+
}
19176+
1917219177
if (!state->threadpool->disposable && state->ith == 0) {
19178+
// Don't need a lock, because there is a barrier after this, and only after that
19179+
// do the secondary threads go into standby
1917319180
state->threadpool->new_work = false;
1917419181
}
1917519182

@@ -19411,6 +19418,8 @@ enum ggml_status ggml_graph_compute(struct ggml_cgraph * cgraph, struct ggml_cpl
1941119418
threadpool->new_work = true;
1941219419
ggml_cond_broadcast(&threadpool->cond);
1941319420
ggml_mutex_unlock(&threadpool->mutex);
19421+
} else {
19422+
threadpool->new_work = true;
1941419423
}
1941519424
}
1941619425
// this is a work thread too

0 commit comments

Comments
 (0)