Merge branch 'claude/par-p04' into claude/hexagonal-finish-14ee3a

This commit is contained in:
Pavlo Ratushnyi
2026-11-08 01:24:17 +01:00
4 changed files with 64 additions and 57 deletions
+3 -53
View File
@@ -348,59 +348,9 @@ pub fn dispatch(
Ok(d)
}
/// The device image of a dispatch (`struct RemoteMeta`): group device pointers (`device_slot(slot)`, supplied
/// by the cache), starts, destinations, token indices and the group count. Unused tails are zero.
pub struct RemoteMeta;
impl RemoteMeta {
pub fn to_bytes(d: &Dispatch, device_slot: &dyn Fn(i32) -> u64) -> [u8; META_BYTES] {
let mut b = [0u8; META_BYTES];
for (g, grp) in d.groups.iter().enumerate() {
b[META_PTR_OFFSET + g * 8..][..8].copy_from_slice(&device_slot(grp.slot).to_le_bytes());
}
for (i, s) in d.start.iter().enumerate() {
b[META_START_OFFSET + i * 4..][..4].copy_from_slice(&s.to_le_bytes());
}
for (i, v) in d.dst.iter().enumerate() {
b[META_DST_OFFSET + i * 4..][..4].copy_from_slice(&v.to_le_bytes());
}
for (i, v) in d.tok.iter().enumerate() {
b[META_TOK_OFFSET + i * 4..][..4].copy_from_slice(&v.to_le_bytes());
}
b[META_COUNT_OFFSET..][..4].copy_from_slice(&(d.groups.len() as i32).to_le_bytes());
b
}
}
/// `RemoteExperts::finish`'s copy: compact row `i` of `h_out` returns to routed row `original_row[i]` of `out`
/// (`row_len` floats each; `H` in the engine).
pub fn scatter(out: &mut [f32], h_out: &[f32], original_row: &[i32], row_len: usize) {
for (i, &r) in original_row.iter().enumerate() {
out[r as usize * row_len..][..row_len].copy_from_slice(&h_out[i * row_len..][..row_len]);
}
}
/// Counters the engine reports per request.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct Totals {
pub computed: u64,
pub launched_layers: u64,
pub returned_bytes: u64,
pub full_row_bytes: u64,
}
impl Totals {
/// After a `begin` that launched (`groups` non-empty).
pub fn record(&mut self, d: &Dispatch) {
self.computed += d.computed;
if !d.is_empty() {
self.launched_layers += 1;
self.returned_bytes += d.returned_bytes();
self.full_row_bytes += d.full_row_bytes();
}
}
}
mod device_image;
#[allow(unused_imports)]
pub use device_image::*;
mod dispatch_groups;
use dispatch_groups::{assign_groups, pack_groups, pick_unclaimed};
@@ -0,0 +1,57 @@
//! The device image of a dispatch, the copy back of its compact rows and the per-request counters.
#[allow(unused_imports)]
use super::*;
/// The device image of a dispatch (`struct RemoteMeta`): group device pointers (`device_slot(slot)`, supplied
/// by the cache), starts, destinations, token indices and the group count. Unused tails are zero.
pub struct RemoteMeta;
impl RemoteMeta {
pub fn to_bytes(d: &Dispatch, device_slot: &dyn Fn(i32) -> u64) -> [u8; META_BYTES] {
let mut b = [0u8; META_BYTES];
for (g, grp) in d.groups.iter().enumerate() {
b[META_PTR_OFFSET + g * 8..][..8].copy_from_slice(&device_slot(grp.slot).to_le_bytes());
}
for (i, s) in d.start.iter().enumerate() {
b[META_START_OFFSET + i * 4..][..4].copy_from_slice(&s.to_le_bytes());
}
for (i, v) in d.dst.iter().enumerate() {
b[META_DST_OFFSET + i * 4..][..4].copy_from_slice(&v.to_le_bytes());
}
for (i, v) in d.tok.iter().enumerate() {
b[META_TOK_OFFSET + i * 4..][..4].copy_from_slice(&v.to_le_bytes());
}
b[META_COUNT_OFFSET..][..4].copy_from_slice(&(d.groups.len() as i32).to_le_bytes());
b
}
}
/// `RemoteExperts::finish`'s copy: compact row `i` of `h_out` returns to routed row `original_row[i]` of `out`
/// (`row_len` floats each; `H` in the engine).
pub fn scatter(out: &mut [f32], h_out: &[f32], original_row: &[i32], row_len: usize) {
for (i, &r) in original_row.iter().enumerate() {
out[r as usize * row_len..][..row_len].copy_from_slice(&h_out[i * row_len..][..row_len]);
}
}
/// Counters the engine reports per request.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct Totals {
pub computed: u64,
pub launched_layers: u64,
pub returned_bytes: u64,
pub full_row_bytes: u64,
}
impl Totals {
/// After a `begin` that launched (`groups` non-empty).
pub fn record(&mut self, d: &Dispatch) {
self.computed += d.computed;
if !d.is_empty() {
self.launched_layers += 1;
self.returned_bytes += d.returned_bytes();
self.full_row_bytes += d.full_row_bytes();
}
}
}
+2 -2
View File
@@ -77,11 +77,11 @@ impl Model {
/// returns the hidden state of the last token after storing every layer's keys and values; the output
/// projection and the greedy choice run here ([`Model::next_from_hidden`]). `progress` receives the
/// number of prompt tokens finished (reused ones included) and the total.
pub fn prefill_reuse_accelerated(
pub fn prefill_reuse_accelerated<A: PrefillAccelerator + ?Sized>(
&self,
state: &mut State,
prompt: &[u32],
accelerate: PrefillOffload,
accelerate: PrefillOffload<A>,
progress: &mut dyn FnMut(usize, usize) -> bool,
) -> Result<Option<Reuse>, ModelError> {
let PrefillOffload { accelerator, min_tokens } = accelerate;
+2 -2
View File
@@ -124,8 +124,8 @@ impl LayerCache for State {
/// An accelerator and the number of prompt tokens to compute from which it is used (see
/// [`Model::prefill_reuse_accelerated`]).
pub struct PrefillOffload<'a> {
pub accelerator: &'a mut dyn PrefillAccelerator,
pub struct PrefillOffload<'a, A: PrefillAccelerator + ?Sized> {
pub accelerator: &'a mut A,
pub min_tokens: usize,
}