| 5496 | void set_tail_skip_rank(int r) { g_tail_skip_rank.store(r > 0 && r < 10 ? r : 0, std::memory_order_relaxed); } |
| 5497 | |
| 5498 | void expert_pool_dispatch_multi(ExpertDispatch& d, const float* x_f, const int32_t* ids, int64_t n_tok, int64_t k, |
| 5499 | float* out, strata::kernels::cpu::NativeArithmetic arithmetic) { |
| 5500 | using namespace strata::kernels::cpu; |
| 5501 | if (d.failed) return; |
| 5502 | if (n_tok < 1 || n_tok > strata::kernels::kWindowMaxT) { |
| 5503 | d.failed = true; |
| 5504 | d.fail = "a verify window has more tokens than the multi-token expert kernel takes"; |
| 5505 | d.fail_layer = d.layers; |
| 5506 | return; |
| 5507 | } |
| 5508 | if (d.lookahead != nullptr) { |
| 5509 | if (d.lookahead->stats_on()) { |
| 5510 | if (d.layers == 0) d.lookahead->stats_window_start(); |
| 5511 | d.lookahead->stats_score(d.layers, ids, n_tok * k, d.host_res, d.pcie_num); |
| 5512 | } |
| 5513 | d.lookahead->submit(d.layers, x_f, n_tok, d.host_res); // CS-T: warm layer + 1 |
| 5514 | } |
| 5515 | if (k < 1 || n_tok * k > kMaxWindowEntries) { |
| 5516 | d.failed = true; |
| 5517 | d.fail = "a verify window routes more entries than the expert pool's window tables hold"; |
| 5518 | d.fail_layer = d.layers; |
| 5519 | return; |
| 5520 | } |
| 5521 | if ((int64_t) d.act_multi.size() < n_tok) d.act_multi.resize((size_t) strata::kernels::kWindowMaxT); |
| 5522 | const ExpertLayout& lay = expert_layout(); |
| 5523 | const bool native = lay.native; |
| 5524 | if (native && d.nact_multi.size() < (size_t) strata::kernels::kWindowMaxT * kNativeActBytes) |
| 5525 | d.nact_multi.resize((size_t) strata::kernels::kWindowMaxT * kNativeActBytes); |
| 5526 | if (d.job_of.size() != (size_t) d.n_expert) d.job_of.assign((size_t) d.n_expert, (int16_t) -1); |
| 5527 | if (d.jobs_multi.size() < (size_t) (n_tok * k)) d.jobs_multi.resize((size_t) (strata::kernels::kWindowMaxT * k)); |
| 5528 | static const bool ptrace = std::getenv("STRATA_POOL_TRACE") != nullptr; |
| 5529 | auto pt = [&](const char* what, long long a = -1) { |
| 5530 | if (ptrace) { std::fprintf(stderr, "pool trace: layer %lld %s %lld\n", (long long) d.layers, what, a); std::fflush(stderr); } |
| 5531 | }; |
| 5532 | const auto c0 = std::chrono::steady_clock::now(); |
| 5533 | const FileExpertSource::DecodeScope decode_scope; // 149 STRATA_IO_PF_GATE: this thread reads for the decode |
| 5534 | // 149-cold STRATA_COLD_OVERLAP: 0 off, 1 overlap, 2 measure only, 3 overlap + zero-copy, 4 zero-copy only. |
| 5535 | // 0.2.0: unset, 4 for the GGUF read in place on Linux (zero-copy needs the page cache's residency query), else 0 |
| 5536 | static const int cold_env = [] { |
| 5537 | const char* v = std::getenv("STRATA_COLD_OVERLAP"); |
| 5538 | return v == nullptr || v[0] == '\0' ? -1 : std::clamp(std::atoi(v), 0, 4); |
| 5539 | }(); |
| 5540 | d.cold_mode = cold_env >= 0 ? cold_env : (d.src != nullptr && d.src->linux_file_defaults() ? 4 : 0); |
| 5541 | pt("begin"); |
| 5542 | d.src->begin_layer(d.layers, ids, n_tok * k); |
| 5543 | pt("begun"); |
| 5544 | if (!d.usage.empty()) |
| 5545 | for (int64_t i = 0; i < n_tok * k; ++i) |
| 5546 | if (ids[i] >= 0 && ids[i] < d.n_expert) d.usage[(size_t) d.layers * (size_t) d.n_expert + (size_t) ids[i]] += 1.0f; |
| 5547 | // ---- plan v0.3 P6: the GPU's share, decided and published FIRST so the GPU starts while the CPU works. |
| 5548 | // Distinct experts in routing order; resident ones and the last pcie_num/256 of the missed ones go to the GPU. |
| 5549 | const int64_t n = n_tok * k; |
| 5550 | int32_t kind[kMaxWindowEntries]; // per entry: -1 CPU, 0 VRAM, 1 PCIe |
| 5551 | if (d.plan != nullptr && n <= kMaxWindowEntries && n <= d.plan->cap) { |
| 5552 | int64_t distinct[kMaxWindowEntries], first_of[kMaxWindowEntries]; |
| 5553 | int nd = 0, nmiss = 0; |
| 5554 | // a helper GPU (RemoteExperts) holding the expert computes it in its own VRAM once begin() claims the row: like |
| 5555 | // the peer tier's, such an expert is no miss of this plan and never part of the PCIe share, which would read it |
nothing calls this directly
no test coverage detected