From 6b969d25ce136eaf695222bd1a10bff1ecac0220 Mon Sep 17 00:00:00 2001 From: Onur Gündüz Date: Sat, 20 Jun 2026 20:10:56 +0200 Subject: all: split Makefile and reorg library/tools --- libffwd/threadpool.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 libffwd/threadpool.h (limited to 'libffwd/threadpool.h') diff --git a/libffwd/threadpool.h b/libffwd/threadpool.h new file mode 100644 index 0000000..1dcc80a --- /dev/null +++ b/libffwd/threadpool.h @@ -0,0 +1,28 @@ +#ifndef TP_THREADPOOL_H +#define TP_THREADPOOL_H + +/* Persistent worker pool for the CPU math kernels: a fixed set of threads that + * sleep until parallel_for() hands them a callback, plus the CPU-count helper + * that sizes the pool (cgroup-quota aware). Separated from the math so the + * kernels depend only on the parallel_for / tp_num_threads interface, not on + * the pool's internals. kernels.h includes this, so kernel callers need no + * extra include. */ + +/* Worker callback: (thread index, total threads, user arg). */ +typedef void (*parallel_fn_t)(int tid, int n_threads, void *arg); + +/* Set the persistent pool size (default 1). Creates/rebuilds the pool; call + * before inference. */ +void tp_set_threads(int n); + +/* Available CPU cores, capped to a cgroup CPU quota when one is tighter. */ +int tp_get_num_cpus(void); + +/* Current pool size (1 == serial). Kernels gate parallelism on this. */ +int tp_num_threads(void); + +/* Run fn across the pool; the calling thread participates as tid 0. Blocks + * until every worker has finished. */ +void parallel_for(parallel_fn_t fn, void *arg); + +#endif /* TP_THREADPOOL_H */ -- cgit v1.3.1