Files
leleka/crates/igpu/src/lib.rs
T

52 lines
1.8 KiB
Rust

//! Integrated-GPU kernels for the Leleka gpt-oss runtime, written for `wgpu` with WGSL shaders.
//!
//! STRA-219: a prefill backend. Phase A gave int8 matrix products over Q8_0 and MXFP4 weights with the block
//! scales applied; phase B adds device-resident buffers, a [`Recorder`] that batches kernel launches into one
//! submission, and the layer's other kernels, each checked against the CPU decoder. The crate is safe Rust;
//! the GPU is optional and every entry point reports why it cannot run instead of falling back silently.
//!
//! Weights are repacked when they are uploaded: ggml's 34-byte Q8_0 and 17-byte MXFP4 blocks are not
//! aligned for 32-bit access, so quants and scales go to separate word arrays (see [`shaders::gemm`]).
pub mod shaders;
use std::fmt;
use wgpu::util::DeviceExt;
/// Elements per quantization block.
pub const BLOCK: usize = 32;
const Q8_0_BYTES: usize = 34;
const MXFP4_BYTES: usize = 17;
#[cfg(test)]
mod tests;
mod error_and_kind;
pub use error_and_kind::{GpuError, WeightKind};
mod handles;
pub use handles::{Buf, GpuActivations, GpuMatrix};
mod params;
pub use params::AttentionShape;
pub use params::{AttentionBufs, CombineBufs, KvStoreShape, NormBufs, NormShape, Operands, ProductOutput};
pub use params::{RopeShape, RouterBufs, SwigluBufs};
pub use params::MoePlan;
use params::SwigluUniform;
use params::{AttentionParams, Quad};
use params::{Dims, NormParams};
pub use params::{ROUTER_EXPERTS, ROUTER_USED, SwigluParams};
mod repacking;
pub use repacking::repack_q8_0;
#[cfg(test)]
use repacking::le_words;
pub use repacking::{repack_activations, repack_mxfp4};
mod device;
pub use device::Gpu;
use device::{entry, groups_1d};
mod matrices_and_moe_plan;
mod readback;
mod recorder_core;
pub use recorder_core::Recorder;
mod recorder_attention_and_submit;
mod recorder_moe;
mod recorder_norm_and_routing;