Avoid INIT synchronization barrier when possible
This change makes inference go ~5% faster for me.
This commit is contained in:
parent
7deec14bd9
commit
8435ab0ae8
1 changed files with 15 additions and 13 deletions
28
ggml.c
28
ggml.c
|
@ -20013,19 +20013,21 @@ static thread_ret_t ggml_graph_compute_thread(void * data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (atomic_fetch_sub(&state->shared->n_active, 1) == 1) {
|
if (GGML_OP_HAS_INIT[node->op]) {
|
||||||
task_phase = GGML_TASK_TYPE_COMPUTE;
|
if (atomic_fetch_sub(&state->shared->n_active, 1) == 1) {
|
||||||
atomic_store(&state->shared->n_active, n_threads);
|
task_phase = GGML_TASK_TYPE_COMPUTE;
|
||||||
atomic_store(&state->shared->node_task, task_phase);
|
atomic_store(&state->shared->n_active, n_threads);
|
||||||
}
|
atomic_store(&state->shared->node_task, task_phase);
|
||||||
else {
|
}
|
||||||
// TODO: this sched_yield can have significant impact on the performance - either positive or negative
|
else {
|
||||||
// depending on the workload and the operating system.
|
// TODO: this sched_yield can have significant impact on the performance - either positive or negative
|
||||||
// since it is not clear what is the best approach, it should potentially become user-configurable
|
// depending on the workload and the operating system.
|
||||||
// ref: https://github.com/ggerganov/ggml/issues/291
|
// since it is not clear what is the best approach, it should potentially become user-configurable
|
||||||
// UPD: adding the do_yield flag seems to resolve the issue universally
|
// ref: https://github.com/ggerganov/ggml/issues/291
|
||||||
const bool do_yield = node_n < 0 || cgraph->nodes[node_n]->op == GGML_OP_MUL_MAT;
|
// UPD: adding the do_yield flag seems to resolve the issue universally
|
||||||
ggml_graph_compute_thread_sync_task(&task_phase, state, do_yield);
|
const bool do_yield = node_n < 0 || cgraph->nodes[node_n]->op == GGML_OP_MUL_MAT;
|
||||||
|
ggml_graph_compute_thread_sync_task(&task_phase, state, do_yield);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state->ith < n_tasks) {
|
if (state->ith < n_tasks) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue