Mettle

dot-shape-addressDot product with an address the kernel cannot follow

Reported by --explain after a verdict.

mettle explain dot-shape-address

The loop is a float multiply-accumulate, which is exactly the FMA dot product kernel's shape, but the addresses do not match. The kernel needs each base to be a plain pointer indexed by the loop counter: a[i], not a[r * cols + i].

Example, an inner product over one row of a matrix:

for r in 0..rows {
    var row: float32* = &m[r * cols];   // hoisted, invariant here
    for c in 0..cols {
        acc = acc + row[c] * x[c];      // now `base[i]`
    }
}

Fix: lift the invariant part of the index into a pointer before the loop. The report checks first: when the other half of the index changes every iteration the access really is non-unit-stride, and the report says so instead of giving advice that cannot work.

Related