diff --git a/sycl/src/prefill/prefill.cpp b/sycl/src/prefill/prefill.cpp index 1aef34d4..ca16304c 100644 --- a/sycl/src/prefill/prefill.cpp +++ b/sycl/src/prefill/prefill.cpp @@ -1824,18 +1824,19 @@ void Prefill::set_ring_budget(int slots, int64_t small_max) { double Prefill::pinned_share() { return g_pinned_share; } int64_t Prefill::stream_all_min_tokens() { return stream_all_min(); } -uint64_t Prefill::bytes_needed(const core::ModelGeometry& g, const core::SessionState& ss, int64_t chunk) { - return bytes_needed_impl(g, ss, chunk, false); +uint64_t Prefill::bytes_needed(const core::ModelGeometry& g, const core::SessionState& ss, int64_t chunk, bool src) { + return bytes_needed_impl(g, ss, chunk, false, src); } // What `init` really allocates when the prompt path owns its buffers (no loan): every cudaMalloc rounds up to a 2 MiB // page, and the ring is one allocation (carve). `bytes_needed` stays the borrowed region's sum. -uint64_t Prefill::bytes_needed_owned(const core::ModelGeometry& g, const core::SessionState& ss, int64_t chunk) { - return bytes_needed_impl(g, ss, chunk, true); +uint64_t Prefill::bytes_needed_owned(const core::ModelGeometry& g, const core::SessionState& ss, int64_t chunk, + bool src) { + return bytes_needed_impl(g, ss, chunk, true, src); } uint64_t Prefill::bytes_needed_impl(const core::ModelGeometry& g, const core::SessionState& ss, int64_t chunk, - bool owned_pages) { + bool owned_pages, bool src) { // the same allocation sequence as `init`, counted const size_t T = (size_t) chunk; bool ok = true; @@ -1869,7 +1870,7 @@ uint64_t Prefill::bytes_needed_impl(const core::ModelGeometry& g, const core::Se const int64_t cap = strata::kernels::qsa_selection_width(strata::kernels::kTopkMaxCells, s); const int64_t max_blocks = ss.qsa_states[ss.qsa_primary()].max_cells / s.idx_block + 2; o.take((size_t) std::max({gdn_set_bytes(T), qsa_set_bytes(T, cap, max_blocks, 256, 32, s), - moe_set_bytes(T, g.n_expert, fused_layout(T, true))}), ok); + moe_set_bytes(T, g.n_expert, fused_layout(T, src))}), ok); for (int i = 0; i < DQ; ++i) { o.take(1280 * 2560, ok); o.take(2560 * 640, ok); } if (mmq_plan().any) { const MmqPlan& mp = mmq_plan(); @@ -1890,8 +1891,9 @@ uint64_t Prefill::bytes_needed_impl(const core::ModelGeometry& g, const core::Se return o.used + (8u << 20); // alignment slack } -uint64_t Prefill::bytes_needed_no_ring(const core::ModelGeometry& g, const core::SessionState& ss, int64_t chunk) { - return bytes_needed(g, ss, chunk) - (uint64_t) ring_slots((size_t) chunk) * (uint64_t) MAXBLOB(); +uint64_t Prefill::bytes_needed_no_ring(const core::ModelGeometry& g, const core::SessionState& ss, int64_t chunk, + bool src) { + return bytes_needed(g, ss, chunk, src) - (uint64_t) ring_slots((size_t) chunk) * (uint64_t) MAXBLOB(); } int64_t Prefill::ring_default_slots() {