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

Method launch_window

engine/src/core/peer_experts.cpp:418–481  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

416}
417
418bool PeerExperts::launch_window(int par, int64_t lb, int64_t le, int T, int k, uint32_t want_flag_start, int G) {
419 if (device_ < 0 || par < 0 || par >= 2 || !autonomous_) return false;
420 uint32_t* const d_seq = d_seq_[par];
421 uint32_t* const d_flag = d_target_flag_p_[par];
422 const float* const d_x_m = d_m_x_[par];
423 const int32_t* const d_ids_m = d_m_ids_[par];
424 float* const d_ymiss_m = d_m_ymiss_[par];
425 if (!d_seq || !d_flag || !d_x_m || !d_ids_m || !d_ymiss_m || !d_plans_ || !d_res_peer_) return false;
426
427 if (G < 1) G = 1;
428 On on(device_);
429 const cudaStream_t s = stream_;
430 // the residency table follows the swaps' copies on refill_: this window's plan kernels read it only after the upload landed
431 if (res_ev_pending_ && res_ev_ != nullptr) { cudaStreamWaitEvent(s, res_ev_, 0); res_ev_pending_ = false; }
432 const auto& lay = strata::kernels::cpu::expert_layout();
433 if (!lay.native) return false;
434
435 // nothing is queued for a window the plan cannot hold: a refusal half way would leave the peer's wait kernels spinning
436 if ((int64_t) (G == 2 ? (T + 1) / 2 : T) * k > kPeerPlanCap || (int64_t) (G == 2 ? (T + 1) / 2 : T) * k > CAP) return false;
437 const int64_t total_steps = (le - lb) * G;
438 for (int64_t step = 0; step < total_steps; ++step) {
439 const int64_t l = lb + step / G;
440 const int grp = (int) (step % G);
441 const uint32_t want = want_flag_start + (uint32_t) step;
442 const int tb = G == 2 ? (grp == 0 ? 0 : (T + 1) / 2) : 0;
443 const int te = G == 2 ? (grp == 0 ? (T + 1) / 2 : T) : T;
444 const int n = te - tb;
445 const int n_entries = n * k;
446 if (n_entries > CAP || n_entries > kPeerPlanCap) return false; // (the plan's arrays hold kPeerPlanCap entries)
447
448 const auto& f = lay.fmt[(size_t) l];
449
450 strata::kernels::wait_flag_ge(d_seq, want, s);
451
452 PeerPlanDevice* pl = d_plans_ + (step % 256);
453 strata::kernels::peer_plan(
454 d_ids_m + (size_t) tb * k, (int) n_entries, k,
455 d_res_peer_ + (size_t) l * (size_t) n_expert_, (int) n_expert_,
456 cache_.device_slot(0), d_slot_off_peer_, (long long) lay.blob_bytes(l),
457 pl->ptr, pl->start, pl->count, pl->dst, pl->tok, pl->out_row, s
458 );
459
460 const float* cur_x = d_x_m + (size_t) tb * H;
461 if (f.had_gu) {
462 strata::kernels::hadamard_rows(cur_x, d_x_, n, H, f.had_block, d_sx_, s);
463 strata::kernels::quantize_q8_1_rows(d_x_, n, H, d_q8_, s);
464 } else {
465 strata::kernels::quantize_q8_1_rows(cur_x, n, H, d_q8_, s);
466 }
467
468 auto L = strata::kernels::native_expert_layout(f.gu_type, f.d_type, f.n_embd, f.n_ff);
469 if (f.had_d) { L.had_block = f.had_block; L.d_signs = d_sh_; }
470 strata::kernels::native_expert_grouped(
471 L, pl->ptr, pl->start, pl->count, pl->dst, pl->tok,
472 CAP, CAP, d_q8_, d_scratch_, d_out_, s
473 );
474
475 strata::kernels::scatter_rows_and_signal_fixed_f32(

Callers 2

runMethod · 0.80
pl_launchMethod · 0.80

Calls 11

expert_layoutFunction · 0.85
peer_planFunction · 0.85
cudaStreamWaitEventFunction · 0.50
wait_flag_geFunction · 0.50
hadamard_rowsFunction · 0.50
quantize_q8_1_rowsFunction · 0.50
native_expert_layoutFunction · 0.50
native_expert_groupedFunction · 0.50
device_slotMethod · 0.45
blob_bytesMethod · 0.45

Tested by

no test coverage detected