Skip to main content

The rule

a @ b (or sf.matmul(a, b)) computes each output as dot of a row of a and a column of b: a sequential chain of fma from k = 0, saturating at each step, in the width of the data. Every output equals the 1-D sf.dot of that row and column bit for bit, which is tested.
Take the top-left output: 0.5 × 0.5 = 0.25 (exact), then fma(0.25, 0.25, 0.25) = 0.0625 + 0.25 = 0.3125. The bottom-left shows truncation at work: 0.1 is 3277 codes, 3277 × 16384 / 32768 = 1638.5 truncates to 1638, plus 0.2 × 0.25 (6554 × 8192 / 32768 = 1638.5, truncates to 1638) gives 3276 codes = 0.09997559, not 0.1.

Shapes

NumPy’s rules: 1-D operands are promoted and the extra dimension dropped, leading dimensions broadcast as a batch. A mismatch raises SFShapeError on the host before anything runs:

Matmul plus bias

sf.addmm(a, b, d) is a @ b followed by one saturating add of d. It is a separate function because “the chain, then one add” is what the hardware’s mat_fma instruction is believed to do, and it is what the PyTorch linear layer uses for the bias.

On the device

With device arrays, @ is a heavy operation: it goes through the pre-flight gate, runs on the target, and returns a status.
The exact=True comes from the range bound: the host computed that no partial sum of any output could exceed the maximum, so the launch was marked safe and no scan was needed. The device path →

Can it saturate?

A partial sum can pass the edge even if the final value would not, and once it saturates it stays there. The host’s bound is conservative: it uses the L1 norms of the rows and columns, which is tighter than the spec’s K × max|A| × max|B| and never looser. When the bound cannot prove safety, the probe samples real outputs; when it can prove every output saturates, the operation is refused before launch by default.
That was a warning rather than a refusal because the probe saw it, not the bound: a sample is a suspicion, never a proof. sf.config(suspect="raise") refuses on a suspicion; suspect="verify" replays the operation on the host and refuses only on proof.