Conversation cache: opt-in STRATA_PARK_VRAM_MIB=N keeps parked conversations' K/V in VRAM in front of the host copy (#3779, #3712)

Problem: restoring a parked conversation copies its K/V from the host over the
link: 27-107 ms over a PCIe Gen2 x4 link.

Change, opt-in and only with STRATA_PARK_ASYNC=1 (CUDA only): a park also keeps
the whole K/V of its image in a VRAM slot of its own (64 MiB granules, up to N MiB
in all, only while 1.5 GB of VRAM stays free beside it); the background copy to
the host reads from the slot, and a restore of that image copies device to device
from the slot (about 1 ms) without waiting for the background copy. Each K/V
layer carries its own join-and-release token, so any order of destruction is safe
(the layers outlive their image when they are retained for the next park). Under
VRAM pressure the elastic K/V's growth releases every slot and the stage, then
retries once (both growth sites in generate.cpp).

With the variable unset the slot code is not reached: the budget is 0, a restore
finds dev_tag 0 and takes the host path, and the growth sites see
conversation_park_vram_release_all() return 0 and behave as before.

Tests: none of its own (it needs a card with the VRAM for the slot and a parked
conversation); see the checklist for the reporters' A/B/A conversation check with
STRATA_PARK_VRAM_MIB set.

Reporter's numbers (linxuhao, CMP 170HX): restore of a 3K conversation 28-47 ->
7-12 ms; outputs identical. The first restore of a run is slower (41.6 / 56.9 ms)
than later ones (6.5-12.6 ms) and they have not found why. Theirs, not measured
here.

Original change by linxuhao (PR #3779, commit bafca410).
This commit is contained in:
linxuhao authored and Niko1221 committed 2026-10-27 00:52:52 +01:00
1 parent ca378670b2
commit 85e3dde522
5 files changed
+275 -12

No files matched your search

+12 -3
View File
@@ -8146,12 +8146,18 @@ int main(int argc, char** argv) {
return false;
}
int64_t fresh = 0;
const bool ok = strata::core::qsa_kv_elastic_grow(target, [&]() -> strata::core::VmmChunk {
auto grow_take = [&]() -> strata::core::VmmChunk {
if (kvg.spare.empty()) { ++fresh; return 0; } // the cache is at its floor: new memory
const strata::core::VmmChunk h = kvg.spare.back();
kvg.spare.pop_back();
return h;
});
};
bool ok = strata::core::qsa_kv_elastic_grow(target, grow_take);
// STRATA_PARK_VRAM_MIB: the parked conversations' VRAM copies of their K/V give way to the K/V itself
if (!ok && strata::core::conversation_park_vram_release_all() > 0) {
(void) cudaGetLastError();
ok = strata::core::qsa_kv_elastic_grow(target, grow_take);
}
kvg.fresh += fresh;
kvg.cells = strata::core::qsa_kv_elastic_cells();
++kvg.grows;
@@ -13328,7 +13334,10 @@ int main(int argc, char** argv) {
}
}
// the elastic K/V: a parked conversation is restored whole, and it may be longer than this prompt
if (incoming && !kvg_ensure((int64_t) incoming->live.ids.size() + 256, kv_quiesce)) {
// (STRATA_PARK_VRAM_MIB: the parked K/V copies in VRAM go first, then one more try)
if (incoming && !kvg_ensure((int64_t) incoming->live.ids.size() + 256, kv_quiesce) &&
(strata::core::conversation_park_vram_release_all() == 0 ||
!kvg_ensure((int64_t) incoming->live.ids.size() + 256, kv_quiesce))) {
std::printf("ERR the K/V cannot grow to the parked conversation: no VRAM is left\n");
return 1;
}