def dotr

bend-ml-tensor-array@0.1.19.0 · main.bend:30

import bend-ml-tensor-array@0.1.19.0/main.bend as BendMlTensorArray
import Base

30# A dot product with four partial sums. Each step adds its product to a0 and rotates the sums
31# (a1, a2, a3, a0), so each sum gets every fourth product and the processor can work on the next
32# addition before the last one has finished; at the end the sums are added in pairs. The order of
33# the additions is fixed, so the result is the same on every run and every thread count, but it is
34# not the order of a single running sum (NOTES.md, exp. 17).
35def dotr(k: Nat, +ia: U32, +ib: U32, +sa: U32, +sb: U32, a0: F32, a1: F32, a2: F32, a3: F32, ra: Array<F32> & F32, rb: Array<F32> & F32) -> R:
36  match k ra rb:
37    case 0n Tuple{a, x} Tuple{b, y}:
38      R{a, b, ((a0 + a1 : F32) + (a2 + a3 : F32) : F32)}
39    case 1n+p Tuple{a, +x} Tuple{b, +y}:
40      dotr(p, (ia + sa : U32), (ib + sb : U32), sa, sb, a1, a2, a3, (a0 + (x * y : F32) : F32), Array.get(F32, a, (ia + sa : U32)), Array.get(F32, b, (ib + sb : U32)))

Uses (11)

Used by (1)