From 0260aa67fcc492e27f4fb75f3e8c3e573fb72d68 Mon Sep 17 00:00:00 2001 From: Olaf Seibert Date: Wed, 12 Apr 2023 16:35:23 +0200 Subject: [PATCH] Eliminate alloca from ggml_graph_compute() It has only 1 exit point (at the end), so adding a single free() is enough. --- ggml.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ggml.c b/ggml.c index a26b4853f..f5f39a644 100644 --- a/ggml.c +++ b/ggml.c @@ -9464,7 +9464,7 @@ void ggml_graph_compute(struct ggml_context * ctx, struct ggml_cgraph * cgraph) /*.has_work =*/ false, /*.stop =*/ false, }; - struct ggml_compute_state * workers = n_threads > 1 ? alloca(sizeof(struct ggml_compute_state)*(n_threads - 1)) : NULL; + struct ggml_compute_state * workers = n_threads > 1 ? malloc(sizeof(struct ggml_compute_state)*(n_threads - 1)) : NULL; // create thread pool if (n_threads > 1) { @@ -9876,6 +9876,8 @@ void ggml_graph_compute(struct ggml_context * ctx, struct ggml_cgraph * cgraph) (double) perf_time_us_cur / 1000.0, (double) cgraph->perf_time_us / 1000.0 / cgraph->perf_runs); } + + free(workers); } void ggml_graph_reset(struct ggml_cgraph * cgraph) {