aboutsummaryrefslogtreecommitdiff
path: root/pplx_embed.c
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-05-24 01:15:34 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-06-14 08:18:59 +0200
commit594324fc44ca62682cac930477abdf3dce94da69 (patch)
tree80e3751e70690d5b9262715a2d3c036e948c9e5e /pplx_embed.c
parentc5a1b660ac1b74e274cf14474e7a8850ec1d1af0 (diff)
downloadffwd-594324fc44ca62682cac930477abdf3dce94da69.tar.gz
ffwd-594324fc44ca62682cac930477abdf3dce94da69.zip
cpu: tighten workspace growth
Diffstat (limited to 'pplx_embed.c')
-rw-r--r--pplx_embed.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/pplx_embed.c b/pplx_embed.c
index d007dce..32ea1e2 100644
--- a/pplx_embed.c
+++ b/pplx_embed.c
@@ -68,6 +68,7 @@ int qwen_verbose = 0;
#define PPLX_BF16_QKV_FUSE_MAX_SEQ 16
#define PPLX_BF16_PAIR_FUSE_MAX_SEQ 4
#define PPLX_MIN_WORKSPACE_SEQ_CAP 16
+#define PPLX_WORKSPACE_SEQ_GRANULARITY 16
/* ========================================================================
* Size helpers
@@ -91,11 +92,20 @@ static int grow_cap(int current, int needed, int *out)
{
if (needed <= 0) return -1;
- int cap = current > 0 ? current : PPLX_MIN_WORKSPACE_SEQ_CAP;
- while (cap < needed) {
- if (cap > INT_MAX / 2) return -1;
- cap *= 2;
+ int cap = needed;
+ if (cap < PPLX_MIN_WORKSPACE_SEQ_CAP)
+ cap = PPLX_MIN_WORKSPACE_SEQ_CAP;
+
+ int rem = cap % PPLX_WORKSPACE_SEQ_GRANULARITY;
+ if (rem != 0) {
+ int add = PPLX_WORKSPACE_SEQ_GRANULARITY - rem;
+ if (cap > INT_MAX - add) return -1;
+ cap += add;
}
+
+ if (cap < current)
+ cap = current;
+
*out = cap;
return 0;
}