perf(prefill): upload the routed slot table before the copy ring, not after it
After the ring the chunk's expert stream keeps the host-to-device copy engine busy and the 327 KB upload waited milliseconds behind it. Same bytes, same fence. Plus a model-free H2D contention probe. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
3ab29114e1
commit
ff93858ca5
@@ -50,6 +50,7 @@ pub struct OriginalMoePromptLayer<'program, 'arena, 'loan, 'ctx> {
|
||||
counts: Vec<u32>,
|
||||
source_rows: Vec<u32>,
|
||||
slot_map: Vec<i32>,
|
||||
slot_uploaded: bool,
|
||||
completed_experts: usize,
|
||||
}
|
||||
enum Command {
|
||||
@@ -571,6 +572,7 @@ impl<'ctx> OriginalMoePromptDevice<'ctx> {
|
||||
counts: actual_counts,
|
||||
source_rows,
|
||||
slot_map,
|
||||
slot_uploaded: false,
|
||||
completed_experts: 0,
|
||||
})
|
||||
}
|
||||
@@ -664,6 +666,7 @@ impl<'program, 'arena, 'loan, 'ctx> OriginalMoePromptLayer<'program, 'arena, 'lo
|
||||
return Err(Error::InvalidQwenShape);
|
||||
}
|
||||
}
|
||||
self.upload_slot_table()?;
|
||||
let mut program = workspace.prepare_original_expert_layer_device(
|
||||
&self.read,
|
||||
&self.counts,
|
||||
@@ -720,12 +723,12 @@ impl<'program, 'arena, 'loan, 'ctx> OriginalMoePromptLayer<'program, 'arena, 'lo
|
||||
self.completed_experts = self.order.len();
|
||||
Ok(())
|
||||
}
|
||||
pub fn finish(
|
||||
self,
|
||||
workspace: &mut NativeBatchWorkspace<'ctx>,
|
||||
) -> Result<OriginalDeviceBlock<'arena, 'loan, 'ctx>> {
|
||||
if self.completed_experts != self.order.len() || self.order.is_empty() {
|
||||
return Err(Error::InvalidQwenShape);
|
||||
/// The routed slot table's upload (read only by the combine kernel). The copy ring does it BEFORE its expert
|
||||
/// copies, because after the ring the chunk's expert stream has the host-to-device copy engine busy and a
|
||||
/// 327 KB upload then waits for several milliseconds behind it. Same bytes, same completion fence.
|
||||
fn upload_slot_table(&mut self) -> Result<()> {
|
||||
if self.slot_uploaded {
|
||||
return Ok(());
|
||||
}
|
||||
let rows = self.read.lease();
|
||||
let t = rows.rows();
|
||||
@@ -746,6 +749,21 @@ impl<'program, 'arena, 'loan, 'ctx> OriginalMoePromptLayer<'program, 'arena, 'lo
|
||||
return combine(combine(copy, wait), pop).map(|()| unreachable!());
|
||||
}
|
||||
combine(combine(copy, wait), pop)?;
|
||||
self.slot_uploaded = true;
|
||||
Ok(())
|
||||
}
|
||||
pub fn finish(
|
||||
mut self,
|
||||
workspace: &mut NativeBatchWorkspace<'ctx>,
|
||||
) -> Result<OriginalDeviceBlock<'arena, 'loan, 'ctx>> {
|
||||
if self.completed_experts != self.order.len() || self.order.is_empty() {
|
||||
return Err(Error::InvalidQwenShape);
|
||||
}
|
||||
self.upload_slot_table()?;
|
||||
let rows = self.read.lease();
|
||||
let t = rows.rows();
|
||||
let (slot, extent) = rows.span(PrefillPhase::Moe, "slot_dev")?;
|
||||
let slot = slot.checked_subspan(extent, 0, t * 10 * 4)?;
|
||||
let bo = common(rows, S::Block, 2560 * 4)?;
|
||||
let mut commands = Vec::new();
|
||||
kernel(
|
||||
|
||||
Reference in New Issue
Block a user