prefill: reuse embedding storage for half outputs

This commit is contained in:
W1nge authored and Niko1221 committed 2026-10-08 03:07:20 +02:00
1 parent e372d4ffd9
commit 199fd1d5d8
1 file changed
+5 -3
+5 -3
View File
@@ -1025,7 +1025,9 @@ bool Prefill::carve(size_t T, void* alloc) {
m.xn16 = o.take<uint16_t>(T * (D + (hc_pad() ? XN_PAD : 0)), ok); m.lo = o.take<float>(T * LR, ok); m.lo16 = o.take<uint16_t>(T * LR, ok);
m.gated = o.take<float>(T * D, ok); m.inj = o.take<float>(T * HC, ok);
m.mixed = o.take<float>(T * N, ok); m.mixed_bf = o.take<uint16_t>(T * N, ok);
m.mixed_h = o.take<uint16_t>(T * N, ok); m.bo = o.take<float>(T * N, ok);
m.mixed_h = o.take<uint16_t>(T * N, ok);
// Embedding rows are dead after gr_broadcast on m.cs; subsequent half outputs use the same stream.
m.bo = m.emb;
if (bf16x2_hc(m.f16_io)) { m.xn16_lo = o.take<uint16_t>(T * D, ok); m.lo16_lo = o.take<uint16_t>(T * LR, ok); }
if (bf16x2(m.f16_io)) m.mixed_bf_lo = o.take<uint16_t>(T * N, ok);
m.steps_dev = o.take<int32_t>(T * strata::kernels::kStepCount, ok);
@@ -1571,7 +1573,7 @@ uint64_t Prefill::bytes_needed_impl(const core::ModelGeometry& g, const core::Se
o.take<uint8_t>(GEMM_WS, ok);
auto f = [&](size_t n) { o.take<float>(n, ok); };
// `carve`'s order, buffer for buffer: emb, R, xn, grs, xn16, lo, lo16, gated, inj, mixed, mixed_bf, mixed_h,
// bo. This counted `xn` unconditionally (carve takes it only under STRATA_GR_UNFUSED) and never counted
// bo aliases emb. This counted `xn` unconditionally (carve takes it only under STRATA_GR_UNFUSED) and never counted
// `grs`. Net over-count T*(D-HC)*4 bytes: 42 MB at a 1024-token chunk, 252 MB (48 Q8_0 slots) at 6144 - the
// prompt path was told it had less room than it did. Safe - the direction is over-estimating, and `take`
// still bounds-checks - but it under-sizes every loan, so every chunk the scan picks is one step smaller.
@@ -1583,7 +1585,7 @@ uint64_t Prefill::bytes_needed_impl(const core::ModelGeometry& g, const core::Se
f(T * N); f(T * D); f(T * D);
}
o.take<uint16_t>(T * (D + (hc_pad() ? XN_PAD : 0)), ok); f(T * LR); o.take<uint16_t>(T * LR, ok);
f(T * D); f(T * HC); f(T * N); o.take<uint16_t>(T * N, ok); o.take<uint16_t>(T * N, ok); f(T * N);
f(T * D); f(T * HC); f(T * N); o.take<uint16_t>(T * N, ok); o.take<uint16_t>(T * N, ok);
const bool f16_io = prompt_f16(); // the current device's mode (the stage's), as Prefill::init will decide it
if (bf16x2_hc(f16_io)) { o.take<uint16_t>(T * D, ok); o.take<uint16_t>(T * LR, ok); }
if (bf16x2(f16_io)) o.take<uint16_t>(T * N, ok);