the drafts of the lanes still going for their next window: their lookups, the plan, then per lane the draft layer (it reads the lane's kept rows either way, so its cells stay current) and its chain where no lookup stands
| 260 | // the drafts of the lanes still going for their next window: their lookups, the plan, then per lane the draft layer |
| 261 | // (it reads the lane's kept rows either way, so its cells stay current) and its chain where no lookup stands |
| 262 | void BatchDecoder::draft_next(const std::vector<BatchLane*>& lanes, const std::vector<int>& going, const std::vector<int>& r0, |
| 263 | const std::vector<std::vector<int>>& got) { |
| 264 | if (going.empty()) return; |
| 265 | const bool mtp = mode_ == BatchDrafts::mtp; |
| 266 | const bool df2 = mtp && e_.df2_on(); // the draft source of the 'mtp' mode is DFlash2 when it is attached |
| 267 | std::vector<std::vector<int>> look(going.size()); |
| 268 | std::vector<int> chain_room(going.size()); |
| 269 | std::vector<RowOffer> offers(going.size()); |
| 270 | for (size_t g = 0; g < going.size(); ++g) { |
| 271 | BatchLane& L = *lanes[(size_t) going[g]]; |
| 272 | look[g] = lookup_drafts(L.ctx, LK_, -1); |
| 273 | // a chain's draft j writes the draft layer's cell at the lane's position - 1 + j: within the pages the lane holds |
| 274 | // (taking a page here could find the pool empty; the next window's own pages come before it runs). Either way |
| 275 | // the window's rows take positions pos .. pos + drafts, inside the context (as Session::generate clamps them) |
| 276 | const int pos = e_.lane_pos(L.lane), ctx_room = std::max(0, e_.max_ctx() - pos - 1); |
| 277 | chain_room[g] = std::min({K_, e_.lane_pages(L.lane) * KVP_POS - pos, ctx_room}); |
| 278 | if (df2) chain_room[g] = std::min({K_, df2::kDrafts, ctx_room}); // DFlash2 writes no cells of the draft layer: only the context bounds its drafts |
| 279 | RowOffer& of = offers[g]; |
| 280 | if (!look[g].empty() || !mtp) { |
| 281 | of.avail = std::min({(int) look[g].size(), MAXT - 1, ctx_room}); |
| 282 | of.reach = reach_of(L.lk_tried, L.lk_stood, of.avail); |
| 283 | } else { |
| 284 | of.avail = chain_room[g]; |
| 285 | of.reach = reach_of(L.tried, L.stood, of.avail); |
| 286 | of.chain = !df2; // (a DFlash2 draft costs no call of its own after the lane's round) |
| 287 | of.explore = (L.chains + 1) % 4 == 0; |
| 288 | } |
| 289 | } |
| 290 | const int ng = (int) going.size(); |
| 291 | static const double df2_call_ms = env_num("FNX_DF2_CALL_MS", 2.5); // one lane's drafter round (about 3 ms alone, overlapped between lanes) |
| 292 | for (RowOffer& of : offers) of.first_ms = df2 ? df2_call_ms : 0.0; // (a lane that drafts nothing banks its taps and pays no round) |
| 293 | const double base = cost_.round_ms + cost_.rows_ms(ng) + (mtp && !df2 ? cost_.call_ms * ng : 0.0); |
| 294 | std::vector<int> plan; |
| 295 | if (fixed_ >= 0) { |
| 296 | for (const RowOffer& of : offers) plan.push_back(std::min(fixed_, of.avail)); |
| 297 | } else { |
| 298 | std::vector<int> ids; |
| 299 | for (int i : going) ids.push_back(lanes[(size_t) i]->lane); |
| 300 | const std::vector<std::vector<int>> held = e_.held_layouts(ids); |
| 301 | plan = choose_rows(offers, MAXT, base, cost_, held, capture_ms_ / horizon_); |
| 302 | // what the plan would be with captures free: the same one blocked by the capture's charge SWITCH_AFTER windows |
| 303 | // in a row is a lasting preference (the first windows' priors can hold a layout that never pays), so it goes in |
| 304 | // and the capture is paid once |
| 305 | const std::vector<int> free_plan = choose_rows(offers, MAXT, base, cost_, held, 0.0); |
| 306 | if (free_plan != plan) { |
| 307 | blocked_streak_ = free_plan == blocked_ ? blocked_streak_ + 1 : 1; |
| 308 | blocked_ = free_plan; |
| 309 | if (blocked_streak_ >= SWITCH_AFTER) { |
| 310 | plan = free_plan; |
| 311 | blocked_streak_ = 0; |
| 312 | } |
| 313 | } else { |
| 314 | blocked_streak_ = 0; |
| 315 | } |
| 316 | } |
| 317 | if (trace_) { // FNX_BATCH_TRACE: each lane's offer (chain or lookup, reach by position) and its plan |
| 318 | std::string s = "batch plan:"; |
| 319 | for (size_t g = 0; g < offers.size(); ++g) { |
nothing calls this directly
no test coverage detected