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 / components / bw_alloc.om

200 lines · 3444 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note Native migration of omega_bw_ir_append/regalloc_solve at CUDApp b759afc3.
3note Existing BlackwellIR serializer unchanged:8ulong/insn,1024insn,256GPR+32UGPR.
4note meta2048: widths0..287,first288..575,last576..863,phys864..1151,
5note active1152..1439,order1440..1695. Unallocated width0; no pointer identity.
6const BCNONE ulong 18446744073709551615
7fn bc_touch m edit ulong 2048 v ulong ix ulong to void
8if eq get m add v 288 BCNONE
9put m add v 288 ix
10end
11put m add v 576 ix
12end
13fn bc_intervals ins view ulong 8192 n ulong m edit ulong 2048 to uint
14for v ulong 288
15put m add v 288 BCNONE
16put m add v 576 BCNONE
17put m add v 1152 0
18end
19for i ulong n
20b = mul i 8
21f = get ins add b 7
22for k ulong 5
23v = get ins add add b k 1
24if ne v BCNONE
25u = ulong 0
26if eq k 4
27u = 256
28else
29if and eq k 0 ne and f 1 0
30u = 256
31end
32end
33if ge v sub ulong 288 u
34ret 1
35end
36v = add v u
37if eq get m v 0
38ret 1
39end
40bc_touch m v i
41end
42end
43end
44note Explicit loop extension: every backward BRA extends loop-carried intervals.
45for i ulong n
46if eq get ins mul i 8 46
47raw = and get ins add mul i 8 6 4294967295
48if ge raw 2147483648
49delta = sub ulong 4294967296 raw
50if gt delta i
51ret 1
52end
53start = sub i delta
54for v ulong 256
55first = get m add v 288
56last = get m add v 576
57if ne first BCNONE
58if and lt first start ge last start
59if lt last i
60put m add v 576 i
61end
62end
63end
64end
65end
66end
67end
68ret 0
69end
70fn bc_release m edit ulong 2048 busy edit uchar 246 first ulong lim ulong to void
71for v ulong 256
72if ne get m add v 1152 0
73if lt get m add v 576 first
74p = get m add v 864
75for k ulong get m v
76if lt add p k lim
77put busy add p k 0
78end
79end
80put m add v 1152 0
81end
82end
83end
84end
85fn bc_find busy view uchar 246 width ulong lim ulong to ulong
86for p ulong lim
87if ge p 2
88if eq rem p width 0
89if le add p width lim
90ok = true
91for k ulong width
92if ne get busy add p k 0
93ok = false
94end
95end
96if ok
97ret p
98end
99end
100end
101end
102end
103ret BCNONE
104end
105fn bc_allocate m edit ulong 2048 phys edit ulong 288 lim ulong to ulong
106busy = new uchar 246 0
107count = ulong 0
108peak = ulong 2
109for v ulong 256
110if ne get m v 0
111if ne get m add v 288 BCNONE
112put m add count 1440 v
113count = add count 1
114else
115put phys v 2
116end
117end
118end
119note Preserve the reference's exact deterministic pairwise sort, including ties.
120for i ulong count
121for j ulong count
122if gt j i
123a = get m add i 1440
124b = get m add j 1440
125if gt get m add a 288 get m add b 288
126put m add i 1440 b
127put m add j 1440 a
128end
129end
130end
131end
132for i ulong count
133v = get m add i 1440
134bc_release m busy get m add v 288 lim
135w = get m v
136p = bc_find busy w lim
137if eq p BCNONE
138ret 0
139end
140for k ulong w
141put busy add p k 1
142end
143put m add v 864 p
144put m add v 1152 1
145put phys v p
146top = sub add p w 1
147if gt top peak
148peak = top
149end
150end
151ret add peak 1
152end
153fn bc_regalloc ins view ulong 8192 n ulong m edit ulong 2048 phys edit ulong 288 stats edit ulong 4 lim ulong to uint
154if or eq n 0 gt n 1024
155ret 1
156end
157if or lt lim 3 gt lim 246
158ret 1
159end
160for v ulong 288
161w = get m v
162if and ne w 0 and ne w 1 and ne w 2 ne w 4
163ret 1
164end
165if and ge v 256 gt w 2
166ret 1
167end
168put phys v BCNONE
169end
170rc = bc_intervals ins n m
171if ne rc 0
172ret rc
173end
174peak = bc_allocate m phys lim
175if eq peak 0
176ret 2
177end
178cur = ulong 4
179for uv ulong 32
180v = add uv 256
181w = get m v
182if ne w 0
183if eq w 2
184if ne rem cur 2 0
185cur = add cur 1
186end
187end
188if gt add cur w 32
189ret 2
190end
191put phys v cur
192cur = add cur w
193end
194end
195put stats 0 n
196put stats 1 peak
197put stats 2 cur
198put stats 3 0
199ret 0
200end