Skip to main content

Module kernels

Module kernels 

Source
Expand description

DRAM application kernels — the workloads in-memory compute is lightning-fast at: bitwise + COUNT over massive data, at zero data movement. Popcount is the linchpin — the reduction that turns the bitwise/XNOR machinery into counts, distances, and dot products:

• popcount — per-lane population count, folded bit-serially into an in-DRAM counter; • hamming_distance = popcount(a XOR b) — vector similarity search (ANN over binary codes), binary-net inference, bioinformatics distance; • agreement_count = popcount(a XNOR b) — the 1-bit / binary neural-net DOT PRODUCT (for ±1 codes, dot = 2·agreements − K). This is how a BitNet-style matmul runs with NO multiply.

All are composed from the {And, Or, Not} basis over a bit-serial (bitplane) layout: bitplane j is a row whose bit i is bit j of lane i’s value, so one kernel processes all lanes in parallel — exactly the data-parallel, bandwidth-bound shape the DRAM plane wins on.

Functions§

agreement_count
Per-lane AGREEMENT COUNT popcount(a XNOR b) — the binary / 1-bit neural-net DOT PRODUCT. For ±1 codes packed as bits, the true dot product is 2·agreements − K; the agreement count is the in-DRAM half (XNOR + popcount, no multiply), the final affine map is a scalar host step.
hamming_distance
Per-lane HAMMING DISTANCE between two bit-serial codes a/b (K planes each): popcount(a XOR b). The core kernel of vector similarity search (ANN over binary codes) and binary-net inference.
popcount
Per-lane POPCOUNT of planes: for each lane, the number of set bits across the planes, as an out_width-plane per-lane integer (LSB first). A reduction realized ENTIRELY in the DRAM plane by folding each plane into a bit-serial counter. zero is a zero row (the initial counter value).
ternary_binary_dot
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.