Skip to content

Commit

Permalink
fix deadlock for cases where cgraph.n_nodes == 1
Browse files Browse the repository at this point in the history
and fix --poll case
  • Loading branch information
fmz authored and fmz committed Jul 31, 2024
1 parent 8a39d75 commit bebe99c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ggml/src/ggml.c
Original file line number Diff line number Diff line change
Expand Up @@ -19169,7 +19169,14 @@ static thread_ret_t ggml_graph_compute_thread(void * data) {
}
}

if (cgraph->n_nodes == 1) {
// We need a barrier before disabling new_work in case we have a trivial graph
ggml_barrier(state->threadpool);
}

if (!state->threadpool->disposable && state->ith == 0) {
// Don't need a lock, because there is a barrier after this, and only after that
// do the secondary threads go into standby
state->threadpool->new_work = false;
}

Expand Down Expand Up @@ -19411,6 +19418,8 @@ enum ggml_status ggml_graph_compute(struct ggml_cgraph * cgraph, struct ggml_cpl
threadpool->new_work = true;
ggml_cond_broadcast(&threadpool->cond);
ggml_mutex_unlock(&threadpool->mutex);
} else {
threadpool->new_work = true;
}
}
// this is a work thread too
Expand Down

0 comments on commit bebe99c

Please sign in to comment.