Skip to main content

ternary_binary_dot

Function ternary_binary_dot 

Source
pub fn ternary_binary_dot(
    df: &mut DramDataflow,
    wp: &[usize],
    wn: &[usize],
    x: &[usize],
    out_width: usize,
    zero: usize,
    ones: usize,
) -> Vec<usize>
Expand description

BitNet-style TERNARY·BINARY dot product — one matmul row, entirely in-DRAM, NO multiply. Ternary weights w[k] ∈ {−1,0,+1} are carried as two disjoint bitplane sets: wp[k]=1 iff w=+1, wn[k]=1 iff w=−1. Binary activations x[k] ∈ {0,1}. Then, per lane (per output neuron), dot = Σ w[k]·x[k] = popcount(Wp AND X) − popcount(Wn AND X) as a two’s-complement out_width-plane integer. zero is a zero row, ones an all-ones carry row (for the subtract). This is how a 1.58-bit LLM layer runs where the weights live: AND + popcount + subtract, no multiplier.