one window for every decoding slot: a row each
| 584 | |
| 585 | // one window for every decoding slot: a row each |
| 586 | void decode_step() { |
| 587 | for (int i = 0; i < (int) slots.size(); ++i) |
| 588 | if (slots[(size_t) i].paused && slot_stopped(i)) { |
| 589 | slots[(size_t) i].paused = false; |
| 590 | slots[(size_t) i].held.reset(); |
| 591 | finish_slot(i, fnx::Finish::cancel); |
| 592 | } |
| 593 | resume_paused(); |
| 594 | std::vector<int> rows; |
| 595 | for (int i = 0; i < (int) slots.size(); ++i) { |
| 596 | if (!slots[(size_t) i].decoding) continue; |
| 597 | if (slot_stopped(i)) { |
| 598 | finish_slot(i, fnx::Finish::cancel); |
| 599 | continue; |
| 600 | } |
| 601 | rows.push_back(i); |
| 602 | } |
| 603 | // with drafts, a lane's rows: within the window's MAXT, then their pages if idle lanes can give them, else its |
| 604 | // drafts cut to the pages it holds (at least its first row, which the loop below sees to as without drafts) |
| 605 | if (dec && !rows.empty()) { |
| 606 | std::vector<fnx::BatchLane*> ls; |
| 607 | for (int i : rows) ls.push_back(&slots[(size_t) i].bl); |
| 608 | fnx::BatchDecoder::fit(ls); |
| 609 | int want = 0; |
| 610 | for (int i : rows) { |
| 611 | const int lane = slots[(size_t) i].lane; |
| 612 | want += std::max(0, pages_for(e.lane_pos(lane) + slots[(size_t) i].bl.rows()) - e.lane_pages(lane)); |
| 613 | } |
| 614 | if (want > 0 && !make_room(want, -1)) |
| 615 | for (int i : rows) { |
| 616 | const int lane = slots[(size_t) i].lane; |
| 617 | slots[(size_t) i].bl.cut(std::max(1, e.lane_pages(lane) * fnx::KVP_POS - 1 - e.lane_pos(lane))); |
| 618 | } |
| 619 | } |
| 620 | auto rows_of = [&](int i) { return dec ? slots[(size_t) i].bl.rows() : 1; }; |
| 621 | // a lane that crosses into a new page needs one free: idle lanes are parked for it, else it sits this window out; |
| 622 | // when that leaves no lane to run, a decoding slot is paused (its conversation parked) for the others' pages |
| 623 | for (;;) { |
| 624 | if (rows.empty()) return; |
| 625 | int grow = 0; |
| 626 | for (int i : rows) grow += e.lane_pages(slots[(size_t) i].lane) < pages_for(e.lane_pos(slots[(size_t) i].lane) + rows_of(i)); |
| 627 | if (grow == 0 || make_room(grow, -1)) break; |
| 628 | std::vector<int> fit; |
| 629 | int left = e.free_pages(); |
| 630 | for (int i : rows) { |
| 631 | const int lane = slots[(size_t) i].lane; |
| 632 | const bool needs = e.lane_pages(lane) < pages_for(e.lane_pos(lane) + rows_of(i)); |
| 633 | if (!needs || left > 0) { |
| 634 | fit.push_back(i); |
| 635 | left -= needs; |
| 636 | } |
| 637 | } |
| 638 | if (!fit.empty()) { |
| 639 | for (int i : rows) |
| 640 | if (std::find(fit.begin(), fit.end(), i) == fit.end() && slots[(size_t) i].sat_out++ == 0) |
| 641 | std::fprintf(stderr, "sfnx: K/V pool short (%d pages free): slot %d waits for a page while %zu slot(s) decode\n", |
| 642 | e.free_pages(), i, fit.size()); |
| 643 | rows = fit; |
nothing calls this directly
no test coverage detected