interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / gpu / nvidia / om / codegen / cg_matmul.om

61 lines · 1157 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note Blackwell matmul layout decisions, exact CUDApp 22ebf8f unsigned semantics.
3fn cg_fit r uint c uint n uint to bool
4row = mul mul mul ulong sub r 1 16 ulong n 4
5col = mul ulong sub c 1 32
6ret lt add add row col 4 shl ulong 1 23
7end
8fn cg_tile n uint to uint
9if eq rem n 4 0
10ret 4
11end
12if eq rem n 2 0
13ret 2
14end
15ret 1
16end
17fn cg_shape m uint n uint to uint
18r = cg_tile m
19c = uint 1
20while gt r 1 bound 2
21c = cg_tile n
22if cg_fit r c mul n 8
23break
24end
25r = div r 2
26end
27if eq r 1
28c = 1
29end
30ret or r shl c 8
31end
32fn cg_bunr k uint r uint c uint to uint
33ks = div k 16
34if and eq rem ks 2 0 le mul add r c 2 8
35ret 2
36end
37ret 1
38end
39fn cg_funr k uint to uint
40ret cg_tile div k 16
41end
42fn cg_index rr uint cc uint to uint
43lane = add mul and rr 7 4 shr and cc 7 1
44base = add mul lane 8 mul shr cc 3 4
45ret add add base mul shr rr 3 2 and cc 1
46end
47fn cg_matmul kind ulong a ulong b ulong c ulong to ulong
48if eq kind 0
49ret ulong cg_shape uint a uint b
50end
51if eq kind 1
52ret ulong cg_bunr uint a uint b uint c
53end
54if eq kind 2
55ret ulong cg_funr uint a
56end
57if eq kind 3
58ret ulong cg_index uint a uint b
59end
60ret 0
61end