From d0336684e50c81dcd28d00e395ad277323354d29 Mon Sep 17 00:00:00 2001 From: sergiywith Date: Fri, 9 Oct 2026 11:42:06 +0300 Subject: [PATCH] kv-grow: kvg_trim uploads the residency table with res_put, which waits for the copy kvg_trim refilled the slots the K/V gave back and then uploaded host_res with a plain cudaMemcpy from pageable memory. That returns once the table is staged, before its DMA lands, and nothing after it waited for stream 0: the next request's session_zero syncs main_stream only, and a prompt part of --short-read tokens or fewer goes straight to ver.run, whose graph reads hits_.d_res on the verifier's cudaStreamNonBlocking stream. res_put (#550) is the upload every other residency change uses: the same copy, then cudaStreamSynchronize(nullptr). kvg_ensure's upload needs nothing: qsa_kv_elastic_grow ends in cudaDeviceSynchronize before anything reads the table. Only --kv-grow (opt-in) runs kvg_trim, so the default path is unchanged. --- src/program/generate.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/program/generate.cpp b/src/program/generate.cpp index e76e582b..bb12ff6f 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -6299,8 +6299,8 @@ int main(int argc, char** argv) { } for (const auto& [i, s] : filled) host_res[i] = s; kvg.refilled += (int64_t) filled.size(); - if (cudaMemcpy(d_res, host_res.data(), host_res.size() * sizeof(int32_t), cudaMemcpyHostToDevice) != cudaSuccess) - return false; + // res_put waits for its copy: the next reader can be a verify window (a non-blocking stream) right away + if (res_put(d_res) != cudaSuccess) return false; for (const strata::core::VmmChunk h : kvg.spare) strata::core::vmm_chunk_free(h); // new ones, if any kvg.spare.clear(); ++kvg.trims;