mirror of
				https://github.com/ggml-org/llama.cpp.git
				synced 2025-10-31 08:51:55 +00:00 
			
		
		
		
	ggml-cpu : fix ggml_graph_compute_thread did not terminate on abort. (ggml/1065)
some threads kept looping and failed to terminate properly after an abort during CPU execution. Co-authored-by: issi <issi@gmail.com>
This commit is contained in:
		| @@ -1302,7 +1302,7 @@ struct ggml_threadpool { | |||||||
|     // these are atomic as an annotation for thread-sanitizer |     // these are atomic as an annotation for thread-sanitizer | ||||||
|     atomic_bool stop;         // Used for stopping the threadpool altogether |     atomic_bool stop;         // Used for stopping the threadpool altogether | ||||||
|     atomic_bool pause;        // Used for pausing the threadpool or individual threads |     atomic_bool pause;        // Used for pausing the threadpool or individual threads | ||||||
|     atomic_bool abort;        // Used for aborting processing of a graph |     atomic_int abort;         // Used for aborting processing of a graph | ||||||
|  |  | ||||||
|     struct ggml_compute_state * workers;   // per thread state |     struct ggml_compute_state * workers;   // per thread state | ||||||
|     int          n_threads_max; // number of threads in the pool |     int          n_threads_max; // number of threads in the pool | ||||||
| @@ -13851,14 +13851,14 @@ static thread_ret_t ggml_graph_compute_thread(void * data) { | |||||||
|         /*.threadpool=*/ tp, |         /*.threadpool=*/ tp, | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     for (int node_n = 0; node_n < cgraph->n_nodes && !tp->abort; node_n++) { |     for (int node_n = 0; node_n < cgraph->n_nodes && atomic_load_explicit(&tp->abort, memory_order_relaxed) != node_n; node_n++) { | ||||||
|         struct ggml_tensor * node = cgraph->nodes[node_n]; |         struct ggml_tensor * node = cgraph->nodes[node_n]; | ||||||
|  |  | ||||||
|         ggml_compute_forward(¶ms, node); |         ggml_compute_forward(¶ms, node); | ||||||
|  |  | ||||||
|         if (state->ith == 0 && cplan->abort_callback && |         if (state->ith == 0 && cplan->abort_callback && | ||||||
|                 cplan->abort_callback(cplan->abort_callback_data)) { |                 cplan->abort_callback(cplan->abort_callback_data)) { | ||||||
|             tp->abort = true; |             atomic_store_explicit(&tp->abort, node_n + 1, memory_order_relaxed); | ||||||
|             tp->ec    = GGML_STATUS_ABORTED; |             tp->ec    = GGML_STATUS_ABORTED; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -14031,7 +14031,7 @@ static struct ggml_threadpool * ggml_threadpool_new_impl( | |||||||
|         threadpool->current_chunk    = 0; |         threadpool->current_chunk    = 0; | ||||||
|         threadpool->stop             = false; |         threadpool->stop             = false; | ||||||
|         threadpool->pause            = tpp->paused; |         threadpool->pause            = tpp->paused; | ||||||
|         threadpool->abort            = false; |         threadpool->abort            = -1; | ||||||
|         threadpool->workers          = NULL; |         threadpool->workers          = NULL; | ||||||
|         threadpool->n_threads_max    = tpp->n_threads; |         threadpool->n_threads_max    = tpp->n_threads; | ||||||
|         threadpool->n_threads_cur    = tpp->n_threads; |         threadpool->n_threads_cur    = tpp->n_threads; | ||||||
| @@ -14110,7 +14110,7 @@ enum ggml_status ggml_graph_compute(struct ggml_cgraph * cgraph, struct ggml_cpl | |||||||
|         threadpool->cgraph           = cgraph; |         threadpool->cgraph           = cgraph; | ||||||
|         threadpool->cplan            = cplan; |         threadpool->cplan            = cplan; | ||||||
|         threadpool->current_chunk    = 0; |         threadpool->current_chunk    = 0; | ||||||
|         threadpool->abort            = false; |         threadpool->abort            = -1; | ||||||
|         threadpool->ec               = GGML_STATUS_SUCCESS; |         threadpool->ec               = GGML_STATUS_SUCCESS; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 issixx
					issixx