omega-bridge
Omega-first language interoperability: checked conversion backends and native language bindings
Brought by drakestapleton
omega-bridge / pytorch / kernels / mm.om
| 1 | note mm: o[M,N] = a[M,K] @ b[K,N] (aten.mm), row-major f32. Each dot product is summed in f64 and |
| 2 | note rounded once to f32. The caller supplies const lines M K N MK KN MN before this text. |
| 3 | fn mmdot a view f32 MK b view f32 KN i ulong j ulong to f64 |
| 4 | s = 0.0f64 |
| 5 | ia = mul i K |
| 6 | rb = j |
| 7 | for k ulong K |
| 8 | s = add s mul f64 get a ia f64 get b rb |
| 9 | ia = add ia 1 |
| 10 | rb = add rb N |
| 11 | end |
| 12 | ret s |
| 13 | end |
| 14 | fn mm a view f32 MK b view f32 KN o edit f32 MN to void |
| 15 | for i ulong M |
| 16 | for j ulong N |
| 17 | put o add mul i N j f32 mmdot a b i j |
| 18 | end |
| 19 | end |
| 20 | end |