diff --git a/include/strata/core/verify.hpp b/include/strata/core/verify.hpp index a9dc19db..bec348e3 100644 --- a/include/strata/core/verify.hpp +++ b/include/strata/core/verify.hpp @@ -459,6 +459,13 @@ private: cudaEvent_t df_join_[2] = {}; cudaGraphExec_t exec_[9] = {}; cudaGraphExec_t exec_nr_[9] = {}; // #871: the doorbell variant of a stage that is all-resident otherwise + // fork 34a35db (STRATA_SIDE_MIXER=1): the GDN gates and the QSA indexer on a branch of the window's graph beside the + // mixer's projections, joined before the recurrence / the attention + cudaStream_t side_ = nullptr; + cudaEvent_t mfork_ = nullptr, mjoin_ = nullptr; + // fork b063c13 (STRATA_SIDE_MIXER=2): a second branch for the GDN gate projection and the QSA queries' chain + cudaStream_t side2_ = nullptr; + cudaEvent_t pfork_ = nullptr, pjoin_ = nullptr; cudaGraphExec_t commit_exec_ = nullptr; // mapped staging (host pointer, device alias) diff --git a/src/core/verify.cpp b/src/core/verify.cpp index a8791cc6..5b7aa35b 100644 --- a/src/core/verify.cpp +++ b/src/core/verify.cpp @@ -173,6 +173,9 @@ inline bool g_qfuse_hc() { return false; #endif } +// fork 34a35db + b063c13 (Eddoursul), STRATA_SIDE_MIXER=1 / =2 (opt-in): the mixer's work that reads only the layer's +// input on branches of the window's graph (bitwise the same outputs); 0 / unset = in line, and no branch stream is created +inline int g_side_mixer() { static const int m = [] { const char* v = std::getenv("STRATA_SIDE_MIXER"); return v ? std::max(0, std::min(2, std::atoi(v))) : 0; }(); return m; } inline bool g_qfuse() { static const bool on = [] { const char* v = std::getenv("STRATA_QFUSE"); return v != nullptr && std::atoi(v) != 0; }(); return on; } #define VDBG(...) do { if (g_dbg) { std::fprintf(stderr, "verify dbg: " __VA_ARGS__); std::fflush(stderr); } } while (0) @@ -517,6 +520,10 @@ Verifier::~Verifier() { if (cs_ && cs_ != ext_stream_) cudaStreamDestroy(cs_); // set_stream: the stage's stream, shared, not ours if (sh_cs_) cudaStreamDestroy(sh_cs_); if (copy_) { cudaStreamSynchronize(copy_); cudaStreamDestroy(copy_); } + if (side_) cudaStreamDestroy(side_); + if (side2_) cudaStreamDestroy(side2_); + for (cudaEvent_t e : {mfork_, mjoin_, pfork_, pjoin_}) + if (e) cudaEventDestroy(e); if (commit_done_) cudaEventDestroy(commit_done_); if (ev_done_) cudaEventDestroy(ev_done_); if (ev_commit_) cudaEventDestroy(ev_commit_); @@ -813,6 +820,16 @@ bool Verifier::init(const WeightTable& wt, const ModelGeometry& g, SessionState& all_resident_ = all_ok; } } + if (g_side_mixer() > 0 && + (cudaStreamCreateWithFlags(&side_, cudaStreamNonBlocking) != cudaSuccess || + cudaEventCreateWithFlags(&mfork_, cudaEventDisableTiming) != cudaSuccess || + cudaEventCreateWithFlags(&mjoin_, cudaEventDisableTiming) != cudaSuccess || + cudaStreamCreateWithFlags(&side2_, cudaStreamNonBlocking) != cudaSuccess || + cudaEventCreateWithFlags(&pfork_, cudaEventDisableTiming) != cudaSuccess || + cudaEventCreateWithFlags(&pjoin_, cudaEventDisableTiming) != cudaSuccess)) { + err = "verify: the mixer branch's stream / events could not be created"; + return false; + } // E-6: a layer whose routed experts are all resident is planned on the device (STRATA_VERIFY_DEVICE_PLAN=1: on; // exact, but neutral on RIBPC 1-2 GPUs: off by default) { @@ -878,6 +895,17 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) { // Pipelined windows must wait for the host verdict/snapshot fence before mutating state. const bool self_commit = T == 1 && !always_publish_ && !batch_rec_ && !g_qfuse() && one_token_self_commit(); // see Verifier::commit static const bool dec_batch = [] { const char* v = std::getenv("STRATA_DEC_BATCH"); return v == nullptr || std::atoi(v) != 0; }(); + // fork 34a35db: the GDN gates and the QSA indexer beside the projections (STRATA_SIDE_MIXER=1; 0 / unset = in line) + const int side_mixer_mode = g_side_mixer(); + const bool side_mixer = side_mixer_mode >= 1; + const bool side_proj = side_mixer_mode >= 2 && !batch_rec_; // fork b063c13: the GDN gate projection, the QSA queries + auto branch = [&](cudaEvent_t e, cudaStream_t from, cudaStream_t to, const char* what) { + if (cudaEventRecord(e, from) == cudaSuccess && cudaStreamWaitEvent(to, e, 0) == cudaSuccess) return true; + err = std::string("verify: the mixer branch could not ") + what; + return false; + }; + // a batch window's rows each read their own slot's indexer: in line there + const bool sidem = side_mixer && !batch_rec_; auto stamp = [&](int64_t l, int i, int grp) { if (prof_on_ && grp == 0) gpu_stamp(prof_, (int) (l * kProfPer + i), cs); if (trace_m_ != nullptr) gpu_stamp(trace_m_, (int) ((l * kProfPer + i) * 2 + grp), cs); // #649 @@ -903,7 +931,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) { // makes side i depend on everything captured on `cs` so far, join(i) makes `cs` depend on everything captured on // side i: a branch never races with what came before its fork or after its join. Not in a split or batch window, // nor under the stage profiler (whose stamps are on `cs`). - const bool br = df_branch_ && G == 1 && !batch_rec_ && !prof_on_; + const bool br = df_branch_ && G == 1 && !batch_rec_ && !prof_on_ && !side_mixer; // STRATA_SIDE_MIXER wins auto fork = [&](int i) { cudaEventRecord(df_fork_, cs); cudaStreamWaitEvent(df_side_[i], df_fork_, 0); @@ -1148,7 +1176,30 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) { float* hb = h_L_ + (size_t) gi * MT * C; float* gate = gate_L_ + (size_t) gi * MT * HV; float* beta = beta_L_ + (size_t) gi * MT * HV; + if (sidem) { // the gates (a few blocks, latency-bound) beside the projections, joined below + if (!branch(mfork_, cs, side_, "fork")) return false; + gdn_ab_multi(xm, (const uint16_t*) wa->data, (const uint16_t*) wb->data, (const float*) wdt->data, + (const float*) wsa->data, gate + (size_t) tb * HV, beta + (size_t) tb * HV, (int) N, + (int) HV, n, side_); + if (cudaEventRecord(mjoin_, side_) != cudaSuccess) { err = "verify: the GDN gates' branch could not join"; return false; } + } if (!q8_attn) native_quantize_q8_1(xm, xq_, (int) N, n, cs); + if (side_proj) { // the gate projection (compute-bound for i-quants) beside qkv and the conv + // the branch reads F4's interleaved copy too (written on cs before the fork; bitwise native_mmvq's + // output), and qkv is recorded before the branch's launch, so its grid is dispatched first and the + // conv / recurrence that wait for it start sooner (z is read only after the recurrence) + const bool g_il = g_mmvq_il() && strata::kernels::native_mmvq_il_supported(wg->native_type, n, (int) ZV); + if (g_il && !il_ready) { + strata::kernels::native_q8_1_interleave(xq_, xil_, (int) N, n, cs); + il_ready = true; + } + if (!branch(pfork_, cs, side2_, "fork")) return false; + mm(wqkv, qkv + (size_t) tb * C, (int) N, (int) C); + if (g_il) strata::kernels::native_mmvq_il(wg->native_type, wg->native_data, xq_, xil_, z_ + (size_t) tb * ZV, + (int) N, (int) ZV, n, side2_); + else native_mmvq(wg->native_type, wg->native_data, xq_, z_ + (size_t) tb * ZV, (int) N, (int) ZV, n, side2_); + if (cudaEventRecord(pjoin_, side2_) != cudaSuccess) { err = "verify: the gate projection's branch could not join"; return false; } + } if (br) { // STRATA_DF_BRANCH: a/b and z beside q/k/v and the conv; all of them read only this layer's input fork(0); gdn_ab_multi(xm, (const uint16_t*) wa->data, (const uint16_t*) wb->data, (const float*) wdt->data, @@ -1158,8 +1209,8 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) { native_mmvq(wg->native_type, wg->native_data, xq_, z_ + (size_t) tb * ZV, (int) N, (int) ZV, n, df_side_[1]); } - const bool fuse_ab = fuse_convab_on() && !br && !batch_rec_ && !prof_on_; - mm(wqkv, qkv + (size_t) tb * C, (int) N, (int) C); + const bool fuse_ab = fuse_convab_on() && !br && !batch_rec_ && !prof_on_ && !sidem; // the side mixer computes the gates on its branch + if (!side_proj) mm(wqkv, qkv + (size_t) tb * C, (int) N, (int) C); // with side_proj: above, first stamp(l, 2, grp); if (batch_rec_) { // contiguous rows may be proposals for the same slot for (int t = tb; t < te;) { @@ -1186,13 +1237,21 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) { join(0); join(1); } else { - if (!fuse_ab) + if (!fuse_ab && !sidem) // the gates: the HIP fused conv kernel (143-amdk) or the side mixer's branch, else here gdn_ab_multi(xm, (const uint16_t*) wa->data, (const uint16_t*) wb->data, (const float*) wdt->data, (const float*) wsa->data, gate + (size_t) tb * HV, beta + (size_t) tb * HV, (int) N, (int) HV, n, cs); stamp(l, 4, grp); - mm(wg, z_ + (size_t) tb * ZV, (int) N, (int) ZV); + if (!side_proj) mm(wg, z_ + (size_t) tb * ZV, (int) N, (int) ZV); stamp(l, 5, grp); + if (side_proj && cudaStreamWaitEvent(cs, pjoin_, 0) != cudaSuccess) { + err = "verify: the gate projection's branch could not join"; + return false; + } + if (sidem && cudaStreamWaitEvent(cs, mjoin_, 0) != cudaSuccess) { + err = "verify: the GDN gates' branch could not join"; + return false; + } } // the recurrence from the untouched state over tokens [0, te); outputs only for this group's if (batch_rec_) { // each slot's recurrence over its own proposed-token group @@ -1273,9 +1332,126 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) { IQ * ID, N, IQ * ID, n, df_side_[1]); norm_rope_on(qidx_ + tb * IQ * ID, wiqn, (int) (n * IQ), (int) ID, pos_i + tb * IQ, df_side_[1]); } - if (qb) bf16_gemv_fp32_mmvf_multi(mixed_ + tb * N, N, (const uint16_t*) wik->data, idx_raw + tb * ID, ID, N, ID, n, cs); - else for (int t = tb; t < te; ++t) - bf16_gemv_fp32_mmvf(mixed_ + t * N, (const uint16_t*) wik->data, idx_raw + t * ID, (int) N, (int) ID, cs); + // STRATA_SIDE_MIXER=1 / =2 (fork Eddoursul 34a35db + b063c13): the indexer's key projection, + // the tail's snapshot, its keys appended, its query projection, norm and RoPE, the block scores and the + // top-k read only the mixer's input and the indexer's own state - =1 runs them on a branch beside the + // attention's projections; =2 also the queries' chain on a second branch. Each step below is + // the in-line code with its stream as a parameter; with the switch off they run on cs in the same order + // as before (STRATA_DF_BRANCH, the same idea for fewer of these steps, is off whenever this is on). + auto norm_rope_s = [&](float* data, const WeightRef* norm, int rows, int cols, const int32_t* pos, cudaStream_t ns) { + if (fuse_nr && native_norm_rope_usable(cols, (int) s.n_rot)) { + native_qsa_rms_norm_rope(data, cols, (const float*) norm->data, data, rows, cols, (int) s.n_rot, EPS, + rope_scaling(), pos, ns); + return; + } + norm_rope_on(data, norm, rows, cols, pos, ns); + }; + auto idx_key = [&](cudaStream_t ns) { + if (qb) bf16_gemv_fp32_mmvf_multi(mixed_ + tb * N, N, (const uint16_t*) wik->data, idx_raw + tb * ID, ID, N, ID, n, ns); + else for (int t = tb; t < te; ++t) + bf16_gemv_fp32_mmvf(mixed_ + t * N, (const uint16_t*) wik->data, idx_raw + t * ID, (int) N, (int) ID, ns); + }; + auto idx_snap = [&](cudaStream_t ns) { + if (batch_rec_) { // snapshot each slot's indexer tail before its first proposed row + for (int t = tb; t < te; ++t) + if (t == tb || brow_[t] != brow_[t - 1]) + copy_from_mapped(tail_snap_b_ + ((size_t) brow_[t] * nQall + qi) * TS, + slot_ss(t).qsa_states[qi].idx_tail, TS, ns); + } else + if (grp == 0) copy_from_mapped(tail_snap_ + (size_t) qi * TS, st.idx_tail, TS, ns); + }; + auto idx_append = [&](cudaStream_t ns) { + if (dec_batch && !g_no_batch_kv && !batch_rec_) { + const QsaIndexerBuffers ib{st.idx_tail, st.idx_dead, st.idx_pooled, st.idx_block_pos}; + native_qsa_indexer_append_steps(idx_raw + tb * ID, step_ + tb * kStepCount + kStepPos, kStepCount, + n, 0, (const float*) wikn->data, EPS, ib, s, st.max_cells, + rope_scaling(), ns); + } else { + for (int t = tb; t < te; ++t) { + const QsaState& sx = slot_ss(t).qsa_states[qi]; + const QsaIndexerBuffers ib{sx.idx_tail, sx.idx_dead, sx.idx_pooled, sx.idx_block_pos}; + native_qsa_indexer_append(idx_raw + t * ID, step_ + t * kStepCount + kStepPos, 0, + (const float*) wikn->data, EPS, ib, s, sx.max_cells, + rope_scaling(), ns); + } + } + }; + auto idx_query = [&](cudaStream_t ns) { + if (qb) { + bf16_gemv_fp32_mmvf_multi(mixed_ + tb * N, N, (const uint16_t*) wiq->data, qidx_ + tb * IQ * ID, IQ * ID, + N, IQ * ID, n, ns); + norm_rope_s(qidx_ + tb * IQ * ID, wiqn, (int) (n * IQ), (int) ID, pos_i + tb * IQ, ns); + } else + for (int t = tb; t < te; ++t) { + float* qx = qidx_ + t * IQ * ID; + bf16_gemv_fp32_mmvf(mixed_ + t * N, (const uint16_t*) wiq->data, qx, (int) N, (int) (IQ * ID), ns); + norm_rope_s(qx, wiqn, (int) IQ, (int) ID, pos_ + t * NH, ns); + } + }; + auto idx_select = [&](cudaStream_t ns) { + qsa_block_scores(st.idx_pooled, st.idx_dead, qidx_ + tb * IQ * ID, step_ + tb * kStepCount, n, max_blocks_, + s, scores_ + (size_t) tb * max_blocks_, ns); + qsa_block_topk(scores_ + (size_t) tb * max_blocks_, step_ + tb * kStepCount, n, max_blocks_, cap_, s, + sel_ + (size_t) tb * cap_, ns); + }; + // the attention's queries: the projection (mm on cs, which may read F4's interleaved copy; on a branch + // F4's kernel too, its copy written on cs before the fork - bitwise the same), the q/gate + // split with norm and RoPE, the rotation + const bool q_il = side_proj && g_mmvq_il() && + strata::kernels::native_mmvq_il_supported(wq->native_type, n, (int) (NH * 2 * HD)); + auto q_chain = [&](cudaStream_t ns) -> bool { + if (ns == cs) mm(wq, qfull_ + tb * NH * 2 * HD, (int) N, (int) (NH * 2 * HD)); + else if (q_il) strata::kernels::native_mmvq_il(wq->native_type, wq->native_data, xq_, xil_, + qfull_ + tb * NH * 2 * HD, (int) N, (int) (NH * 2 * HD), n, ns); + else native_mmvq(wq->native_type, wq->native_data, xq_, qfull_ + tb * NH * 2 * HD, (int) N, + (int) (NH * 2 * HD), n, ns); + if (qb) { + if (fuse_nr) { // the q/gate split reads q straight out of the q|gate rows (stride 2 * HD) + native_qsa_rms_norm_rope(qfull_ + tb * NH * 2 * HD, (int) (2 * HD), (const float*) wqn->data, + qcur_ + tb * NH * HD, (int) (n * NH), (int) HD, (int) s.n_rot, EPS, + rope_scaling(), pos_ + tb * NH, ns); + } else { + copy_rows_strided(qcur_ + tb * NH * HD, qfull_ + tb * NH * 2 * HD, (int64_t) n * NH, HD, 2 * HD, ns); + norm_rope_s(qcur_ + tb * NH * HD, wqn, (int) (n * NH), (int) HD, pos_ + tb * NH, ns); + } + if (st.kv_rot) fwht256_inplace_cuda(qcur_ + tb * NH * HD, (int64_t) n * NH, ns); // = + } else { + for (int t = tb; t < te; ++t) { + float* qc = qcur_ + t * NH * HD; + if (fuse_nr) { + native_qsa_rms_norm_rope(qfull_ + t * NH * 2 * HD, (int) (2 * HD), (const float*) wqn->data, qc, + (int) NH, (int) HD, (int) s.n_rot, EPS, rope_scaling(), pos_ + t * NH, ns); + } else { + if (cudaMemcpy2DAsync(qc, (size_t) HD * 4, qfull_ + t * NH * 2 * HD, (size_t) HD * 2 * 4, + (size_t) HD * 4, (size_t) NH, cudaMemcpyDeviceToDevice, ns) != cudaSuccess) { + err = "verify: the q/gate split failed"; + return false; + } + norm_rope_s(qc, wqn, (int) NH, (int) HD, pos_ + t * NH, ns); + } + if (st.kv_rot) fwht256_inplace_cuda(qc, NH, ns); // = + } + } + return true; + }; + if (sidem) { + if (!branch(mfork_, cs, side_, "fork")) return false; + idx_key(side_); + idx_snap(side_); + idx_append(side_); + idx_query(side_); + idx_select(side_); + if (cudaEventRecord(mjoin_, side_) != cudaSuccess) { err = "verify: the indexer's branch could not join"; return false; } + } + if (side_proj) { // the queries beside the keys and values (fork b063c13) + if (q_il && !il_ready) { // the copy before the fork (mm(wk) / mm(wv) on cs reuse it) + strata::kernels::native_q8_1_interleave(xq_, xil_, (int) N, n, cs); + il_ready = true; + } + if (!branch(pfork_, cs, side2_, "fork") || !q_chain(side2_)) return false; + if (cudaEventRecord(pjoin_, side2_) != cudaSuccess) { err = "verify: the queries' branch could not join"; return false; } + } + if (!sidem) idx_key(cs); stamp(l, 7, grp); mm(wk, kcur_ + tb * NKV * HD, (int) N, (int) (NKV * HD)); mm(wv, vcur_ + tb * NKV * HD, (int) N, (int) (NKV * HD)); @@ -1288,13 +1464,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) { fwht256_inplace_cuda(vcur_ + tb * NKV * HD, (int64_t) n * NKV, cs); } stamp(l, 8, grp); - if (batch_rec_) { // snapshot each slot's indexer tail before its first proposed row - for (int t = tb; t < te; ++t) - if (t == tb || brow_[t] != brow_[t - 1]) - copy_from_mapped(tail_snap_b_ + ((size_t) brow_[t] * nQall + qi) * TS, - slot_ss(t).qsa_states[qi].idx_tail, TS, cs); - } else - if (grp == 0) copy_from_mapped(tail_snap_ + (size_t) qi * TS, st.idx_tail, TS, cs); + if (!sidem) idx_snap(cs); // #783 PR-d (stuchapin909): the window's K/V cells in one launch per pool instead of one per token (a // batch's rows each have their own K/V, so that case keeps the loop) if (dec_batch && !g_no_batch_kv && !batch_rec_) { @@ -1342,61 +1512,13 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) { kv_append_step(st.k_pool, st.v_pool, st.page_table, step_t, kcur_ + t * NKV * HD, vcur_ + t * NKV * HD, s, cs, &st.host); } - if (dec_batch && !g_no_batch_kv && !batch_rec_) { - const QsaIndexerBuffers ib{st.idx_tail, st.idx_dead, st.idx_pooled, st.idx_block_pos}; - native_qsa_indexer_append_steps(idx_raw + tb * ID, step_ + tb * kStepCount + kStepPos, kStepCount, - n, 0, (const float*) wikn->data, EPS, ib, s, st.max_cells, - rope_scaling(), cs); - } else { - for (int t = tb; t < te; ++t) { - const QsaState& sx = slot_ss(t).qsa_states[qi]; - const QsaIndexerBuffers ib{sx.idx_tail, sx.idx_dead, sx.idx_pooled, sx.idx_block_pos}; - native_qsa_indexer_append(idx_raw + t * ID, step_ + t * kStepCount + kStepPos, 0, - (const float*) wikn->data, EPS, ib, s, sx.max_cells, - rope_scaling(), cs); - } - } + if (!sidem) idx_append(cs); stamp(l, 9, grp); if (qbr) { join(1); // the indexer query, for the block scores } else { - mm(wq, qfull_ + tb * NH * 2 * HD, (int) N, (int) (NH * 2 * HD)); - if (qb) { - if (fuse_nr) { // the q/gate split reads q straight out of the q|gate rows (stride 2 * HD) - native_qsa_rms_norm_rope(qfull_ + tb * NH * 2 * HD, (int) (2 * HD), (const float*) wqn->data, - qcur_ + tb * NH * HD, (int) (n * NH), (int) HD, (int) s.n_rot, EPS, - rope_scaling(), pos_ + tb * NH, cs); - } else { - // the q/gate split as a copy kernel: the window's chain stays kernel to kernel (PDL) - copy_rows_strided(qcur_ + tb * NH * HD, qfull_ + tb * NH * 2 * HD, (int64_t) n * NH, HD, 2 * HD, cs); - norm_rope(qcur_ + tb * NH * HD, wqn, (int) (n * NH), (int) HD, pos_ + tb * NH); - } - if (st.kv_rot) fwht256_inplace_cuda(qcur_ + tb * NH * HD, (int64_t) n * NH, cs); // = - bf16_gemv_fp32_mmvf_multi(mixed_ + tb * N, N, (const uint16_t*) wiq->data, qidx_ + tb * IQ * ID, IQ * ID, - N, IQ * ID, n, cs); - norm_rope(qidx_ + tb * IQ * ID, wiqn, (int) (n * IQ), (int) ID, pos_i + tb * IQ); - } else { - for (int t = tb; t < te; ++t) { - float* qc = qcur_ + t * NH * HD; - if (fuse_nr) { - native_qsa_rms_norm_rope(qfull_ + t * NH * 2 * HD, (int) (2 * HD), (const float*) wqn->data, qc, - (int) NH, (int) HD, (int) s.n_rot, EPS, rope_scaling(), pos_ + t * NH, cs); - } else { - if (cudaMemcpy2DAsync(qc, (size_t) HD * 4, qfull_ + t * NH * 2 * HD, (size_t) HD * 2 * 4, - (size_t) HD * 4, (size_t) NH, cudaMemcpyDeviceToDevice, cs) != cudaSuccess) { - err = "verify: the q/gate split failed"; - return false; - } - norm_rope(qc, wqn, (int) NH, (int) HD, pos_ + t * NH); - } - if (st.kv_rot) fwht256_inplace_cuda(qc, NH, cs); // = - } - for (int t = tb; t < te; ++t) { - float* qx = qidx_ + t * IQ * ID; - bf16_gemv_fp32_mmvf(mixed_ + t * N, (const uint16_t*) wiq->data, qx, (int) N, (int) (IQ * ID), cs); - norm_rope(qx, wiqn, (int) IQ, (int) ID, pos_ + t * NH); - } - } + if (!side_proj && !q_chain(cs)) return false; + if (!sidem) idx_query(cs); } stamp(l, 10, grp); if (batch_rec_) { // each row selects and attends over its own slot's K/V @@ -1413,10 +1535,15 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) { attn_ + t * NH * HD, 1, cs); } } else { - qsa_block_scores(st.idx_pooled, st.idx_dead, qidx_ + tb * IQ * ID, step_ + tb * kStepCount, n, max_blocks_, - s, scores_ + (size_t) tb * max_blocks_, cs); - qsa_block_topk(scores_ + (size_t) tb * max_blocks_, step_ + tb * kStepCount, n, max_blocks_, cap_, s, - sel_ + (size_t) tb * cap_, cs); + if (!sidem) idx_select(cs); + else if (cudaStreamWaitEvent(cs, mjoin_, 0) != cudaSuccess) { + err = "verify: the indexer's branch could not join"; + return false; + } + if (side_proj && cudaStreamWaitEvent(cs, pjoin_, 0) != cudaSuccess) { + err = "verify: the queries' branch could not join"; + return false; + } stamp(l, 11, grp); // KV streaming: the n selections' blocks resident (device-side, inside the graph) qsa_kv_resolve(st, *g_, sel_ + (size_t) tb * cap_, step_ + tb * kStepCount, n, cap_, cs);