Files
leleka/crates/igpu/examples/dot4_peak.rs
T
Pavlo RatushnyiandClaude Sonnet 5.5 fb696983bd test: run the gpt-oss stack smoke test with the GPU-prefill worker; add the dot4 peak-throughput probe (STRA-219)
Smoke-GptOssStack.ps1 takes -Worker leleka-igpu-worker -GpuMinTokens N. With every prompt forced through the
GPU (N=1): plain answer, function call, tool-result round trip with prefix reuse (134 of 181 tokens cached)
and streaming all pass through the control plane. dot4_peak measures 4.49 TOPS of dot4I8Packed with no memory
traffic on this iGPU, against 0.67-0.86 TOPS for the GEMM kernels (tile sweep in docs/igpu-prefill.md).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-15 00:43:39 +02:00

117 lines
4.4 KiB
Rust

//! Peak `dot4I8Packed` throughput of the GPU with no memory traffic: 16 independent accumulators per thread
//! in a long loop. The ceiling any int8 GEMM kernel on this device can approach.
//!
//! Run: `cargo run --release -p leleka-igpu --example dot4_peak`
use wgpu::util::DeviceExt;
const SHADER: &str = r#"
requires packed_4x8_integer_dot_product;
@group(0) @binding(0) var<storage, read_write> out: array<i32>;
@group(0) @binding(1) var<uniform> iters: vec4<u32>;
@compute @workgroup_size(64)
fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
var a0 = 0; var a1 = 0; var a2 = 0; var a3 = 0; var a4 = 0; var a5 = 0; var a6 = 0; var a7 = 0;
var a8 = 0; var a9 = 0; var a10 = 0; var a11 = 0; var a12 = 0; var a13 = 0; var a14 = 0; var a15 = 0;
let x = gid.x * 2654435761u + 12345u;
var y = x ^ 0x9E3779B9u;
for (var i = 0u; i < iters.x; i++) {
y = y * 1664525u + 1013904223u;
let b = y;
a0 += dot4I8Packed(x, b);
a1 += dot4I8Packed(x + 1u, b);
a2 += dot4I8Packed(x + 2u, b);
a3 += dot4I8Packed(x + 3u, b);
a4 += dot4I8Packed(x + 4u, b);
a5 += dot4I8Packed(x + 5u, b);
a6 += dot4I8Packed(x + 6u, b);
a7 += dot4I8Packed(x + 7u, b);
a8 += dot4I8Packed(x + 8u, b);
a9 += dot4I8Packed(x + 9u, b);
a10 += dot4I8Packed(x + 10u, b);
a11 += dot4I8Packed(x + 11u, b);
a12 += dot4I8Packed(x + 12u, b);
a13 += dot4I8Packed(x + 13u, b);
a14 += dot4I8Packed(x + 14u, b);
a15 += dot4I8Packed(x + 15u, b);
}
out[gid.x] = a0 + a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12 + a13 + a14 + a15;
}
"#;
fn main() {
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor::default());
let adapter = pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::HighPerformance,
..Default::default()
}))
.expect("an adapter");
println!("adapter: {}", adapter.get_info().name);
let (device, queue) = pollster::block_on(adapter.request_device(&wgpu::DeviceDescriptor {
required_limits: adapter.limits(),
..Default::default()
}))
.expect("device");
let module = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(SHADER.into()),
});
let pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
label: None,
layout: None,
module: &module,
entry_point: Some("main"),
compilation_options: Default::default(),
cache: None,
});
let threads = 1 << 18;
let iters = 4096u32;
let out = device.create_buffer(&wgpu::BufferDescriptor {
label: None,
size: threads * 4,
usage: wgpu::BufferUsages::STORAGE,
mapped_at_creation: false,
});
let params = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: None,
contents: bytemuck::cast_slice(&[iters, 0u32, 0, 0]),
usage: wgpu::BufferUsages::UNIFORM,
});
let bind = device.create_bind_group(&wgpu::BindGroupDescriptor {
label: None,
layout: &pipeline.get_bind_group_layout(0),
entries: &[
wgpu::BindGroupEntry {
binding: 0,
resource: out.as_entire_binding(),
},
wgpu::BindGroupEntry {
binding: 1,
resource: params.as_entire_binding(),
},
],
});
let run = |count: usize| {
let mut encoder = device.create_command_encoder(&Default::default());
for _ in 0..count {
let mut pass = encoder.begin_compute_pass(&Default::default());
pass.set_pipeline(&pipeline);
pass.set_bind_group(0, &bind, &[]);
pass.dispatch_workgroups((threads / 64) as u32, 1, 1);
}
queue.submit([encoder.finish()]);
device.poll(wgpu::PollType::Wait).expect("poll");
};
run(1);
let start = std::time::Instant::now();
run(3);
let seconds = start.elapsed().as_secs_f64() / 3.0;
// 16 dot4 per iteration, 4 multiplies and 4 adds each
let ops = threads as f64 * f64::from(iters) * 16.0 * 8.0;
println!(
"{:.3} s per dispatch, {:.2} TOPS (dot4I8Packed, 8 ops each, no memory traffic)",
seconds,
ops / seconds / 1e12
);
}