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

Method dep_task

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

BW-G: task i of a mode-7 batch (see DepExpert in pool.hpp): i < nb * k_gu = gate/up rows, then down rows.

Source from the content-addressed store, hash-verified

1491
1492// BW-G: task i of a mode-7 batch (see DepExpert in pool.hpp): i < nb * k_gu = gate/up rows, then down rows.
1493void ExpertPool::dep_task(int i) {
1494 const NativeFmt& f = *nfmt_;
1495 const int ngu = dep_nb_ * dep_k_gu_;
1496 if (i < ngu) {
1497 const int e = i / dep_k_gu_, p = i % dep_k_gu_;
1498 const int h = (int) f.n_ff;
1499 const int r0 = (int) ((int64_t) h * p / dep_k_gu_), r1 = (int) ((int64_t) h * (p + 1) / dep_k_gu_);
1500 SplitBufMulti& sb = split_multi_[(size_t) e];
1501 const NativeFmt* const nfmt = mjobs_[e].fmt != nullptr ? mjobs_[e].fmt : nfmt_;
1502 float* ff[MAXT];
1503 for (int t = 0; t < mjobs_[e].nt; ++t) ff[t] = sb.ff[t];
1504 if (narithmetic_ == NativeArithmetic::WindowInvariant)
1505 native_gu_rows_invariant(*nfmt, mjobs_[e].blob, mjobs_[e].nact, mjobs_[e].nt, ff, r0, r1);
1506 else
1507 native_gu_rows(*nfmt, mjobs_[e].blob, mjobs_[e].nact, mjobs_[e].nt, ff, r0, r1);
1508 dep_[(size_t) e].gu_left.fetch_sub(1, std::memory_order_release); // the rows above are visible to whoever sees the count reach 0
1509 return;
1510 }
1511 const int j = i - ngu;
1512 const int e = j / dep_k_dn_, p = j % dep_k_dn_;
1513 DepExpert& d = dep_[(size_t) e];
1514 while (d.gu_left.load(std::memory_order_acquire) > 0) strata_cpu_pause(); // this expert's gate/up tasks all claimed earlier: one of them is running
1515 int expect = 0;
1516 SplitBufMulti& sb = split_multi_[(size_t) e];
1517 if (d.quant.compare_exchange_strong(expect, 1, std::memory_order_acquire)) {
1518 for (int t = 0; t < mjobs_[e].nt; ++t) native_quant_h(f, sb.ff[t], sb.hq[t]);
1519 d.quant.store(2, std::memory_order_release);
1520 } else {
1521 while (d.quant.load(std::memory_order_acquire) != 2) strata_cpu_pause();
1522 }
1523 const int h = (int) f.n_embd;
1524 const int r0 = (int) ((int64_t) h * p / dep_k_dn_), r1 = (int) ((int64_t) h * (p + 1) / dep_k_dn_);
1525 const NativeFmt* const nfmt = mjobs_[e].fmt != nullptr ? mjobs_[e].fmt : nfmt_;
1526 const void* hq[MAXT];
1527 for (int t = 0; t < mjobs_[e].nt; ++t) hq[t] = sb.hq[t];
1528 if (narithmetic_ == NativeArithmetic::WindowInvariant)
1529 native_down_rows_invariant(*nfmt, mjobs_[e].blob, hq, mjobs_[e].nt, mjobs_[e].out, r0, r1);
1530 else
1531 native_down_rows(*nfmt, mjobs_[e].blob, hq, mjobs_[e].nt, mjobs_[e].out, r0, r1);
1532}
1533
1534void ExpertPool::run_range(int n_tasks, void (*fn)(void*, int), void* ctx) {
1535 if (n_tasks <= 0 || fn == nullptr) return;

Callers

nothing calls this directly

Calls 10

strata_cpu_pauseFunction · 0.85
fetch_subMethod · 0.80
native_gu_rows_invariantFunction · 0.70
native_gu_rowsFunction · 0.70
native_quant_hFunction · 0.70
native_down_rowsFunction · 0.70
loadMethod · 0.45
storeMethod · 0.45

Tested by

no test coverage detected