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 / tests / share / fake-rm.om

441 lines · 8727 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note Fake NVIDIA RM and UVM for the zero-copy host test. No device file is opened.
3note The runner renames devctl, devcall, uvmctl, fopen, fclose, mapbind and mapnew in a private
4note copy of context.om plus share.om to the fk words below. Layouts, request numbers and
5note statuses come from the generated k functions (tests/share/abi-oracle.c), not from share.om.
6note Each memory object's pages are a memfd, so a CPU import really aliases the owner's bytes.
7note Map bounds follow 580.173.02 mapping_cpu.c: offset at or past the end is INVALID_BASE,
8note zero length or a span past the end is INVALID_LIMIT.
9text fkname "fake-rm-memory"
10global fkcli uint 64
11global fkhnd uint 64
12global fkbk ulong 64
13global fklive uchar 64
14global fkshr uchar 64
15global fbfd int 16
16global fbsize ulong 16
17global fbref uint 16
18global fbview long 16
19global fbn ulong 1
20global fdopen uchar 32
21global fdbk ulong 32
22global fdro uchar 32
23global fdn ulong 1
24global frbase ulong 16
25global frlive uchar 16
26global fdmh uint 16
27global fdmlive uchar 16
28note Counters: 0 RM and UVM calls, 1 shares, 2 dups, 3 frees, 4 maps accepted, 5 DMA maps,
29note 6 DMA unmaps, 7 UVM ranges, 8 UVM external maps, 9 UVM frees, 10 opens, 11 closes,
30note 12 backings released, 13 binds.
31global fcnt ulong 16
32note Last seen: 0 map flags, 1 DMA flags, 2 UVM mapping type, 3 bind access, 4 share target,
33note 5 share mask, 6 share type, 7 share action, 8 dup flags.
34global flast uint 16
35global finj ulong 1
36global finjst uint 1
37global fkchk ulong 1
38text fkbad "ZERO_COPY_SHARE_HOST_FAIL fake check "
39text fknl "\n"
40note A fake-side contract breach: share.om sent something the RM ABI does not allow.
41fn fkok yes bool to void
42put fkchk 0 add get fkchk 0 1
43if not yes
44w = write 2 fkbad 0 len fkbad
45tprintn 2 get fkchk 0
46w = write 2 fknl 0 len fknl
47exit int 1
48end
49end
50fn fkbump i ulong to void
51put fcnt i add get fcnt i 1
52end
53fn fkfind cli uint h uint to ulong
54for i ulong 64
55if and ne get fklive i 0 and eq get fkcli i cli eq get fkhnd i h
56ret i
57end
58end
59ret 64
60end
61fn fkhascli cli uint to bool
62for i ulong 64
63if and ne get fklive i 0 eq get fkcli i cli
64ret true
65end
66end
67ret false
68end
69fn fklivecnt cli uint to ulong
70n = ulong 0
71for i ulong 64
72if and ne get fklive i 0 eq get fkcli i cli
73n = add n 1
74end
75end
76ret n
77end
78fn fkback size ulong to ulong
79b = get fbn 0
80fkok lt b 16
81m = int memfd fkname 0 len fkname 0
82fkok ge m 0
83fkok eq ftrunc m long size 0
84v = mapnew m 0 size 3 1
85fkok gt v 0
86put fbfd b m
87put fbsize b size
88put fbref b 0
89put fbview b v
90put fbn 0 add b 1
91ret b
92end
93fn fkobj cli uint h uint b ulong to ulong
94fkok eq fkfind cli h 64
95for i ulong 64
96if eq get fklive i 0
97put fkcli i cli
98put fkhnd i h
99put fkbk i b
100put fkshr i 0
101put fklive i 1
102put fbref b add get fbref b 1
103ret i
104end
105end
106fkok false
107ret 64
108end
109fn fkunobj i ulong to void
110b = get fkbk i
111put fklive i 0
112put fkshr i 0
113fkok gt get fbref b 0
114put fbref b sub get fbref b 1
115if eq get fbref b 0
116fkok eq mapdrop get fbview b 0
117fkok eq fclose get fbfd b 0
118fkbump 12
119end
120end
121note An object owned by another process's RM client.
122fn fkforeign cli uint h uint size ulong shared bool to ulong
123i = fkobj cli h fkback size
124if shared
125put fkshr i 1
126end
127ret i
128end
129
130fn fkopen code ulong to long
131fkok or eq code 1 eq code 3
132i = get fdn 0
133fkok lt i 32
134put fdn 0 add i 1
135put fdopen i 1
136put fdbk i 0
137put fdro i 0
138fkbump 10
139ret long add 1000 i
140end
141fn fkfdi fd int to ulong
142fkok and ge fd 1000 lt fd 1032
143i = ulong sub fd 1000
144fkok lt i get fdn 0
145ret i
146end
147fn fkclose fd int to long
148i = fkfdi fd
149fkok eq get fdopen i 1
150put fdopen i 0
151fkbump 11
152ret 0
153end
154fn fknew fd int off ulong n ulong acc int mode int to long
155fkok false
156ret neg long 5
157end
158fn fkbind m long fd int off ulong acc int to long
159i = fkfdi fd
160fkok eq get fdopen i 1
161fkok eq off 0
162fkok ne get fdbk i 0
163put flast 3 uint acc
164b = sub get fdbk i 1
165if and ne get fdro i 0 ne acc 1
166ret neg long 13
167end
168fkbump 13
169if eq acc 1
170ret mapbind m get fbfd b 0 1
171end
172ret mapbind m get fbfd b 0 3
173end
174
175fn fkctl fd int req uint off ulong n ulong to long
176fkok eq off 0
177fkok eq fd get nvfd 0
178fkbump 0
179r = ulong req
180if eq r kreqfree
181fkok eq n kszfree
182fkfreeop
183ret 0
184end
185if eq r kreqshare
186fkok eq n kszshare
187fkshareop
188ret 0
189end
190if eq r kreqdup
191fkok eq n kszdup
192fkdupop
193ret 0
194end
195if eq r kreqmap
196fkok eq n kszmap
197fkmapop
198ret 0
199end
200if eq r kreqdma
201fkok eq n kszdma
202fkdmaop
203ret 0
204end
205if eq r krequndma
206fkok eq n kszundma
207fkundmaop
208ret 0
209end
210fkok false
211ret neg long 22
212end
213fn fkcall fd int req uint ho ulong hn ulong po ulong pn ulong to long
214fkok eq fd get nvfd 0
215fkok eq ulong req kreqalloc
216fkok and eq ho 0 eq hn 32
217fkok eq po 0
218fkbump 0
219fkok eq nhget kalcclient get nvobj 0
220fkok eq nhget kalcparent get nvobj 1
221fkok eq nhget kalcclass 62
222h = nhget kalcnew
223fkok ne h 0
224size = npg64 kmemsize
225fkok and gt size 0 eq and size 4095 0
226i = fkobj get nvobj 0 h fkback size
227nhput kalcstatus 0
228ret 0
229end
230fn fkuvm fd int cmd uint off ulong n ulong to long
231fkok eq fd get nvfd 2
232fkok eq off 0
233fkbump 0
234c = ulong cmd
235if and ne get finj 0 0 eq c get finj 0
236put finj 0 0
237if eq c kuvmrange
238npput krangestatus get finjst 0
239end
240if eq c kuvmmapext
241npput kextstatus get finjst 0
242end
243ret 0
244end
245if eq c kuvmrange
246fkok eq n kszrange
247fkrangeop
248ret 0
249end
250if eq c kuvmmapext
251fkok eq n kszmapext
252fkextop
253ret 0
254end
255if eq c kuvmfree
256fkok eq n kszuvmfree
257fkufreeop
258ret 0
259end
260fkok false
261ret neg long 22
262end
263
264fn fkfreeop to void
265fkok eq nhget kfreeclient get nvobj 0
266fkok eq nhget kfreeparent get nvobj 1
267i = fkfind get nvobj 0 nhget kfreeobj
268if eq i 64
269nhput kfreestatus uint kerrnotfound
270ret
271end
272for j ulong 16
273if and ne get fdmlive j 0 eq get fdmh j get fkhnd i
274put fdmlive j 0
275end
276end
277fkunobj i
278fkbump 3
279nhput kfreestatus 0
280end
281fn fkshareop to void
282i = fkfind npget kshclient npget kshobj
283put flast 4 npget kshtarget
284put flast 5 npget kshmask
285put flast 6 and npget kshtype 65535
286put flast 7 uint get nvpar kshaction
287if eq i 64
288npput kshstatus uint kerrnotfound
289ret
290end
291if and eq ulong npget kshmask kshdupbit eq ulong get flast 6 kshtoken
292put fkshr i 1
293end
294fkbump 1
295npput kshstatus 0
296end
297fn fkdupop to void
298cli = npget kdupclient
299fkok eq cli get nvobj 0
300fkok eq npget kdupparent get nvobj 1
301h = npget kdupobj
302fkok ne h 0
303put flast 8 npget kdupflags
304scli = npget kdupsrcclient
305if not fkhascli scli
306npput kdupstatus uint kerrclient
307ret
308end
309s = fkfind scli npget kdupsrcobj
310if eq s 64
311npput kdupstatus uint kerrnotfound
312ret
313end
314if and ne scli cli eq get fkshr s 0
315npput kdupstatus uint kerrperm
316ret
317end
318i = fkobj cli h get fkbk s
319fkbump 2
320npput kdupstatus 0
321end
322fn fkmapop to void
323fkok eq npget kmapclient get nvobj 0
324fkok eq npget kmapdevice get nvobj 1
325i = fkfind get nvobj 0 npget kmapmem
326if eq i 64
327npput kmapstatus uint kerrnotfound
328ret
329end
330size = get fbsize get fkbk i
331off = npg64 kmapoffset
332n = npg64 kmaplength
333fl = npget kmapflags
334put flast 0 fl
335if ge off size
336npput kmapstatus uint kerrbase
337ret
338end
339if or eq n 0 gt add off n size
340npput kmapstatus uint kerrlimit
341ret
342end
343d = fkfdi int npget kmapfd
344fkok eq get fdopen d 1
345put fdbk d add get fkbk i 1
346put fdro d 0
347if eq ulong and fl 3 kmapro
348put fdro d 1
349end
350fkbump 4
351npput kmapstatus 0
352end
353fn fkdmaop to void
354fkok eq npget kdmaclient get nvobj 0
355fkok eq npget kdmadevice get nvobj 1
356fkok eq npget kdmactx get nvobj 3
357h = npget kdmamem
358put flast 1 npget kdmaflags
359o = fkfind get nvobj 0 h
360if eq o 64
361npput kdmastatus uint kerrnotfound
362ret
363end
364note GPU VA is fixed at a reserved UVM range and covers the whole object.
365fkok fkhasrange npg64 kdmaoffset
366fkok eq npg64 kdmalength get fbsize get fkbk o
367for j ulong 16
368if eq get fdmlive j 0
369put fdmh j h
370put fdmlive j 1
371fkbump 5
372npput kdmastatus 0
373ret
374end
375end
376fkok false
377end
378fn fkundmaop to void
379h = npget kundmamem
380for j ulong 16
381if and ne get fdmlive j 0 eq get fdmh j h
382put fdmlive j 0
383fkbump 6
384npput kundmastatus 0
385ret
386end
387end
388npput kundmastatus uint kerrnotfound
389end
390fn fkrangeop to void
391b = npg64 krangebase
392fkok gt npg64 krangelength 0
393for j ulong 16
394if eq get frlive j 0
395put frbase j b
396put frlive j 1
397fkbump 7
398npput krangestatus 0
399ret
400end
401end
402fkok false
403end
404fn fkhasrange b ulong to bool
405for j ulong 16
406if and ne get frlive j 0 eq get frbase j b
407ret true
408end
409end
410ret false
411end
412fn fkextop to void
413fkok fkhasrange npg64 kextbase
414fkok eq npg64 kextcount 1
415fkok eq npget kextfd uint get nvfd 0
416fkok eq npget kextclient get nvobj 0
417put flast 2 npget kexttype
418for i ulong 16
419fkok eq get nvpar add kextuuid i get nvuuid i
420end
421o = fkfind get nvobj 0 npget kextmem
422if eq o 64
423npput kextstatus uint kerrnotfound
424ret
425end
426fkok eq npg64 kextlength get fbsize get fkbk o
427fkbump 8
428npput kextstatus 0
429end
430fn fkufreeop to void
431b = npg64 kfreebase
432for j ulong 16
433if and ne get frlive j 0 eq get frbase j b
434put frlive j 0
435fkbump 9
436npput kfreestat 0
437ret
438end
439end
440fkok false
441end