omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / gpu / nvidia / om / codegen / cg_matmul.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note Blackwell matmul layout decisions, exact CUDApp 22ebf8f unsigned semantics. |
| 3 | fn cg_fit r uint c uint n uint to bool |
| 4 | row = mul mul mul ulong sub r 1 16 ulong n 4 |
| 5 | col = mul ulong sub c 1 32 |
| 6 | ret lt add add row col 4 shl ulong 1 23 |
| 7 | end |
| 8 | fn cg_tile n uint to uint |
| 9 | if eq rem n 4 0 |
| 10 | ret 4 |
| 11 | end |
| 12 | if eq rem n 2 0 |
| 13 | ret 2 |
| 14 | end |
| 15 | ret 1 |
| 16 | end |
| 17 | fn cg_shape m uint n uint to uint |
| 18 | r = cg_tile m |
| 19 | c = uint 1 |
| 20 | while gt r 1 bound 2 |
| 21 | c = cg_tile n |
| 22 | if cg_fit r c mul n 8 |
| 23 | break |
| 24 | end |
| 25 | r = div r 2 |
| 26 | end |
| 27 | if eq r 1 |
| 28 | c = 1 |
| 29 | end |
| 30 | ret or r shl c 8 |
| 31 | end |
| 32 | fn cg_bunr k uint r uint c uint to uint |
| 33 | ks = div k 16 |
| 34 | if and eq rem ks 2 0 le mul add r c 2 8 |
| 35 | ret 2 |
| 36 | end |
| 37 | ret 1 |
| 38 | end |
| 39 | fn cg_funr k uint to uint |
| 40 | ret cg_tile div k 16 |
| 41 | end |
| 42 | fn cg_index rr uint cc uint to uint |
| 43 | lane = add mul and rr 7 4 shr and cc 7 1 |
| 44 | base = add mul lane 8 mul shr cc 3 4 |
| 45 | ret add add base mul shr rr 3 2 and cc 1 |
| 46 | end |
| 47 | fn cg_matmul kind ulong a ulong b ulong c ulong to ulong |
| 48 | if eq kind 0 |
| 49 | ret ulong cg_shape uint a uint b |
| 50 | end |
| 51 | if eq kind 1 |
| 52 | ret ulong cg_bunr uint a uint b uint c |
| 53 | end |
| 54 | if eq kind 2 |
| 55 | ret ulong cg_funr uint a |
| 56 | end |
| 57 | if eq kind 3 |
| 58 | ret ulong cg_index uint a uint b |
| 59 | end |
| 60 | ret 0 |
| 61 | end |