From d8a960e46dd8de10322e76f06eb35594d9a464c5 Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Sun, 8 Nov 2026 01:20:54 +0100 Subject: [PATCH] STRA-338 params h02: stream-all stager run entry points take OriginalStreamPair and OriginalStreamAllPass; walk takes WalkedLayer --- crates/cuda-driver/src/original_stream_all.rs | 13 +++++++++++++ .../impl_originalexpertstager.rs | 11 ++++------- .../impl_originalexpertstager.rs | 10 ++++------ .../impl_originalstreamall/walk.rs | 19 +++++++++++++------ 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/crates/cuda-driver/src/original_stream_all.rs b/crates/cuda-driver/src/original_stream_all.rs index a34bc6ef..5fb9c38c 100644 --- a/crates/cuda-driver/src/original_stream_all.rs +++ b/crates/cuda-driver/src/original_stream_all.rs @@ -10,6 +10,19 @@ pub struct OriginalStreamAllOptions { pub minimum_rows: usize, pub issuer: bool, } +/// The copy stream that moves expert blobs and the compute stream that consumes them in one stream-all pass. +pub struct OriginalStreamPair<'ctx> { + pub copy: OriginalGpuStream<'ctx>, + pub compute: OriginalGpuStream<'ctx>, +} +/// The layers `first..end` a stream-all pass covers, its options and the host bytes it may use. +#[derive(Clone, Copy)] +pub struct OriginalStreamAllPass { + pub first: u8, + pub end: u8, + pub options: OriginalStreamAllOptions, + pub host_allowance: usize, +} #[derive(Clone, Copy)] struct Entry { layer: u8, diff --git a/crates/cuda-driver/src/original_stream_all/impl_originalexpertstager.rs b/crates/cuda-driver/src/original_stream_all/impl_originalexpertstager.rs index a759e9e4..318ad592 100644 --- a/crates/cuda-driver/src/original_stream_all/impl_originalexpertstager.rs +++ b/crates/cuda-driver/src/original_stream_all/impl_originalexpertstager.rs @@ -12,17 +12,14 @@ impl<'ctx> OriginalExpertStager<'ctx> { pub fn run_stream_all_forward<'arena, 'loan, T>( &mut self, rows: OriginalPromptRows<'arena, 'loan, 'ctx>, - copy: OriginalGpuStream<'ctx>, - compute: OriginalGpuStream<'ctx>, - first: u8, - end: u8, - options: OriginalStreamAllOptions, - host_allowance: usize, + streams: OriginalStreamPair<'ctx>, + pass: OriginalStreamAllPass, consumer: impl FnOnce( &mut OriginalStreamAllForward<'_, '_, 'arena, 'loan, 'ctx>, OriginalPromptRows<'arena, 'loan, 'ctx>, ) -> (Result, Option>), ) -> Result<(T, OriginalStreamAllCompleted<'arena, 'loan, 'ctx>)> { + let OriginalStreamAllPass { first, end, options, host_allowance } = pass; if first >= end || end > 48 { return Err(Error::InvalidQwenShape); } @@ -35,7 +32,7 @@ impl<'ctx> OriginalExpertStager<'ctx> { let resident = resident_spans(&rows, (first, end), count)?; let lease = rows.lease_identity(); let row_count = rows.rows(); - self.run_stream_all(rows, copy, compute, first, end, options, remaining, move |scope| { + self.run_stream_all(rows, streams, OriginalStreamAllPass { host_allowance: remaining, ..pass }, move |scope| { run_forward_consumer(scope, (lease, row_count, resident), consumer) }) } diff --git a/crates/cuda-driver/src/original_stream_all/impl_originalstreamalloptions/impl_originalexpertstager.rs b/crates/cuda-driver/src/original_stream_all/impl_originalstreamalloptions/impl_originalexpertstager.rs index 7c24d7cb..67bf16d4 100644 --- a/crates/cuda-driver/src/original_stream_all/impl_originalstreamalloptions/impl_originalexpertstager.rs +++ b/crates/cuda-driver/src/original_stream_all/impl_originalstreamalloptions/impl_originalexpertstager.rs @@ -11,14 +11,12 @@ impl<'ctx> OriginalExpertStager<'ctx> { pub fn run_stream_all<'arena, 'loan, T>( &mut self, rows: OriginalPromptRows<'arena, 'loan, 'ctx>, - copy: OriginalGpuStream<'ctx>, - compute: OriginalGpuStream<'ctx>, - first: u8, - end: u8, - options: OriginalStreamAllOptions, - host_allowance: usize, + streams: OriginalStreamPair<'ctx>, + pass: OriginalStreamAllPass, consumer: impl FnOnce(&mut OriginalStreamAll<'_, 'arena, 'loan, 'ctx>) -> Result, ) -> Result<(T, OriginalStreamAllCompleted<'arena, 'loan, 'ctx>)> { + let OriginalStreamPair { copy, compute } = streams; + let OriginalStreamAllPass { first, end, options, host_allowance } = pass; let ring = self.stream_preflight(&rows, (©, &compute), (first, end), options)?; self.check_stream_budget(options, host_allowance)?; let (mut entries, targets) = self.reserve_stream_targets(&rows, ring)?; diff --git a/crates/cuda-driver/src/original_stream_all/impl_originalstreamalloptions/impl_originalstreamall/walk.rs b/crates/cuda-driver/src/original_stream_all/impl_originalstreamalloptions/impl_originalstreamall/walk.rs index da55cdbc..bdba04dc 100644 --- a/crates/cuda-driver/src/original_stream_all/impl_originalstreamalloptions/impl_originalstreamall/walk.rs +++ b/crates/cuda-driver/src/original_stream_all/impl_originalstreamalloptions/impl_originalstreamall/walk.rs @@ -19,6 +19,13 @@ impl Streamed<'_> { } } +/// A layer of a stream-all walk and the end of its entries in the job list. +#[derive(Clone, Copy)] +struct WalkedLayer { + layer: u8, + end: usize, +} + /// One expert of a sorted layer list and its place in the 16-wide gather groups. pub(crate) struct GroupStep<'a> { expert: u32, @@ -104,7 +111,7 @@ impl<'s, 'arena, 'loan, 'ctx> OriginalStreamAll<'s, 'arena, 'loan, 'ctx> { ) -> Result<()> { let layer_end = self.layer_start[layer as usize + 1]; for &e in experts { - self.walk_expert(layer, layer_end, e, &mut producer, &mut resident)?; + self.walk_expert(WalkedLayer { layer, end: layer_end }, e, &mut producer, &mut resident)?; } self.release_unused(512, layer_end)?; self.next_layer += 1; @@ -112,12 +119,12 @@ impl<'s, 'arena, 'loan, 'ctx> OriginalStreamAll<'s, 'arena, 'loan, 'ctx> { } fn walk_expert( &mut self, - layer: u8, - layer_end: usize, + walked: WalkedLayer, e: u32, producer: &mut impl FnMut(u32, BufferHandle, usize, &mut OriginalGpuStream<'ctx>) -> Result<()>, resident: &mut impl FnMut(&Self, u8, u32) -> Result<(BufferHandle, usize)>, ) -> Result<()> { + let WalkedLayer { layer, end: layer_end } = walked; self.release_unused(e, layer_end)?; self.healthy()?; if self.streams_next(e, layer_end) { @@ -146,7 +153,7 @@ impl<'s, 'arena, 'loan, 'ctx> OriginalStreamAll<'s, 'arena, 'loan, 'ctx> { group_ids[slot] = expert; let last = slot + 1 == ORIGINAL_MMQ_GROUP || j + 1 == experts.len(); let step = GroupStep { expert, ids: &group_ids[..slot + 1], j, slot, last }; - self.group_step(layer, layer_end, &step, producer, &mut resident)?; + self.group_step(WalkedLayer { layer, end: layer_end }, &step, producer, &mut resident)?; } self.release_unused(512, layer_end)?; self.next_layer += 1; @@ -154,12 +161,12 @@ impl<'s, 'arena, 'loan, 'ctx> OriginalStreamAll<'s, 'arena, 'loan, 'ctx> { } fn group_step>( &mut self, - layer: u8, - layer_end: usize, + walked: WalkedLayer, step: &GroupStep<'_>, producer: &mut P, resident: &mut impl FnMut(&Self, u8, u32) -> Result<(BufferHandle, usize)>, ) -> Result<()> { + let WalkedLayer { layer, end: layer_end } = walked; let context = self.stager.context; if self.streams_next(step.expert, layer_end) { return self.consume_streamed(layer, |st, compute| {