interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / om / gdn / admit.om

177 lines · 3260 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note admit.om: the admission and layout decisions of src/omega_gpu_gdn_api.c in seeded Omega.
3note Entry gdn_admit op a b c o: result 0 admitted, 1 refused (OMEGA_GPU_GDN_BAD_ARGS / shape -1).
4note op 1 SHAPE a=ratio b=state_bf16: o[0..9] = r vh conv vdim par_scal par_norm par_bytes tail state post_y.
5note op 2 ALLOC a=layers b=ratio c=state_bf16: 1 <= layers <= 64, then SHAPE.
6note op 3 LAYER a=layer b=layers: layer < layers.
7note op 4 FINITE a=eps_l2|eps_norm<<32 b=in_scale|out_scale<<32 (f32 bits): all four finite.
8note op 5 MULTI a=layer b=layers c=tokens, o[0..6] = qkv z ab out xstride abstride ostride.
9note op 6 TOKENS a=T: OMEGA_GDN_PF_MIN_T 3 <= T <= OMEGA_GPU_GDN_PF_MAX_T 65536.
10note op 7 PFLAYOUT a=T b=ratio: o[0..5] the six section offsets, o[6] the total bytes.
11note op 8 MOVE a=kind b=bytes c=dst: kind 4 COPY or 5 ZERO, dst nonzero, bytes a nonzero multiple of 4096 with
12note bytes/4096 <= 0x7fffffff; o[0] = the grid.
13const MASK32 ulong 4294967295
14fn shape r ulong bf ulong o edit ulong 16 to ulong
15if eq r 0
16r = ulong 3
17end
18if or lt r 1 gt r 3
19ret 1
20end
21vh = mul r 16
22vdim = mul vh 128
23conv = add 4096 vdim
24put o 0 r
25put o 1 vh
26put o 2 conv
27put o 3 vdim
28put o 4 mul conv 16
29put o 5 add mul conv 16 mul vh 8
30put o 6 add add mul conv 16 mul vh 8 512
31put o 7 mul vh 6144
32st = mul vh 65536
33if ne bf 0
34st = mul vh 32768
35end
36put o 8 st
37put o 9 div vh 8
38ret 0
39end
40fn fin32 x ulong to ulong
41if eq and shr x 23 255 255
42ret 1
43end
44ret 0
45end
46fn finite a ulong b ulong to ulong
47if ne fin32 and a MASK32 0
48ret 1
49end
50if ne fin32 shr a 32 0
51ret 1
52end
53if ne fin32 and b MASK32 0
54ret 1
55end
56if ne fin32 shr b 32 0
57ret 1
58end
59ret 0
60end
61fn multi a ulong b ulong c ulong o edit ulong 16 to ulong
62if ge a b
63ret 1
64end
65if eq c 0
66ret 1
67end
68if eq get o 0 0
69ret 1
70end
71if eq get o 1 0
72ret 1
73end
74if eq get o 2 0
75ret 1
76end
77if eq get o 3 0
78ret 1
79end
80m16 = or get o 0 get o 1
81m16 = or m16 get o 3
82m16 = or m16 get o 4
83m16 = or m16 get o 6
84if ne and m16 15 0
85ret 1
86end
87if ne and or get o 2 get o 5 7 0
88ret 1
89end
90ret 0
91end
92fn r256 x ulong to ulong
93ret shl shr add x 255 8 8
94end
95fn layout t ulong r ulong o edit ulong 16 to ulong
96if gt t 65536
97ret 1
98end
99sh = new ulong 16 0
100if ne shape r 0 sh 0
101ret 1
102end
103vh = get sh 1
104conv = get sh 2
105vdim = get sh 3
106t8 = mul div add t 7 8 8
107at = ulong 0
108put o 0 at
109at = add at r256 mul mul t conv 4
110put o 1 at
111at = add at r256 mul mul t vdim 4
112put o 2 at
113at = add at r256 mul mul t vh 8
114put o 3 at
115at = add at r256 mul mul t vdim 4
116put o 4 at
117at = add at r256 mul mul t vdim 4
118put o 5 at
119at = add at r256 mul mul t8 vh 1552
120put o 6 at
121ret 0
122end
123fn move k ulong by ulong dst ulong o edit ulong 16 to ulong
124if and ne k 4 ne k 5
125ret 1
126end
127if eq dst 0
128ret 1
129end
130if eq by 0
131ret 1
132end
133if ne rem by 4096 0
134ret 1
135end
136if gt div by 4096 2147483647
137ret 1
138end
139put o 0 div by 4096
140ret 0
141end
142fn gdn_admit op ulong a ulong b ulong c ulong o edit ulong 16 to ulong
143if eq op 1
144ret shape a b o
145end
146if eq op 2
147if or eq a 0 gt a 64
148ret 1
149end
150ret shape b c o
151end
152if eq op 3
153if ge a b
154ret 1
155end
156ret 0
157end
158if eq op 4
159ret finite a b
160end
161if eq op 5
162ret multi a b c o
163end
164if eq op 6
165if or lt a 3 gt a 65536
166ret 1
167end
168ret 0
169end
170if eq op 7
171ret layout a b o
172end
173if eq op 8
174ret move a b c o
175end
176ret 1
177end