STRA-338: dyn-trait ratchet back (alias for the arena trait object, serve takes generic channels, one pool alias)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Pavlo Ratushnyi
2026-11-07 17:24:02 +01:00
co-authored by Claude Sonnet 5.5
parent 08def7efea
commit ef4fdea4a6
3 changed files with 16 additions and 11 deletions
@@ -3,10 +3,13 @@
#[allow(unused_imports)]
use super::*;
/// The row arena the planners read, as a trait object (one place names the dyn).
type Arena<'a> = &'a dyn ArenaMap;
/// `grouped(gp, gs, gn)` of `post`: `native_expert_grouped(L, ...)` for one tier, `L` the layer's native
/// layout and `cap = n * K` groups / entries.
pub(crate) fn plan_expert_groups(
arena: &dyn ArenaMap,
arena: Arena<'_>,
g: &OriginalVerifyGeometry,
knobs: &MoeKnobs,
formats: &OriginalVerifyExpertFormats,
@@ -63,7 +66,7 @@ struct GroupPlan {
}
impl GroupPlan {
fn new(arena: &dyn ArenaMap, g: &OriginalVerifyGeometry, rows: Rows, tier: ExpertTier, n: usize) -> Result<Self> {
fn new(arena: Arena<'_>, g: &OriginalVerifyGeometry, rows: Rows, tier: ExpertTier, n: usize) -> Result<Self> {
let layout = PlanLayout::new(g.max_t * g.k);
let (ptr_word, start_word, count_word) = match tier {
ExpertTier::Vram => (layout.ptr, layout.start, layout.counts),
@@ -168,7 +171,7 @@ impl GroupPlan {
/// `moe_hit_add(parts_ + tb*K*N, hit_out, p_dst, p_counts + 1, cap, N)`:
/// `add_hits_kernel<<<(min(ceil(N/256), 8), cap), 256>>>`.
pub(crate) fn plan_hit_add(arena: &dyn ArenaMap, g: &OriginalVerifyGeometry, rows: Rows) -> Result<Vec<Launch>> {
pub(crate) fn plan_hit_add(arena: Arena<'_>, g: &OriginalVerifyGeometry, rows: Rows) -> Result<Vec<Launch>> {
let n = check_rows(g, rows)?;
let layout = PlanLayout::new(g.max_t * g.k);
let (n_embd, k, tb) = (g.n, g.k, rows.begin);
@@ -191,7 +194,7 @@ pub(crate) fn plan_hit_add(arena: &dyn ArenaMap, g: &OriginalVerifyGeometry, row
/// `native_moe_combine_multi` launch (`grid.y` = token). Otherwise `moe_combine_parts` per row:
/// `native_moe_combine` (same kernel, one token) or the legacy double-precision `moe_combine`.
pub(crate) fn plan_combine(
arena: &dyn ArenaMap,
arena: Arena<'_>,
g: &OriginalVerifyGeometry,
knobs: &MoeKnobs,
rows: Rows,
@@ -209,7 +212,7 @@ pub(crate) fn plan_combine(
}
/// The per-row combine launch of row `t`.
fn combine_row(arena: &dyn ArenaMap, g: &OriginalVerifyGeometry, knobs: &MoeKnobs, t: usize) -> Result<Launch> {
fn combine_row(arena: Arena<'_>, g: &OriginalVerifyGeometry, knobs: &MoeKnobs, t: usize) -> Result<Launch> {
let (n_embd, k) = (g.n, g.k);
let parts = f32s(arena, "parts", t * k * n_embd, k * n_embd)?;
let w = f32s(arena, "w", t * k, k)?;
@@ -238,7 +241,7 @@ fn combine_legacy(g: &OriginalVerifyGeometry, [parts, w, shared, bo]: [u64; 4])
/// ONE `native_moe_combine_multi` launch over all rows of the group.
fn combine_batched(
arena: &dyn ArenaMap,
arena: Arena<'_>,
g: &OriginalVerifyGeometry,
knobs: &MoeKnobs,
rows: Rows,
@@ -20,6 +20,6 @@ impl<'a, 'ctx> OriginalServeStack<'a, 'ctx> {
let mut view = self.decode_view(&staged.shared);
let assembled = view.assemble(&staged)?;
let resources = view.resolve(assembled)?;
view.serve(request, sampling, resources, emit, cancel)
view.serve(request, sampling, resources, (emit, cancel))
}
}
@@ -20,9 +20,12 @@ pub(super) struct Staged<'ctx> {
/// The assembly's outcome: the window width it settled on and the resources or the failure.
pub(super) type Assembled<'s, 'ctx> = (usize, std::result::Result<DecodeResources<'s, 'ctx>, AssembleFailure<'ctx>>);
/// The expert pool a request runs over: the GPU share over the CPU pool, or the CPU pool alone (decided at run time).
type PoolRef<'q, 'ctx> = &'q mut dyn OriginalServePool<'ctx>;
/// The pool, the QSA journal with its layer slots, and the PLE history image a host is built over.
type HostTail<'h, 'ctx> =
(&'h mut dyn OriginalServePool<'ctx>, Rc<OriginalVerifyQsaJournal<'h, 'ctx>>, [usize; 12], &'h DeviceBuffer<'ctx>);
(PoolRef<'h, 'ctx>, Rc<OriginalVerifyQsaJournal<'h, 'ctx>>, [usize; 12], &'h DeviceBuffer<'ctx>);
impl<'a, 'ctx> OriginalServeStack<'a, 'ctx> {
/// The request's start: a poisoned controller is renewed, the base position is checked, the PLE history is seeded
@@ -159,8 +162,7 @@ impl<'s, 'a, 'ctx> DecodeView<'s, 'a, 'ctx> {
request: &ServeRequest,
sampling: RequestSampling,
resources: DecodeResources<'s, 'ctx>,
mut emit: &mut dyn FnMut(&[i32]) -> Result<()>,
mut cancel: &mut dyn FnMut() -> bool,
(mut emit, mut cancel): (impl FnMut(&[i32]) -> Result<()>, impl FnMut() -> bool),
) -> std::result::Result<ServeOutcome, SpecError> {
let DecodeResources { verifier, qsa, slots } = resources;
// the NaN guard's retry takes a refused window back from these (OriginalVerifier::discard_window)
@@ -197,7 +199,7 @@ fn begin_tail(policy: &mut Policy<'_>, book: &mut Book<'_, '_>) -> bool {
fn expert_pool<'q, 'p: 'q, 'a, 'ctx>(
groups: (&Ids<'_, 'a, 'ctx>, &Reads<'p, 'ctx>, &'p mut Tier<'_, 'a, 'ctx>, &Policy<'_>),
slot: &'q mut Option<GpuExpertPool<'p, 'a, 'ctx>>,
) -> std::result::Result<&'q mut dyn OriginalServePool<'ctx>, SpecError> {
) -> std::result::Result<PoolRef<'q, 'ctx>, SpecError> {
let (ids, reads, tier, policy) = groups;
match tier.expert_cache.as_mut() {
Some(cache) => {