From 94ddd6204ce6e0c0f51adc50e9c3f8211f4038d2 Mon Sep 17 00:00:00 2001 From: Howard Su Date: Mon, 10 Apr 2023 22:37:37 +0800 Subject: [PATCH] Simplify the logic of scheduling --- ggml.c | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/ggml.c b/ggml.c index 3004e9932..c8a149645 100644 --- a/ggml.c +++ b/ggml.c @@ -9258,22 +9258,17 @@ struct ggml_compute_state { static void ggml_graph_compute_thread(void * data) { struct ggml_compute_state * state = (struct ggml_compute_state *) data; int type = state->params.type; - if (state->node) { - if (state->params.ith < state->params.nth) { - if (type == GGML_TASK_INIT) - { - state->params.type = GGML_TASK_INIT; - ggml_compute_forward(&state->params, state->node); - type = GGML_TASK_COMPUTE; - } + if (type == GGML_TASK_INIT) + { + state->params.type = GGML_TASK_INIT; + ggml_compute_forward(&state->params, state->node); + type = GGML_TASK_COMPUTE; + } - if (type == GGML_TASK_COMPUTE) - { - state->params.type = GGML_TASK_COMPUTE; - ggml_compute_forward(&state->params, state->node); - } - } - state->node = NULL; + if (type == GGML_TASK_COMPUTE) + { + state->params.type = GGML_TASK_COMPUTE; + ggml_compute_forward(&state->params, state->node); } } @@ -9284,18 +9279,6 @@ void ggml_graph_compute(struct ggml_context * ctx, struct ggml_cgraph * cgraph) // create thread pool ctx->tpool = thpool_init(n_threads); - for (int j = 0; j < n_threads - 1; j++) { - workers[j] = (struct ggml_compute_state) { - .params = { - .type = GGML_TASK_COMPUTE, - .ith = j + 1, - .nth = n_threads, - .wsize = cgraph->work ? ggml_nbytes(cgraph->work) : 0, - .wdata = cgraph->work ? cgraph->work->data : NULL, - }, - .node = NULL, - }; - } // initialize tasks + work buffer {