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

Method run_split_multi_native

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

Source from the content-addressed store, hash-verified

1635}
1636
1637void ExpertPool::run_split_multi_native(const NativeFmt& f, ExpertJobMulti* jobs, int n, NativeArithmetic arithmetic) {
1638 if (n <= 0) return;
1639 const auto t0 = std::chrono::steady_clock::now();
1640 // more distinct experts than buffers: run them in batches
1641 for (int b0 = 0; b0 < n; b0 += kMaxSplitMulti) {
1642 const int nb = (std::min)(kMaxSplitMulti, n - b0);
1643 mjobs_ = jobs + b0;
1644 nfmt_ = &f;
1645 narithmetic_ = arithmetic;
1646 if (dep_on_ && !static_slices_ && numa_n_ == 0 && n_ > 1 && !q2_native_kernels(f.gu_type) && !q2_native_kernels(f.d_type)) {
1647 // BW-G (STRATA_POOL_DEP=1): the whole layer call as one batch, no barrier between the phases (DepExpert, pool.hpp)
1648 const int per_phase = phase_tasks((int64_t) nb * f.n_ff);
1649 dep_nb_ = nb;
1650 dep_k_gu_ = (std::max)(1, (std::min)((int) f.n_ff, (per_phase + nb - 1) / nb));
1651 dep_k_dn_ = (std::max)(1, (std::min)((int) f.n_embd, (phase_tasks((int64_t) nb * f.n_embd) + nb - 1) / nb));
1652 for (int e = 0; e < nb; ++e) {
1653 dep_[(size_t) e].gu_left.store(dep_k_gu_, std::memory_order_relaxed);
1654 dep_[(size_t) e].quant.store(0, std::memory_order_relaxed);
1655 }
1656 const auto a = std::chrono::steady_clock::now();
1657 run_phase(7, nb * (dep_k_gu_ + dep_k_dn_));
1658 const auto b = std::chrono::steady_clock::now();
1659 ms_multi_gu += std::chrono::duration<double, std::milli>(b - a).count();
1660 if (diag_pool_on()) ++dg_batches_;
1661 continue;
1662 }
1663 mrows_ = (int64_t) nb * f.n_ff;
1664 mtasks_ = static_slices_ ? n_ : numa_n_ > 0 ? numa_plan_phase((int) f.n_ff, nb) : phase_tasks(mrows_);
1665 const auto a = std::chrono::steady_clock::now();
1666 run_phase(5, mtasks_, static_slices_);
1667 const auto b = std::chrono::steady_clock::now();
1668 for (int e = 0; e < nb; ++e)
1669 for (int t = 0; t < mjobs_[e].nt; ++t)
1670 if (q2_native_kernels(f.d_type)) act_quant_any(split_multi_[(size_t) e].ff[t], FF, split_multi_[(size_t) e].a2[t]);
1671 else native_quant_h(f, split_multi_[(size_t) e].ff[t], split_multi_[(size_t) e].hq[t]);
1672 const auto c = std::chrono::steady_clock::now();
1673 mrows_ = (int64_t) nb * f.n_embd;
1674 mtasks_ = static_slices_ ? n_ : numa_n_ > 0 ? numa_plan_phase((int) f.n_embd, nb) : phase_tasks(mrows_);
1675 run_phase(6, mtasks_, static_slices_);
1676 const auto d = std::chrono::steady_clock::now();
1677 ms_multi_gu += std::chrono::duration<double, std::milli>(b - a).count();
1678 ms_multi_q += std::chrono::duration<double, std::milli>(c - b).count();
1679 ms_multi_down += std::chrono::duration<double, std::milli>(d - c).count();
1680 if (diag_pool_on()) {
1681 ++dg_batches_;
1682 dg_quant_ns_ += std::chrono::duration_cast<std::chrono::nanoseconds>(c - b).count();
1683 }
1684 }
1685 multi_bytes += (int64_t) n * (int64_t) f.bytes;
1686 mode_ = 0;
1687 const auto t_end = std::chrono::steady_clock::now();
1688 ms_drain_ += std::chrono::duration<double, std::milli>(t_end - t0).count();
1689 if (diag_pool_on()) {
1690 ++dg_calls_;
1691 dg_experts_ += n;
1692 for (int e = 0; e < n; ++e) dg_entries_ += jobs[e].nt;
1693 dg_run_ns_ += std::chrono::duration_cast<std::chrono::nanoseconds>(t_end - t0).count();
1694 if (dg_calls_ % 2000 == 0) diag_pool_print("running");

Callers 6

mainFunction · 0.45
realFunction · 0.45
mainFunction · 0.45
prefill.cppFile · 0.45

Calls 7

q2_native_kernelsFunction · 0.85
diag_pool_onFunction · 0.85
act_quant_anyFunction · 0.85
nowFunction · 0.70
native_quant_hFunction · 0.70
storeMethod · 0.45
countMethod · 0.45

Tested by 2

realFunction · 0.36
mainFunction · 0.36