| 3583 | } |
| 3584 | |
| 3585 | void RouterLookahead::submit(int64_t layer, const float* x, int64_t n_tok, const int32_t* host_res) { |
| 3586 | if (layer + 1 >= (int64_t) routers_.size() || n_tok <= 0 || x == nullptr) return; |
| 3587 | { |
| 3588 | std::lock_guard<std::mutex> lk(mu_); |
| 3589 | // Zero-drop latest-submission overwrite: even when busy_ is true, overwrite the pending staging slot |
| 3590 | // (worker runs from work_x_ / work_res_) so the freshest L+1/L+2 prediction is never skipped! |
| 3591 | if (pending_) skipped_.fetch_add(1, std::memory_order_relaxed); // superseded unstarted older layer |
| 3592 | n_tok_ = std::min<int64_t>(n_tok, 8); |
| 3593 | std::memcpy(x_.data(), x, (size_t) (n_tok_ * n_embd_) * sizeof(float)); |
| 3594 | layer_ = layer + 1; |
| 3595 | has_res_ = host_res != nullptr; |
| 3596 | if (has_res_) { // the rows of layer + 1 .. + depth, as they are now: the table changes while this runs |
| 3597 | const int64_t l1 = std::min<int64_t>(layer_ + depth_, (int64_t) routers_.size()); |
| 3598 | res_.assign(host_res + (size_t) (layer_ * n_expert_), host_res + (size_t) (l1 * n_expert_)); |
| 3599 | } |
| 3600 | sub_gen_ = gen_.load(std::memory_order_relaxed); |
| 3601 | pending_ = true; |
| 3602 | } |
| 3603 | cv_.notify_one(); |
| 3604 | } |
| 3605 | |
| 3606 | void RouterLookahead::enable_stats(int64_t n_layers) { |
| 3607 | words_ = (n_expert_ + 63) / 64; |