| 5341 | // ================================ BATCH WINDOWS (see init_slots) ================================ |
| 5342 | |
| 5343 | bool Verifier::init_slots(const std::vector<SessionState*>& slots, std::string& err) { |
| 5344 | const OnDevice on_device(device_); |
| 5345 | if (g_ == nullptr || ss_ == nullptr) { err = "verify: init_slots before init"; return false; } |
| 5346 | if (slots.empty()) { |
| 5347 | err = "verify: init_slots needs at least one session"; |
| 5348 | return false; |
| 5349 | } |
| 5350 | #ifdef STRATA_WITH_LOOP |
| 5351 | if (cyclic()) { |
| 5352 | err = "verify: batch windows do not run on a cyclic layer split"; |
| 5353 | return false; |
| 5354 | } |
| 5355 | #endif |
| 5356 | for (SessionState* x : slots) { |
| 5357 | if (x == nullptr || x->layer_lo != ss_->layer_lo || x->layer_hi != ss_->layer_hi || |
| 5358 | x->max_cells != ss_->max_cells || x->gdn_ord0 != ss_->gdn_ord0 || x->qsa_ord0 != ss_->qsa_ord0) { |
| 5359 | err = "verify: a slot's session is not carved like the stage's own (layer range, context)"; |
| 5360 | return false; |
| 5361 | } |
| 5362 | } |
| 5363 | #if defined(STRATA_GPU_METAL) |
| 5364 | // the Metal window keeps each slot's running state itself (metal/src/engine/window.cpp): none of the CUDA batch buffers |
| 5365 | slots_ = slots; |
| 5366 | slot_sp_.assign(slots.size(), sampling_); |
| 5367 | slot_bias_dev_.assign(slots.size(), nullptr); |
| 5368 | slot_tail_.assign(slots.size(), {}); |
| 5369 | if (metal_ == nullptr || !strata::metal_engine::window_init_slots(metal_, slots, err)) { |
| 5370 | if (err.empty()) err = "verify: the Metal window is not up"; |
| 5371 | return false; |
| 5372 | } |
| 5373 | std::fprintf(stderr, "strata verify: batch windows of up to %d sequences, run slot by slot in the Metal window\n", (int) slots.size()); |
| 5374 | return true; |
| 5375 | #endif |
| 5376 | const strata::kernels::QsaShapes s = shapes_of(*g_); |
| 5377 | const int64_t S = (int64_t) slots.size(), CB = 2 + max_t_; |
| 5378 | const int64_t TS = (s.idx_block - 1) * g_->idx_key_dim, nQ = g_->n_qsa_layers(); |
| 5379 | void* d = nullptr; |
| 5380 | if (!mapped((size_t) (S * CB * 4 + 16), (void**) &h_commitb_, (void**) &m_commitb_)) { |
| 5381 | err = "verify: the batch commit staging failed"; |
| 5382 | return false; |
| 5383 | } |
| 5384 | const uint64_t a = ((uint64_t) S * CB * 4 + 255) & ~255ull; |
| 5385 | if (cudaMalloc(&d, a + (uint64_t) S * std::max<int64_t>(nQ, 1) * TS * 4) != cudaSuccess) { |
| 5386 | err = "verify: the batch buffers do not fit"; |
| 5387 | return false; |
| 5388 | } |
| 5389 | arena_b_ = d; |
| 5390 | commitb_ = (int32_t*) d; |
| 5391 | tail_snap_b_ = (float*) ((uint8_t*) d + a); |
| 5392 | slots_ = slots; |
| 5393 | slot_sp_.assign(slots.size(), sampling_); // greedy until set_slot_sampling |
| 5394 | slot_bias_dev_.assign(slots.size(), nullptr); |
| 5395 | slot_tail_.assign(slots.size(), {}); |
| 5396 | std::fprintf(stderr, "strata verify: batch windows of up to %lld sequences (layers [%lld, %lld))%s\n", (long long) S, |
| 5397 | (long long) lb_, (long long) le_, g_batch_self_commit ? ", one-row windows keep their rows" : ""); |
| 5398 | if (g_batch_attn_rows || g_batch_gdn_groups) { // #2234: which are on, and when attention cannot use its own |
| 5399 | bool streamed = false; // a slot whose KV streams (kv_mode 1) keeps the per-row attention launches |
| 5400 | for (const SessionState* x : slots) |
nothing calls this directly
no test coverage detected