From a08d6fbf55663eded71e095d608d126d7f1f16e7 Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Thu, 15 Oct 2026 01:32:19 +0200 Subject: [PATCH] perf: separate tile configuration for the grouped expert products; record the tile sweep (STRA-219) No tile beat 4x4 for the experts; the hook (LELEKA_IGPU_MOE_TILE) stays for later experiments. Co-Authored-By: Claude Sonnet 5.5 --- crates/igpu/src/lib.rs | 17 ++++++++++++++--- docs/igpu-prefill.md | 2 ++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/igpu/src/lib.rs b/crates/igpu/src/lib.rs index 2bcba7ab..a39f62d6 100644 --- a/crates/igpu/src/lib.rs +++ b/crates/igpu/src/lib.rs @@ -125,6 +125,8 @@ pub struct Gpu { no_bias: wgpu::Buffer, /// Outputs per thread along the activation rows and the weight rows. tile: (u32, u32), + /// Outputs per thread of the grouped expert products (their own tile: rows per expert are few). + moe_tile: (u32, u32), } #[repr(C)] @@ -378,6 +380,14 @@ impl Gpu { if !(1..=8).contains(&tm) || !(1..=8).contains(&tn) { return Err(GpuError::Shape(format!("tile {tm}x{tn} is outside 1..=8"))); } + // experiment hook: LELEKA_IGPU_MOE_TILE=TMxTN + let moe_tile = std::env::var("LELEKA_IGPU_MOE_TILE") + .ok() + .and_then(|s| { + let (a, b) = s.split_once('x')?; + Some((a.parse().ok()?, b.parse().ok()?)) + }) + .unwrap_or((tm, tn)); let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor::default()); let adapter = pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions { power_preference: wgpu::PowerPreference::HighPerformance, @@ -424,7 +434,7 @@ impl Gpu { ), gemm_moe: pipeline( "gemm moe mxfp4", - shaders::gemm(WeightKind::Mxfp4, tm, tn, true), + shaders::gemm(WeightKind::Mxfp4, moe_tile.0, moe_tile.1, true), ), quantize: pipeline("quantize", shaders::with_helpers(shaders::QUANTIZE)), swiglu_quant: pipeline("swiglu quant", shaders::with_helpers(shaders::SWIGLU_QUANT)), @@ -442,6 +452,7 @@ impl Gpu { queue, info, tile: (tm, tn), + moe_tile, }) } @@ -688,7 +699,7 @@ impl Gpu { for (i, expert) in chosen.iter().enumerate() { per_expert[*expert as usize].push((i / used) as u32); } - let rows_per_tile = 8 * self.tile.0 as usize; + let rows_per_tile = 8 * self.moe_tile.0 as usize; let mut rowmap = Vec::with_capacity(chosen.len()); let mut tiles = Vec::new(); let mut first = vec![0usize; experts]; @@ -1077,7 +1088,7 @@ impl Recorder<'_> { let dims_buf = self.uniform(&dims); let bias_buffer = bias.map_or(&self.gpu.no_bias, |b| &b.buffer); let groups = ( - n.div_ceil(8 * self.gpu.tile.1 as usize) as u32, + n.div_ceil(8 * self.gpu.moe_tile.1 as usize) as u32, plan.tile_count as u32, 1, ); diff --git a/docs/igpu-prefill.md b/docs/igpu-prefill.md index afe580ec..f00ba68e 100644 --- a/docs/igpu-prefill.md +++ b/docs/igpu-prefill.md @@ -78,6 +78,8 @@ Limits of this result: synthetic random-id prompts (not an agent trace), three t and the GPU path's quality is the borderline gate result above. Time-to-first-token for a real request also includes the CPU's lm-head and the control plane; the end-to-end agent workload A/B is still to do. +After the A/B above, staging two shared-dimension blocks per barrier pair in the MXFP4 GEMM (bit-identical output) took a single 1024-token GPU prefill from 15.9 s to 13.6 s (75 tok/s; the A/B table was measured before this change). Other expert tiles per thread (6x6, 4x3, 3x4, 6x4, 4x6, 5x5, `LELEKA_IGPU_MOE_TILE`) were not faster than 4x4; the machine warmed up during that sweep, so small differences there are not meaningful. + Where the GPU time goes (earlier single runs): experts are the floor (the grouped GEMM runs at 0.6-0.85 TOPS of integer work against 4.49 TOPS for `dot4I8Packed` alone, `examples/dot4_peak.rs`, tile sweep with `LELEKA_IGPU_TILE`), and attention grows with the square of the context (one full layer over a 512-token batch