@@ -2013,6 +2013,7 @@ struct ggml_threadpool {
2013
2013
// these are atomic as an annotation for thread-sanitizer
2014
2014
atomic_bool stop; // Used for stopping the threadpool altogether
2015
2015
atomic_bool pause; // Used for pausing the threadpool or individual threads
2016
+ atomic_bool abort; // Used for aborting processing of a graph
2016
2017
2017
2018
struct ggml_compute_state * workers; // per thread state
2018
2019
int n_threads_max; // number of threads in the pool
@@ -19928,34 +19929,33 @@ struct ggml_cplan ggml_graph_plan(
19928
19929
19929
19930
static thread_ret_t ggml_graph_compute_thread(void * data) {
19930
19931
struct ggml_compute_state * state = (struct ggml_compute_state *) data;
19932
+ struct ggml_threadpool * tp = state->threadpool;
19931
19933
19932
- const struct ggml_cgraph * cgraph = state->threadpool ->cgraph;
19933
- const struct ggml_cplan * cplan = state->threadpool ->cplan;
19934
+ const struct ggml_cgraph * cgraph = tp ->cgraph;
19935
+ const struct ggml_cplan * cplan = tp ->cplan;
19934
19936
19935
19937
set_numa_thread_affinity(state->ith);
19936
19938
19937
19939
struct ggml_compute_params params = {
19938
19940
/*.ith =*/ state->ith,
19939
- /*.nth =*/ state->threadpool-> n_threads_cur,
19941
+ /*.nth =*/ atomic_load_explicit(&tp-> n_threads_cur, memory_order_relaxed) ,
19940
19942
/*.wsize =*/ cplan->work_size,
19941
19943
/*.wdata =*/ cplan->work_data,
19942
- /*.threadpool=*/ state->threadpool ,
19944
+ /*.threadpool=*/ tp ,
19943
19945
};
19944
19946
19945
- for (int node_n = 0; node_n < cgraph->n_nodes; node_n++) {
19947
+ for (int node_n = 0; node_n < cgraph->n_nodes && !tp->abort ; node_n++) {
19946
19948
struct ggml_tensor * node = cgraph->nodes[node_n];
19947
19949
19948
19950
ggml_compute_forward(¶ms, node);
19949
19951
19950
- if (state->ith == 0 && cplan->abort_callback && cplan->abort_callback(cplan->abort_callback_data)) {
19951
- state->threadpool->ec = GGML_STATUS_ABORTED;
19952
+ if (state->ith == 0 && cplan->abort_callback &&
19953
+ cplan->abort_callback(cplan->abort_callback_data)) {
19954
+ tp->abort = true;
19955
+ tp->ec = GGML_STATUS_ABORTED;
19952
19956
}
19953
19957
19954
19958
ggml_barrier(state->threadpool);
19955
-
19956
- if (state->threadpool->ec != GGML_STATUS_SUCCESS) {
19957
- break;
19958
- }
19959
19959
}
19960
19960
19961
19961
return 0;
@@ -20144,6 +20144,7 @@ static struct ggml_threadpool * ggml_threadpool_new_impl(
20144
20144
threadpool->current_chunk = 0;
20145
20145
threadpool->stop = false;
20146
20146
threadpool->pause = tpp->paused;
20147
+ threadpool->abort = false;
20147
20148
threadpool->workers = NULL;
20148
20149
threadpool->n_threads_max = tpp->n_threads;
20149
20150
threadpool->n_threads_cur = tpp->n_threads;
@@ -20220,6 +20221,7 @@ enum ggml_status ggml_graph_compute(struct ggml_cgraph * cgraph, struct ggml_cpl
20220
20221
threadpool->cgraph = cgraph;
20221
20222
threadpool->cplan = cplan;
20222
20223
threadpool->current_chunk = 0;
20224
+ threadpool->abort = false;
20223
20225
threadpool->ec = GGML_STATUS_SUCCESS;
20224
20226
}
20225
20227
0 commit comments