Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

prefill timing: KV staging on its own line ("kv stage")

Niko12214fb14bf92388
diff --git a/src/prefill/prefill.cpp b/src/prefill/prefill.cpp
index 1f0494689..0d1e08a19 100644
--- a/src/prefill/prefill.cpp
+++ b/src/prefill/prefill.cpp
@@ -701,10 +701,10 @@ namespace {
// host's expert grouping, or for an expert's copy) lands on the phase that was waiting. Events are reused: the marks
// are folded at every MoE layer's host sync, after which all of them have completed.
enum PfPhase { kPfStart, kPfHc, kPfGdn, kPfQsa, kPfQsaIdx, kPfQsaSel, kPfQsaAttn, kPfRouter, kPfHostGroup, kPfGather,
- kPfWaitCopy, kPfDequant, kPfGemmGU, kPfGemmD, kPfCombine, kPfPle, kPfCount };
+ kPfWaitCopy, kPfDequant, kPfGemmGU, kPfGemmD, kPfCombine, kPfPle, kPfKvStage, kPfCount };
const char* const kPfNames[kPfCount] = {"embed+steps", "hc read", "gdn", "qsa proj", "qsa indexer", "qsa select",
"qsa attn", "router+shared", "host grouping", "gather", "wait copy", "dequant",
- "gemm gate/up", "gemm down", "combine", "ple"};
+ "gemm gate/up", "gemm down", "combine", "ple", "kv stage"};
struct PfTimer {
bool on = std::getenv("STRATA_PREFILL_TIMING") != nullptr;
std::vector<cudaEvent_t> ev;
@@ -1113,10 +1113,13 @@ bool Prefill::run(const int64_t* tokens, int64_t n, int64_t pos0, std::string& e
// KV streaming: this layer's cells [0, p0) come in from the host copy to the staging pool, and the
// chunk's cells go to the host copy, the staging pool, and the VRAM slots of resident blocks
const bool staged = st.kv_mode == 1;
- if (staged)
+ if (staged) {
+ pt.mark(kPfKvStage, cs);
strata::kernels::kv_stage_from_host(pools_of(m.stage, m.ident_table), st.host,
core::qsa_kv_format(st),
(p0 + s.page_size - 1) / s.page_size, s, m.cs);
+ pt.mark(kPfQsa, cs);
+ }
if (st.kv_q4) { // Q4_0 KV (kv_q4.hpp): rotated K and V, the queries below too, the output back
strata::kernels::fwht256_inplace_cuda(m.Kc, T * 2, m.cs);
strata::kernels::fwht256_inplace_cuda(m.Vc, T * 2, m.cs);