Merge f-028-par

This commit is contained in:
Niko1221 committed 2026-10-29 15:11:01 +01:00
commit 32f0c44f08
29 files changed
+1024 -128

No files matched your search

+18 -17
View File
@@ -135,7 +135,7 @@ struct RouteResidentCfg {
RouteResidentCfg& c = route_resident_cfg();
for (const auto& kv : c.blocks) {
if (kv.second == nullptr) continue;
unsigned long long h[8] = {};
unsigned long long h[8] = {}; // (the counter block allocated above: 8 words)
if (cudaSetDevice(kv.first) != cudaSuccess || cudaDeviceSynchronize() != cudaSuccess ||
cudaMemcpy(h, kv.second, sizeof(h), cudaMemcpyDeviceToHost) != cudaSuccess) {
(void) cudaGetLastError();
@@ -801,7 +801,7 @@ bool Verifier::init(const WeightTable& wt, const ModelGeometry& g, SessionState&
return strata::metal_engine::window_init(metal_, g, ss, max_t, ss.qsa_states[ss.qsa_primary()].max_cells, &n_vocab_,
err);
#endif
if (max_t < 2 || max_t > strata::kernels::kVerifyMaxT || max_t > strata::kernels::cpu::MAXT) {
if (max_t < 2 || max_t > strata::kernels::kVerifyMaxT) { // (the CPU experts take a wider window as jobs of at most cpu::MAXT tokens)
err = "verify: the window must hold 2.." + std::to_string(strata::kernels::kVerifyMaxT) + " tokens";
return false;
}
@@ -1453,7 +1453,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
pending = false;
}
auto gr_read_group = [&](int half, bool apply, float* inj_prev, float* inj_out) {
FusedGrArgs fa[kFusedGrMaxT];
FusedGrArgs fa[kFusedGrWideT];
for (int t = tb; t < te; ++t) {
FusedGrArgs& a = fa[t - tb];
a.R = Rt(t); a.R_out = Rt(t); a.apply = apply;
@@ -2232,8 +2232,8 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
native_expert_grouped(L, gp, gs, gn, p_dst, p_tok, cap, cap,
nat_xq_ + (size_t) tb * (N / 32) * 36, hit_scratch_, dst_buf, cs, gy);
} else {
moe_grouped_s2(gp, gs, gn, p_dst, p_tok, cap, cap, hit_xq_ + (size_t) tb * (N / 32) * 34,
hit_xs_ + (size_t) tb * (N / 32), hit_scratch_, dst_buf, cs);
moe_grouped_s2_window(gp, gs, gn, p_dst, p_tok, cap, cap, hit_xq_ + (size_t) tb * (N / 32) * 34,
hit_xs_ + (size_t) tb * (N / 32), hit_scratch_, dst_buf, cs, n); // (a group holds <= n entries)
}
};
bool hits_in_combine = false;
@@ -2390,7 +2390,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
// (no pending write, no inject)
const bool mix_q8 = hd->hc_q8 != nullptr && hu->hc_q8 != nullptr && head_ != nullptr && head_->loaded();
if (mix_q8) {
FusedGrArgs fa[kFusedGrMaxT];
FusedGrArgs fa[kFusedGrWideT];
for (int t = 0; t < T; ++t) {
FusedGrArgs& a = fa[t];
a.R = Rt(t); a.R_out = Rt(t); a.apply = false;
@@ -2403,7 +2403,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
fused_gr_read_multi(fa, T, xn_, cs);
}
else if (fuse_head_gr) {
FusedGrArgs fa[kFusedGrMaxT];
FusedGrArgs fa[kFusedGrWideT];
for (int t = 0; t < T; ++t) {
FusedGrArgs& a = fa[t];
a.R = Rt(t); a.R_out = Rt(t); a.apply = true;
@@ -2426,7 +2426,7 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
err = "verify: the output_hc_* weights have the wrong engine forms";
return false;
}
FusedGrArgs fa[kFusedGrMaxT];
FusedGrArgs fa[kFusedGrWideT];
for (int t = 0; t < T; ++t) {
fa[t].R = Rt(t); fa[t].R_out = Rt(t); fa[t].apply = false;
fa[t].w_norm = (const float*) hn->data; fa[t].w_down = (const uint16_t*) hd->data;
@@ -4134,9 +4134,10 @@ bool Verifier::evict_batch_graph(const std::vector<int>& keep, bool& evicted, st
bool Verifier::evict_window_graph(int keep_t, bool& evicted, std::string& err) {
evicted = false;
if (no_window_eviction_ || keep_t < 1) return true;
bool have[9] = {};
for (int t = 1; t <= max_t_ && t < 9; ++t) have[t] = (ar_off_ ? exec_nr_[sel_long_][t] : exec_[sel_long_][t]) != nullptr;
const int victim = strata::core::pick_window_victim(have, std::min(max_t_, 8), keep_t, prelaunched_);
bool have[strata::kernels::kWindowMaxT + 1] = {};
const int top = std::min<int>(max_t_, strata::kernels::kWindowMaxT);
for (int t = 1; t <= top; ++t) have[t] = (ar_off_ ? exec_nr_[sel_long_][t] : exec_[sel_long_][t]) != nullptr;
const int victim = strata::core::pick_window_victim(have, top, keep_t, prelaunched_);
if (victim == 0) return true;
if (cudaStreamSynchronize(cs_) != cudaSuccess) {
err = "verify: synchronizing before window graph eviction failed";
@@ -4294,9 +4295,9 @@ bool Verifier::stage_batch(const int* rows, int S, int hbase, const int32_t* tok
std::string& err) {
using namespace strata::kernels;
// the row layout: a slot may own a contiguous group of rows (--batch-mtp), also across the stages of a layer split,
// whose hand-off buffers hold kVerifyMaxT rows, or set_handoff_rows' (a stage that hands rows on or takes them)
// whose hand-off buffers hold kVerifyNarrowT rows, or set_handoff_rows' (a stage that hands rows on or takes them)
if (const char* why = batch_rows_error(rows, S, pos, (int) slots_.size(), max_t_, hbase,
next_ != nullptr || lb_ > 0, handoff_rows_ > 0 ? handoff_rows_ : kVerifyMaxT)) {
next_ != nullptr || lb_ > 0, handoff_rows_ > 0 ? handoff_rows_ : kVerifyNarrowT)) {
err = why;
return false;
}
@@ -4371,8 +4372,8 @@ bool Verifier::stage_batch(const int* rows, int S, int hbase, const int32_t* tok
bool Verifier::run_slots(int S, const int32_t* tokens, const int64_t* pos, PoolMultiFn pool, void* user, int32_t* out,
std::string& err) {
int rows[8] = {};
for (int t = 0; t < S && t < 8; ++t) rows[t] = t;
int rows[strata::kernels::kVerifyMaxT] = {};
for (int t = 0; t < S && t < strata::kernels::kVerifyMaxT; ++t) rows[t] = t;
return run_slot_rows(rows, S, tokens, pos, pool, user, out, err);
}
@@ -4548,8 +4549,8 @@ bool Verifier::sample_rows(int S, std::string& err) {
bool Verifier::batch_launch(int base, int S, const int32_t* tokens, const int64_t* pos, std::string& err) {
const OnDevice on_device(device_);
if (b_running_) { err = "verify: batch_launch while this stage is busy"; return false; }
int rows[8] = {};
for (int t = 0; t < S && t < 8; ++t) rows[t] = base + t;
int rows[strata::kernels::kVerifyMaxT] = {};
for (int t = 0; t < S && t < strata::kernels::kVerifyMaxT; ++t) rows[t] = base + t;
if (pre_launch_ && !pre_launch_(cs_, err)) return false;
if (!stage_batch(rows, S, base, tokens, pos, err)) return false;
cudaError_t le = cudaGraphLaunch(exec_bm_[bkey(rows, S, base)], cs_);