From 2299b0a5f515315e862a3a855a39224164d4efb1 Mon Sep 17 00:00:00 2001 From: Olaf Seibert Date: Wed, 12 Apr 2023 20:37:41 +0200 Subject: [PATCH] Use VLAs instead of alloca, if possible. --- ggml.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ggml.c b/ggml.c index acdba0333..b7f5688d7 100644 --- a/ggml.c +++ b/ggml.c @@ -3,11 +3,13 @@ #include "ggml.h" +#if __STDC_NO_VLA__ #if defined(_MSC_VER) || defined(__MINGW32__) #include // using malloc.h with MSC/MINGW #elif !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) #include #endif +#endif /* __STDC_NO_VLA__ */ #include #include @@ -10362,7 +10364,11 @@ void ggml_graph_compute(struct ggml_context * ctx, struct ggml_cgraph * cgraph) /*.has_work =*/ false, /*.stop =*/ false, }; +#if __STDC_NO_VLA__ struct ggml_compute_state * workers = n_threads > 1 ? alloca(sizeof(struct ggml_compute_state)*(n_threads - 1)) : NULL; +#else + struct ggml_compute_state workers[n_threads]; +#endif // create thread pool if (n_threads > 1) { @@ -11374,7 +11380,11 @@ static enum ggml_opt_result ggml_opt_lbfgs( ggml_opt_get_params(np, ps, x); // the L-BFGS memory +#if __STDC_NO_VLA__ struct ggml_lbfgs_iteration_data * lm = alloca(sizeof(struct ggml_lbfgs_iteration_data)*m); +#else + struct ggml_lbfgs_iteration_data lm[m]; +#endif for (int i = 0; i < m; ++i) { lm[i].alpha = 0.0f;