From c49d6340718be5a2b9d397bd3db21bba98d2c176 Mon Sep 17 00:00:00 2001 From: Max Krasnyansky Date: Wed, 28 Aug 2024 21:34:16 -0700 Subject: [PATCH] threadpool: use _new and _free instead of _create and _release --- examples/llama-bench/llama-bench.cpp | 4 ++-- examples/main/main.cpp | 8 ++++---- ggml/include/ggml.h | 6 +++--- ggml/src/ggml.c | 12 ++++++------ 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/examples/llama-bench/llama-bench.cpp b/examples/llama-bench/llama-bench.cpp index ff092cd59..8edadef90 100644 --- a/examples/llama-bench/llama-bench.cpp +++ b/examples/llama-bench/llama-bench.cpp @@ -1531,7 +1531,7 @@ int main(int argc, char ** argv) { tpp.poll = t.poll; tpp.prio = params.prio; - struct ggml_threadpool* threadpool = ggml_threadpool_create(&tpp); + struct ggml_threadpool* threadpool = ggml_threadpool_new(&tpp); if (!threadpool) { LOG_TEE("%s: threadpool create failed : n_threads %d\n", __func__, tpp.n_threads); exit(1); @@ -1578,7 +1578,7 @@ int main(int argc, char ** argv) { llama_free(ctx); - ggml_threadpool_release(threadpool); + ggml_threadpool_free(threadpool); } llama_free_model(lmodel); diff --git a/examples/main/main.cpp b/examples/main/main.cpp index 4d8b02801..2c05afb04 100644 --- a/examples/main/main.cpp +++ b/examples/main/main.cpp @@ -234,7 +234,7 @@ int main(int argc, char ** argv) { struct ggml_threadpool * threadpool_batch = NULL; if (!ggml_threadpool_params_match(&tpp, &tpp_batch)) { - threadpool_batch = ggml_threadpool_create(&tpp_batch); + threadpool_batch = ggml_threadpool_new(&tpp_batch); if (!threadpool_batch) { LOG_TEE("%s: batch threadpool create failed : n_threads %d\n", __func__, tpp_batch.n_threads); exit(1); @@ -244,7 +244,7 @@ int main(int argc, char ** argv) { tpp.paused = true; } - struct ggml_threadpool * threadpool = ggml_threadpool_create(&tpp); + struct ggml_threadpool * threadpool = ggml_threadpool_new(&tpp); if (!threadpool) { LOG_TEE("%s: threadpool create failed : n_threads %d\n", __func__, tpp.n_threads); exit(1); @@ -1023,8 +1023,8 @@ int main(int argc, char ** argv) { llama_sampling_free(ctx_sampling); llama_backend_free(); - ggml_threadpool_release(threadpool); - ggml_threadpool_release(threadpool_batch); + ggml_threadpool_free(threadpool); + ggml_threadpool_free(threadpool_batch); #ifndef LOG_DISABLE_LOGS LOG_TEE("Log end\n"); diff --git a/ggml/include/ggml.h b/ggml/include/ggml.h index 8b10e025a..94afc4d9a 100644 --- a/ggml/include/ggml.h +++ b/ggml/include/ggml.h @@ -2037,10 +2037,10 @@ extern "C" { GGML_API size_t ggml_graph_overhead_custom(size_t size, bool grads); GGML_API struct ggml_threadpool_params ggml_threadpool_params_default(int n_threads); - GGML_API void ggml_threadpool_params_init(struct ggml_threadpool_params *p, int n_threads); + GGML_API void ggml_threadpool_params_init (struct ggml_threadpool_params *p, int n_threads); GGML_API bool ggml_threadpool_params_match (const struct ggml_threadpool_params *p0, const struct ggml_threadpool_params *p1); - GGML_API struct ggml_threadpool* ggml_threadpool_create (struct ggml_threadpool_params * params); - GGML_API void ggml_threadpool_release (struct ggml_threadpool * threadpool); + GGML_API struct ggml_threadpool* ggml_threadpool_new (struct ggml_threadpool_params * params); + GGML_API void ggml_threadpool_free (struct ggml_threadpool * threadpool); GGML_API int ggml_threadpool_get_n_threads(struct ggml_threadpool * threadpool); GGML_API void ggml_threadpool_pause (struct ggml_threadpool * threadpool); GGML_API void ggml_threadpool_resume (struct ggml_threadpool * threadpool); diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c index c8f6152e5..45dca68d4 100644 --- a/ggml/src/ggml.c +++ b/ggml/src/ggml.c @@ -18837,7 +18837,7 @@ static void ggml_thread_cpumask_next(const bool * global_mask, bool * local_mask } } -void ggml_threadpool_release(struct ggml_threadpool* threadpool) { +void ggml_threadpool_free(struct ggml_threadpool* threadpool) { if (!threadpool) return; #ifndef GGML_USE_OPENMP @@ -19254,7 +19254,7 @@ bool ggml_threadpool_params_match(const struct ggml_threadpool_params * p0, cons return memcmp(p0->cpumask, p1->cpumask, GGML_MAX_N_THREADS) == 0; } -static struct ggml_threadpool * ggml_threadpool_create_impl( +static struct ggml_threadpool * ggml_threadpool_new_impl( struct ggml_threadpool_params * tpp, struct ggml_cgraph * cgraph, struct ggml_cplan * cplan) { @@ -19320,8 +19320,8 @@ static struct ggml_threadpool * ggml_threadpool_create_impl( return threadpool; } -struct ggml_threadpool * ggml_threadpool_create(struct ggml_threadpool_params * tpp) { - return ggml_threadpool_create_impl(tpp, NULL, NULL); +struct ggml_threadpool * ggml_threadpool_new(struct ggml_threadpool_params * tpp) { + return ggml_threadpool_new_impl(tpp, NULL, NULL); } enum ggml_status ggml_graph_compute(struct ggml_cgraph * cgraph, struct ggml_cplan * cplan) { @@ -19339,7 +19339,7 @@ enum ggml_status ggml_graph_compute(struct ggml_cgraph * cgraph, struct ggml_cpl disposable_threadpool = true; struct ggml_threadpool_params ttp = ggml_threadpool_params_default(n_threads); - threadpool = ggml_threadpool_create_impl(&ttp, cgraph, cplan); + threadpool = ggml_threadpool_new_impl(&ttp, cgraph, cplan); } else { // Reset some of the parameters that need resetting // No worker threads should be accessing the parameters below at this stage @@ -19384,7 +19384,7 @@ enum ggml_status ggml_graph_compute(struct ggml_cgraph * cgraph, struct ggml_cpl enum ggml_status ret = threadpool->ec; if (disposable_threadpool) { - ggml_threadpool_release(threadpool); + ggml_threadpool_free(threadpool); } return ret;