D-4: refill the prompt path's lent cache slots with queued copies and one wait
The same copies on the same (legacy) stream, but queued instead of waited on one by one: the same bytes, ordered the same against earlier work. Q2_0 on a 5070 (1,782 slots): 162 -> 96 ms per prompt, 4K and 32K outputs identical. The rest (publishing slots in the background while decode starts) would hide the last ~2% of the time to first token on a 4K prompt; not done. STRATA_REFILL_BLOCKING=1 keeps the old loop.
This commit is contained in:
1 parent
4fb14bf923
commit
68072d30d4
3 files changed
+48
-6
No files matched your search
@@ -87,6 +87,11 @@
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
// perf-review D-4: the lent slots are refilled with queued copies and one wait; STRATA_REFILL_BLOCKING=1 waits on each
|
||||
bool refill_blocking() {
|
||||
static const bool v = std::getenv("STRATA_REFILL_BLOCKING") != nullptr;
|
||||
return v;
|
||||
}
|
||||
|
||||
using Clock = std::chrono::steady_clock;
|
||||
|
||||
@@ -3798,13 +3803,15 @@ int main(int argc, char** argv) {
|
||||
auto refill = [&](std::string& e) -> bool {
|
||||
if (lent_now.empty()) return true;
|
||||
tr("refill start", (long long) lent_now.size());
|
||||
for (const auto& [i, slot] : lent_now) {
|
||||
for (const auto& [i, slot] : lent_now) { // D-4: queued, one wait (STRATA_REFILL_BLOCKING=1: each)
|
||||
const uint8_t* b = srcp->blob(i / g.n_expert, i % g.n_expert);
|
||||
if (b == nullptr || !xcache.fill_slot_blocking(slot, b, e,
|
||||
(int64_t) strata::kernels::cpu::expert_layout().blob_bytes(i / g.n_expert)))
|
||||
const int64_t nb = (int64_t) strata::kernels::cpu::expert_layout().blob_bytes(i / g.n_expert);
|
||||
if (b == nullptr || !(refill_blocking() ? xcache.fill_slot_blocking(slot, b, e, nb)
|
||||
: xcache.fill_slot_queued(slot, b, e, nb)))
|
||||
return false;
|
||||
host_res[(size_t) i] = slot;
|
||||
}
|
||||
if (!xcache.sync_queued(e)) return false;
|
||||
cudaMemcpy(d_res, host_res.data(), host_res.size() * sizeof(int32_t), cudaMemcpyHostToDevice);
|
||||
lent_now.clear();
|
||||
lent_chunk = 0;
|
||||
@@ -4250,15 +4257,20 @@ int main(int argc, char** argv) {
|
||||
// refill the lent slots from the arena and give them back to the decode tier
|
||||
if (!lent.empty()) {
|
||||
const Clock::time_point tr = Clock::now();
|
||||
for (const auto& [i, slot] : lent) {
|
||||
for (const auto& [i, slot] : lent) { // D-4: queued, one wait (STRATA_REFILL_BLOCKING=1: each)
|
||||
const uint8_t* b = srcp->blob(i / g.n_expert, i % g.n_expert);
|
||||
if (b == nullptr || !xcache.fill_slot_blocking(slot, b, err,
|
||||
(int64_t) strata::kernels::cpu::expert_layout().blob_bytes(i / g.n_expert))) {
|
||||
const int64_t nb = (int64_t) strata::kernels::cpu::expert_layout().blob_bytes(i / g.n_expert);
|
||||
if (b == nullptr || !(refill_blocking() ? xcache.fill_slot_blocking(slot, b, err, nb)
|
||||
: xcache.fill_slot_queued(slot, b, err, nb))) {
|
||||
std::fprintf(stderr, "strata generate: refilling a lent slot failed: %s\n", err.c_str());
|
||||
return 1;
|
||||
}
|
||||
host_res[(size_t) i] = slot;
|
||||
}
|
||||
if (!xcache.sync_queued(err)) {
|
||||
std::fprintf(stderr, "strata generate: refilling the lent slots failed: %s\n", err.c_str());
|
||||
return 1;
|
||||
}
|
||||
cudaMemcpy(d_res, host_res.data(), host_res.size() * sizeof(int32_t), cudaMemcpyHostToDevice);
|
||||
std::fprintf(stderr, "strata generate: %zu lent slots refilled in %.1f ms\n", lent.size(),
|
||||
std::chrono::duration<double, std::milli>(Clock::now() - tr).count());
|
||||
|
||||
Reference in new issue
Block a user