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

Method prefetch_task

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

Source from the content-addressed store, hash-verified

1711}
1712
1713void ExpertPool::prefetch_task(int j) {
1714 const L3Prefetch& q = pfq_;
1715 const int W = n_;
1716 auto stop = [&] { return pf_abort_.load(std::memory_order_acquire); };
1717 // 1. this worker's experts of the router: logits [t][e] for e in [e0, e1)
1718 const int e0 = q.n_expert * j / W, e1 = q.n_expert * (j + 1) / W, ne = e1 - e0;
1719 if (ne > 0) {
1720 thread_local std::vector<float> tmp;
1721 tmp.resize((size_t) ne * (size_t) q.nt);
1722 for (int t0 = 0; t0 < q.nt; t0 += 8) {
1723 const int nt = (std::min)(8, q.nt - t0);
1724 const uint16_t* rw = q.router + (size_t) e0 * (size_t) q.n_embd;
1725 const float* rx = pf_x_.data() + (size_t) t0 * (size_t) q.n_embd;
1726#if defined(STRATA_NATIVE_EXPERTS)
1727 if (cpu_avx2_ok()) {
1728 bf16_rows_dot_multi(rw, ne, q.n_embd, rx, nt, tmp.data());
1729 } else {
1730 for (int t = 0; t < nt; ++t) {
1731 const float* xt = rx + (size_t) t * (size_t) q.n_embd;
1732 float* ot = tmp.data() + (size_t) t * (size_t) ne;
1733 for (int r = 0; r < ne; ++r) {
1734 const uint16_t* wr = rw + (size_t) r * (size_t) q.n_embd;
1735 float s = 0.0f;
1736 for (int k = 0; k < q.n_embd; ++k) {
1737 const uint32_t u = (uint32_t) wr[k] << 16;
1738 float wv;
1739 std::memcpy(&wv, &u, sizeof(wv));
1740 s += wv * xt[k];
1741 }
1742 ot[r] = s;
1743 }
1744 }
1745 }
1746#else
1747 for (int t = 0; t < nt; ++t) {
1748 const float* xt = rx + (size_t) t * (size_t) q.n_embd;
1749 float* ot = tmp.data() + (size_t) t * (size_t) ne;
1750 for (int r = 0; r < ne; ++r) {
1751 const uint16_t* wr = rw + (size_t) r * (size_t) q.n_embd;
1752 float s = 0.0f;
1753 for (int k = 0; k < q.n_embd; ++k) {
1754 const uint32_t u = (uint32_t) wr[k] << 16;
1755 float wv;
1756 std::memcpy(&wv, &u, sizeof(wv));
1757 s += wv * xt[k];
1758 }
1759 ot[r] = s;
1760 }
1761 }
1762#endif
1763 for (int t = 0; t < nt; ++t)
1764 std::memcpy(pf_logits_.data() + (size_t) (t0 + t) * (size_t) q.n_expert + (size_t) e0,
1765 tmp.data() + (size_t) t * (size_t) ne, (size_t) ne * sizeof(float));
1766 }
1767 }
1768 // 2. every worker's logits are in
1769 pf_arrive_.fetch_add(1, std::memory_order_acq_rel);
1770 while (pf_arrive_.load(std::memory_order_acquire) < W) {

Callers

nothing calls this directly

Calls 14

memcpyFunction · 0.85
strata_cpu_pauseFunction · 0.85
fetch_addMethod · 0.80
assignMethod · 0.80
cpu_avx2_okFunction · 0.70
bf16_rows_dot_multiFunction · 0.70
stopFunction · 0.50
touchFunction · 0.50
loadMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected