Skip to main content

cpu_linear

Function cpu_linear 

Source
pub fn cpu_linear(
    x: &[f32],
    w: &[f32],
    m: usize,
    in_f: usize,
    out_f: usize,
) -> Vec<f32>
Expand description

CPU reference matmul for a linear layer y = x @ W^T. Conventions (ggml/GGUF): a weight tensor with ne=[in, out] is stored row-major as out rows of in contiguous elements — i.e. W[oin + i]. A linear layer computes y[o] = sum_i x[i] * W[oin + i], for each of out outputs. Batched over m tokens: x: [m, in] row-major (x[tin + i]); w: [out, in] row-major (w[oin + i]); y: [m, out].