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 / native / aiengpu / context.om

228 lines · 5465 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note aien-gpu compute ABI 1 client decisions and request bytes (CUDApp#128). Successor of the logic in
3note src/omega_gpu_platform_aien.c; that C stays behind CUDAPP_MIGRATION_PENDING_C_PLATFORM_AIEN as the oracle.
4note Layouts: third_party/aien-gpu-abi1/aien_gpu_uapi.h, little endian, reserved bytes zero. The open, ioctl,
5note mmap and doorbell/USERD stores stay in the C host binding until devctl accepts the AGPU requests.
6note m[0] operation, m[1..] arguments; b is one 128-byte request or reply block (the largest struct is 112).
7note 1 info check: b=agpu_info; 0 usable, 1 abi is not 1, 2 state is not RM_READY (4).
8note 2 mem size: m1 bytes; page-rounded size, or 0 when bytes is 0 or above 2^37.
9note 3 VA start: m1 cursor; the cursor, or the window base when it lies outside [2^36, 2^40).
10note 4 VA align: m1 x, m2 align; x rounded up to max(align, 4096).
11note 5 VA try: m1 at, m2 size, m3 wrapped, m4 start; 0 reserve at, 1 give up, 2 wrap to the base.
12note 6 VA base, 7 VA top. 8 VA step: m1 at, m2 size, m3 align; next candidate after a taken range.
13note 9 MEM_ALLOC request: m1 size, m2 va, m3 flags; writes b, returns 48 (bytes of the request).
14note 10 rm ok: m1 offset of agpu_rm_status in b; 1 when its verdict is AGPU_RM_OK (1).
15note 11 MEM_FREE request: m1 handle; returns 24. 12 CHAN_CREATE request: m1 ring/USERD handle, m2 notifier
16note handle; 1024 entries, ring at 0, USERD at 8192; returns 72. 13 CHAN_DESTROY request: m1 channel; 24.
17note 14 cache policy: m1 kind, m2 rights, m3 cache; 1 GPU-uncached flag, 0 GPU-cached, 2 refused.
18note 15 range: m1 size, m2 off, m3 len; 1 inside. 16 poll check: m1 rights, m2 off, m3 size;
19note 0 ok, 1 not HOST_POLLED, 2 misaligned, 3 out of range. 17 serial compare: m1 observed, m2 target;
20note 1 when (int32)(observed - target) >= 0.
21note 18 submit plan: m1 nwords, m2 words present, m3 L2 invalidate pending, m4 pushbuffer bytes, m5 put,
22note m6 retired, m7 pushbuffer VA. 0 accepted, 1 bad args, 2 bad length, 3 ring full. Accepted writes
23note b[0..20) prefix words, b[24..32) GP entry, b[32..36) ring slot, b[36..40) new GPPut, b[40..44)
24note prefix words, b[44..48) total words.
25note 19 GP entry: m1 va, m2 words. Any other operation returns 0 and writes nothing.
26const AGBASE ulong 68719476736
27const AGTOP ulong 1099511627776
28const AGMAXB ulong 137438953472
29const AGPAGE ulong 4096
30const AGGPMAX ulong 2097151
31const AGRING ulong 1024
32const AGUSERD ulong 8192
33const AGUNC ulong 1
34fn ag_put b edit uchar 128 off ulong v ulong n ulong to void
35for i ulong 8
36if ge i n
37break
38end
39put b add off i uchar and shr v mul i 8 255
40end
41end
42fn ag_load b edit uchar 128 off ulong n ulong to ulong
43v = ulong 0
44for i ulong 8
45if ge i n
46break
47end
48v = or v shl ulong get b add off i mul i 8
49end
50ret v
51end
52fn ag_clear b edit uchar 128 to void
53for i ulong 128
54put b i uchar 0
55end
56end
57fn ag_align x ulong a ulong to ulong
58al = a
59if lt al AGPAGE
60al = AGPAGE
61end
62y = sub add x al 1
63ret sub y and y sub al 1
64end
65fn ag_gp va ulong n ulong to ulong
66ret or or sub va and va 3 shl and n AGGPMAX 42 shl ulong 1 41
67end
68fn ag_submit m view ulong 16 b edit uchar 128 to ulong
69if or eq get m 2 0 eq get m 1 0
70ret 1
71end
72pre = ulong 0
73if ne get m 3 0
74pre = ulong 5
75end
76total = add get m 1 pre
77if or gt mul total 4 get m 4 gt total AGGPMAX
78ret 2
79end
80if ge and sub get m 5 get m 6 4294967295 sub AGRING 1
81ret 3
82end
83ag_clear b
84if ne pre 0
85ag_put b 0 537133066 4
86ag_put b 16 2281701376 4
87end
88ag_put b 24 ag_gp get m 7 total 8
89ag_put b 32 rem and get m 5 4294967295 AGRING 4
90ag_put b 36 rem and add get m 5 1 4294967295 AGRING 4
91ag_put b 40 pre 4
92ag_put b 44 total 4
93ret 0
94end
95fn ag_range sz ulong off ulong ln ulong to ulong
96if or eq ln 0 gt off sz
97ret 0
98end
99if gt ln sub sz off
100ret 0
101end
102ret 1
103end
104fn ag_chk m view ulong 16 b edit uchar 128 to ulong
105op = get m 0
106if eq op 14
107if eq get m 3 1
108note GPU-cached only for device-private DATA (kind 2): no CPU_READ (1), no HOST_POLLED (32).
109if or ne get m 1 2 ne and get m 2 33 0
110ret 2
111end
112ret 0
113end
114ret AGUNC
115end
116if eq op 15
117ret ag_range get m 1 get m 2 get m 3
118end
119if eq op 16
120if eq and get m 1 32 0
121ret 1
122end
123if ne and get m 2 3 0
124ret 2
125end
126if eq ag_range get m 3 get m 2 4 0
127ret 3
128end
129ret 0
130end
131if eq op 17
132if lt and sub get m 1 get m 2 4294967295 2147483648
133ret 1
134end
135ret 0
136end
137if eq op 18
138ret ag_submit m b
139end
140if eq op 19
141ret ag_gp get m 1 get m 2
142end
143ret 0
144end
145fn aiengpu m view ulong 16 b edit uchar 128 to ulong
146op = get m 0
147if eq op 1
148if ne ag_load b 0 4 1
149ret 1
150end
151if ne ag_load b 4 4 4
152ret 2
153end
154ret 0
155end
156if eq op 2
157if or eq get m 1 0 gt get m 1 AGMAXB
158ret 0
159end
160ret ag_align get m 1 AGPAGE
161end
162if eq op 3
163if or lt get m 1 AGBASE ge get m 1 AGTOP
164ret AGBASE
165end
166ret get m 1
167end
168if eq op 4
169ret ag_align get m 1 get m 2
170end
171if eq op 5
172if gt add get m 1 get m 2 AGTOP
173if ne get m 3 0
174ret 1
175end
176ret 2
177end
178if and ne get m 3 0 ge get m 1 get m 4
179ret 1
180end
181ret 0
182end
183if eq op 6
184ret AGBASE
185end
186if eq op 7
187ret AGTOP
188end
189if eq op 8
190ret ag_align add get m 1 get m 2 get m 3
191end
192if eq op 9
193ag_clear b
194ag_put b 0 get m 1 8
195ag_put b 8 get m 2 8
196ag_put b 16 get m 3 4
197ret 48
198end
199if eq op 10
200if eq ag_load b get m 1 4 1
201ret 1
202end
203ret 0
204end
205if eq op 11
206ag_clear b
207ag_put b 0 get m 1 4
208ret 24
209end
210if eq op 12
211ag_clear b
212ag_put b 0 get m 1 4
213ag_put b 4 AGRING 4
214ag_put b 16 get m 1 4
215ag_put b 20 get m 2 4
216ag_put b 24 AGUSERD 8
217ret 72
218end
219if eq op 13
220ag_clear b
221ag_put b 0 get m 1 4
222ret 24
223end
224if ge op 14
225ret ag_chk m b
226end
227ret 0
228end