pub struct MoeV41 {
pub last: Cell<MoeV41Timing>,
pub cfg: MoeV41Cfg,
/* private fields */
}Fields§
§last: Cell<MoeV41Timing>2026-09-25: The last forward’s timing.
cfg: MoeV41CfgImplementations§
Source§impl MoeV41
impl MoeV41
Sourcepub fn upload_bias(gpu: &dyn GpuBackend, bias: &[f32]) -> Result<DevicePtr>
pub fn upload_bias(gpu: &dyn GpuBackend, bias: &[f32]) -> Result<DevicePtr>
2026-09-25: The device bias for a layer’s router (MoeV41LayerWeights::gate_bias_dev).
Sourcepub fn header_words(&self) -> usize
pub fn header_words(&self) -> usize
2026-09-25: Words in one layer’s header: the miss flag, the picks, the weight bits, the plan slots.
Sourcepub fn arena_of(lru: &ExpertLru) -> (u64, u64, u64, u64, u64)
pub fn arena_of(lru: &ExpertLru) -> (u64, u64, u64, u64, u64)
2026-09-25: The arena facts the selection kernel builds pointers from: (base, slot bytes, gate / up / down offsets).
Sourcepub fn route_select_deferred(
&self,
gpu: &dyn GpuBackend,
w: &MoeV41LayerWeights,
arena: (u64, u64, u64, u64, u64),
stream: u64,
) -> Result<()>
pub fn route_select_deferred( &self, gpu: &dyn GpuBackend, w: &MoeV41LayerWeights, arena: (u64, u64, u64, u64, u64), stream: u64, ) -> Result<()>
2026-09-25: The device selection for a replayed step: the kernel
launched with its header in layer w.layer’s row, and no read-back
(the caller runs read_headers after the segment). The slot table must
already be up to date. Device work only; an error when
device_route_ok refuses the layer.
Sourcepub fn read_headers(&self, gpu: &dyn GpuBackend, stream: u64) -> Result<Vec<u8>>
pub fn read_headers(&self, gpu: &dyn GpuBackend, stream: u64) -> Result<Vec<u8>>
2026-09-25: Every layer’s header in one read-back ordered on stream.
Source§impl MoeV41
impl MoeV41
Sourcepub fn forward<S: ExpertSource + ?Sized>(
&self,
gpu: &dyn GpuBackend,
w: &MoeV41LayerWeights,
lru: &mut ExpertLru,
src: &S,
x: DevicePtr,
m: usize,
reader_threads: usize,
next: Option<&RouterWeights>,
stream: u64,
) -> Result<(DevicePtr, Vec<f32>, Vec<usize>)>
pub fn forward<S: ExpertSource + ?Sized>( &self, gpu: &dyn GpuBackend, w: &MoeV41LayerWeights, lru: &mut ExpertLru, src: &S, x: DevicePtr, m: usize, reader_threads: usize, next: Option<&RouterWeights>, stream: u64, ) -> Result<(DevicePtr, Vec<f32>, Vec<usize>)>
2026-09-25: One layer’s MoE for m tokens: routed experts from the
cache, plus the shared expert. Returns the bf16 [m, dim] output (the
out buffer) and the routing weights and indices, [m, topk] each.
Source§impl MoeV41
impl MoeV41
Sourcepub fn route(
&self,
gpu: &dyn GpuBackend,
w: &MoeV41LayerWeights,
x: DevicePtr,
m: usize,
stream: u64,
) -> Result<(Vec<f32>, Vec<usize>)>
pub fn route( &self, gpu: &dyn GpuBackend, w: &MoeV41LayerWeights, x: DevicePtr, m: usize, stream: u64, ) -> Result<(Vec<f32>, Vec<usize>)>
2026-09-25: Router logits on the GPU (f32 out), the selection on the
CPU. Drains stream.
Sourcepub fn route_launch(
&self,
gpu: &dyn GpuBackend,
w: &MoeV41LayerWeights,
x: DevicePtr,
m: usize,
stream: u64,
) -> Result<()>
pub fn route_launch( &self, gpu: &dyn GpuBackend, w: &MoeV41LayerWeights, x: DevicePtr, m: usize, stream: u64, ) -> Result<()>
2026-09-25: The router GEMM/GEMV into self.logits: device work only,
so a CUDA graph can hold it (segment A of the step graph ends with it).
Errors when m is outside 1..=max_tokens.
Sourcepub fn route_select(
&self,
gpu: &dyn GpuBackend,
w: &MoeV41LayerWeights,
m: usize,
stream: u64,
) -> Result<(Vec<f32>, Vec<usize>)>
pub fn route_select( &self, gpu: &dyn GpuBackend, w: &MoeV41LayerWeights, m: usize, stream: u64, ) -> Result<(Vec<f32>, Vec<usize>)>
2026-09-25: The selection: drain the stream, download the logits
route_launch wrote, pick the top-k on the CPU with
route_from_logits. Errors when the host bias length is not
n_routed.
Source§impl MoeV41
impl MoeV41
Sourcepub fn predict_launch(
&self,
gpu: &dyn GpuBackend,
next: &RouterWeights,
x: DevicePtr,
stream: u64,
) -> Result<()>
pub fn predict_launch( &self, gpu: &dyn GpuBackend, next: &RouterWeights, x: DevicePtr, stream: u64, ) -> Result<()>
2026-09-25: The next layer’s router GEMV on this layer’s single-token
input, into pred_logits. Device work only; predict_select reads it
back.
Sourcepub fn predict_select(
&self,
gpu: &dyn GpuBackend,
next: &RouterWeights,
k: usize,
stream: u64,
) -> Result<Vec<(u32, u32)>>
pub fn predict_select( &self, gpu: &dyn GpuBackend, next: &RouterWeights, k: usize, stream: u64, ) -> Result<Vec<(u32, u32)>>
2026-09-25: The k best experts of the predicted layer by
score + bias, as (layer, expert) cache keys, from the logits
predict_launch wrote. Drains stream.
Sourcepub fn route_predict(
&self,
gpu: &dyn GpuBackend,
w: &MoeV41LayerWeights,
x: DevicePtr,
k: usize,
stream: u64,
) -> Result<Vec<usize>>
pub fn route_predict( &self, gpu: &dyn GpuBackend, w: &MoeV41LayerWeights, x: DevicePtr, k: usize, stream: u64, ) -> Result<Vec<usize>>
2026-09-25: The router of this layer on x (one token), the k best
experts by score + bias in route_from_logits order. Drains the
stream; overwrites self.logits.
Source§impl MoeV41
impl MoeV41
Sourcepub fn ffn_input_q8_m1(
&self,
gpu: &dyn GpuBackend,
x: DevicePtr,
stream: u64,
) -> Result<()>
pub fn ffn_input_q8_m1( &self, gpu: &dyn GpuBackend, x: DevicePtr, stream: u64, ) -> Result<()>
2026-09-25: The token’s q8_1 rows into a_q8, once for the routed experts and the
shared expert’s two input projections (x_pre at the readers).
Sourcepub fn stage_m1<S: ExpertSource + ?Sized>(
&self,
gpu: &dyn GpuBackend,
w: &MoeV41LayerWeights,
lru: &mut ExpertLru,
src: &S,
reader_threads: usize,
next: Option<&RouterWeights>,
x: DevicePtr,
stream: u64,
) -> Result<MoeV41Stage>
pub fn stage_m1<S: ExpertSource + ?Sized>( &self, gpu: &dyn GpuBackend, w: &MoeV41LayerWeights, lru: &mut ExpertLru, src: &S, reader_threads: usize, next: Option<&RouterWeights>, x: DevicePtr, stream: u64, ) -> Result<MoeV41Stage>
2026-09-25: The host span of a single-token step between the router
GEMV and the expert compute: the next layer’s router on x (when
next is given, prefetch_k() > 0 and the cache has a reader pool),
the selection (drains the stream), the cache fetch with the predicted
experts, and the rows / weights / pointer-table uploads into fixed
buffers. route_launch must have been issued on stream first.
Sourcepub fn compute_m1(
&self,
gpu: &dyn GpuBackend,
w: &MoeV41LayerWeights,
x: DevicePtr,
ne: usize,
stream: u64,
) -> Result<DevicePtr>
pub fn compute_m1( &self, gpu: &dyn GpuBackend, w: &MoeV41LayerWeights, x: DevicePtr, ne: usize, stream: u64, ) -> Result<DevicePtr>
2026-09-25: The single-token expert compute after stage_m1: the accumulator
cleared, the routed experts from the pointer table, the shared expert,
the finish into out. Device work only, no per-token scalar
arguments (ne is the top-k: one token’s picks are distinct experts),
so a CUDA graph of it replays for any token once stage_m1 has
refilled rows_dev / weight_dev / ptrs_dev.
2026-09-25: The single-token shared expert up to sd on side,
reading the token’s q8_1 rows that Self::ffn_input_q8_m1 wrote on
the forking stream, with its own q8_1 scratch sh_q8 (as forward’s
side-stream arm): the fork half of Self::compute_m1_joined. Device
work only.
Sourcepub fn compute_m1_joined(
&self,
gpu: &dyn GpuBackend,
x: DevicePtr,
ne: usize,
join: u64,
stream: u64,
) -> Result<DevicePtr>
pub fn compute_m1_joined( &self, gpu: &dyn GpuBackend, x: DevicePtr, ne: usize, join: u64, stream: u64, ) -> Result<DevicePtr>
2026-09-25: Self::compute_m1 with the shared expert forked onto a
side stream by Self::shared_expert_on: the routed experts, then the
wait on join (recorded on the side after sd), then the accumulate
and finish, the same launch order as forward’s side-stream arm. The
token’s q8_1 rows must already be in a_q8 (Self::ffn_input_q8_m1).