MCPcopy Create free account
hub / github.com/Niko1221/Strata / drain

Method drain

engine/src/kernels/cpu/pool.cpp:1391–1490  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1389}
1390
1391void ExpertPool::drain(int id, ExpertScratch& scratch, uint32_t epoch) {
1392 if (per_worker_) { // task j on worker j, once per batch; the host has none (it never calls this for such a batch)
1393 if (id < 0 || id >= n_) return;
1394 wstate_[(size_t) id].store(id, std::memory_order_relaxed);
1395 if (mode_ == 9) prefetch_task(id);
1396 else {
1397 const int per = mode_ == 5 ? (int) nfmt_->n_ff : (int) nfmt_->n_embd;
1398 const int r0 = (int) ((int64_t) per * id / n_), r1 = (int) ((int64_t) per * (id + 1) / n_);
1399 const int nb = (int) (mrows_ / per);
1400 if (r1 > r0)
1401 for (int e = 0; e < nb; ++e) native_rows(e, r0, r1);
1402 }
1403 done_.fetch_add(1, std::memory_order_release);
1404 return;
1405 }
1406 const int s = numa_n_ == 0 ? 0 : id >= 0 ? wslice_[(size_t) id] : hslice_;
1407 for (;;) {
1408 // STRATA_NUMA_SPLIT: a mode-5/6 batch lives on the slice heads, any other on `head_`; the epoch tag makes the
1409 // other family's claim fail, so `mode_` is never read before a claim has succeeded (pool.hpp)
1410 int ci = numa_n_ > 0 ? claim_slice(epoch, s) : -1;
1411 const bool sliced = ci >= 0;
1412 if (!sliced) ci = claim(epoch);
1413 if (ci < 0) break;
1414 const uint32_t i = (uint32_t) ci;
1415 const bool dg_task = diag_pool_on() && mode_ >= 5;
1416 const int64_t dg_t0 = dg_task ? now_ns() : 0;
1417 if (id >= 0) wstate_[(size_t) id].store(ci, std::memory_order_relaxed);
1418 else { hstate_.store(ci, std::memory_order_relaxed); hstate_ms_.store(now_ms(), std::memory_order_relaxed); }
1419 if (mode_ == 0) {
1420 const ExpertJob& j = jobs_[i];
1421 s2_expert_vnni_q(j.blob, *j.act, j.out, scratch);
1422 } else if (mode_ == 1) {
1423 const int e = (int) i / parts_a_, part = (int) i % parts_a_;
1424 const int r0 = FF * part / parts_a_, r1 = FF * (part + 1) / parts_a_;
1425 s2_expert_gu_rows(jobs_[e].blob, *jobs_[e].act, split_[(size_t) e].ff, r0, r1);
1426 } else if (mode_ == 2) {
1427 const int e = (int) i / parts_b_, part = (int) i % parts_b_;
1428 const int r0 = H * part / parts_b_, r1 = H * (part + 1) / parts_b_;
1429 s2_expert_down_rows(jobs_[e].blob, split_[(size_t) e].a2, jobs_[e].out, r0, r1);
1430 } else if (mode_ == 8) {
1431 range_fn_(range_ctx_, (int) i);
1432 } else if (mode_ == 7) {
1433 dep_task((int) i); // BW-G: the one-batch layer call (STRATA_POOL_DEP)
1434 } else if (mode_ >= 5) {
1435 // plan v0.3 P6: native layers, 5 = gate/up rows, 6 = down rows (the layer's own n_ff / n_embd: Flash-Next's
1436 // FF / H, or another family's smaller expert)
1437 // Task j of T over R rows of `h` per expert from matrix row `row0`: the whole phase (R = mrows_, h = per,
1438 // row0 = 0) or, under the NUMA split, this thread's slice (slice-local row g -> expert g / h, matrix row
1439 // row0 + g % h)
1440 const int per = mode_ == 5 ? (int) nfmt_->n_ff : (int) nfmt_->n_embd;
1441 int64_t R = mrows_, T = mtasks_, j = i;
1442 int h = per, row0 = 0;
1443 if (sliced) {
1444 const NodeSync& ns = nsync_[(size_t) s];
1445 R = ns.rows; T = ns.tasks; h = ns.h; row0 = ns.row0; j = ci - ns.base;
1446 }
1447 const int64_t g0 = R * j / T, g1 = R * (j + 1) / T;
1448 for (int64_t g = g0; g < g1;) {

Callers 2

loop-stop.test.mjsFile · 0.45

Calls 10

diag_pool_onFunction · 0.85
fetch_addMethod · 0.80
now_nsFunction · 0.70
now_msFunction · 0.70
s2_expert_vnni_qFunction · 0.70
s2_expert_gu_rowsFunction · 0.70
s2_expert_down_rowsFunction · 0.70
s2_expert_gu_rows_multiFunction · 0.70
storeMethod · 0.45

Tested by 1