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 / nvml / abi.om

759 lines · 15835 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note tests/nvml/abi.om: the 55 NVML ABI facts the CUDA++ subset depends on, in seeded Omega. It
3note replaces the former C driver tests/nvml/abi.c and is composed after gate.om (mk/nvml.mk), which
4note calls na_facts once per header. The ORACLE tools see no C source: cc compiles /dev/null with
5note `-include HEADER -g3 -fno-eliminate-unused-debug-types`, and readelf lists the object's DWARF
6note types (--debug-dump=info) and macros (--debug-dump=macro). This unit reads both listings and
7note writes one fact per line in the former abi.c format: `sizeof(T) N`, `offsetof(T, f) N`, or
8note `NAME N` for an enumerator or an integer macro. A fact that is missing, ambiguous or not a
9note plain integer refuses the gate (CUDAPP-NVML HOST FAIL, exit 1).
10note NaSpec rows: `S T` is sizeof T, `O T f` is offsetof(T, f), `V NAME` is a value.
11text NaSpec "S nvmlDevice_t\nS nvmlReturn_t\nS nvmlTemperatureSensors_t\nS nvmlUtilization_t\nO nvmlUtilization_t gpu\nO nvmlUtilization_t memory\nS nvmlMemory_t\nO nvmlMemory_t total\nO nvmlMemory_t free\nO nvmlMemory_t used\nS nvmlProcessInfo_t\nO nvmlProcessInfo_t pid\nO nvmlProcessInfo_t usedGpuMemory\nO nvmlProcessInfo_t gpuInstanceId\nO nvmlProcessInfo_t computeInstanceId\nS nvmlProcessInfo_v2_t\nV NVML_VALUE_NOT_AVAILABLE\nV NVML_TEMPERATURE_GPU\nV NVML_TEMPERATURE_COUNT\nV NVML_DEVICE_NAME_BUFFER_SIZE\nV NVML_DEVICE_NAME_V2_BUFFER_SIZE\nV NVML_DEVICE_UUID_BUFFER_SIZE\nV NVML_DEVICE_UUID_V2_BUFFER_SIZE\nV NVML_SUCCESS\nV NVML_ERROR_UNINITIALIZED\nV NVML_ERROR_INVALID_ARGUMENT\nV NVML_ERROR_NOT_SUPPORTED\nV NVML_ERROR_NO_PERMISSION\nV NVML_ERROR_ALREADY_INITIALIZED\nV NVML_ERROR_NOT_FOUND\nV NVML_ERROR_INSUFFICIENT_SIZE\nV NVML_ERROR_INSUFFICIENT_POWER\nV NVML_ERROR_DRIVER_NOT_LOADED\nV NVML_ERROR_TIMEOUT\nV NVML_ERROR_IRQ_ISSUE\nV NVML_ERROR_LIBRARY_NOT_FOUND\nV NVML_ERROR_FUNCTION_NOT_FOUND\nV NVML_ERROR_CORRUPTED_INFOROM\nV NVML_ERROR_GPU_IS_LOST\nV NVML_ERROR_RESET_REQUIRED\nV NVML_ERROR_OPERATING_SYSTEM\nV NVML_ERROR_LIB_RM_VERSION_MISMATCH\nV NVML_ERROR_IN_USE\nV NVML_ERROR_MEMORY\nV NVML_ERROR_NO_DATA\nV NVML_ERROR_VGPU_ECC_NOT_SUPPORTED\nV NVML_ERROR_INSUFFICIENT_RESOURCES\nV NVML_ERROR_FREQ_NOT_SUPPORTED\nV NVML_ERROR_ARGUMENT_VERSION_MISMATCH\nV NVML_ERROR_DEPRECATED\nV NVML_ERROR_NOT_READY\nV NVML_ERROR_GPU_NOT_FOUND\nV NVML_ERROR_INVALID_STATE\nV NVML_ERROR_RESET_TYPE_NOT_SUPPORTED\nV NVML_ERROR_UNKNOWN\n"
12text NaG3 "-g3"
13text NaFeu "-fno-eliminate-unused-debug-types"
14text NaInc "-include"
15text NaLx "-x"
16text NaNull "/dev/null"
17text NaDi "--debug-dump=info"
18text NaDm "--debug-dump=macro"
19text NaObj "build/nvml/abi.o"
20text NaInfo "build/nvml/abi.info"
21text NaMacr "build/nvml/abi.mac"
22text NaBadH "build/nvml/abi-bad.h"
23text NaBadT "build/nvml/abi-bad.txt"
24text NaWideF " unsigned int gpuInstanceId;"
25text NaWideT " unsigned long long gpuInstanceId;"
26text NaNegOk "PASS abi negative control (a copy of the generated nvml.h with gpuInstanceId widened to 64 bits gives different facts)\n"
27text NaLneg "abi negative control edit)\n"
28text NaLfac "abi fact missing, ambiguous or not an integer in the DWARF listing)\n"
29text NaLcnt "abi fact count)\n"
30text NaTagP "(DW_TAG_"
31text NaAtP "DW_AT_"
32text NaAName "DW_AT_name"
33text NaASize "DW_AT_byte_size"
34text NaAType "DW_AT_type"
35text NaALoc "DW_AT_data_member_location"
36text NaAVal "DW_AT_const_value"
37text NaTTd "typedef)"
38text NaTPtr "pointer_type)"
39text NaTSt "structure_type)"
40text NaTMem "member)"
41text NaTEt "enumeration_type)"
42text NaTEn "enumerator)"
43text NaMDef "DW_MACRO_define"
44text NaMUnd "DW_MACRO_undef"
45text NaMac " macro : "
46text NaSzP "sizeof("
47text NaOfP "offsetof("
48text NaCom ", "
49text NaRp ") "
50text NaSp1 " "
51const NaNone ulong 18446744073709551615
52const NaCap ulong 16384
53note DIE table, one row per DWARF entry in listing order: offset, depth, tag (1 typedef, 2 pointer,
54note 3 structure, 4 member, 5 enumeration, 6 enumerator, 0 other), name span in the listing,
55note byte size, type reference, member offset, and a constant value with its present flag.
56global NaOff ulong 16384
57global NaDep ulong 16384
58global NaTag ulong 16384
59global NaNs ulong 16384
60global NaNl ulong 16384
61global NaSz ulong 16384
62global NaTy ulong 16384
63global NaLoc ulong 16384
64global NaVal ulong 16384
65global NaVf ulong 16384
66global NaDn ulong 1
67note Macro table: name span, value span, 1 define or 0 undef.
68global NaMs ulong 16384
69global NaMl ulong 16384
70global NaVs ulong 16384
71global NaVl ulong 16384
72global NaMd ulong 16384
73global NaMn ulong 1
74global NaOut uchar 65536
75global NaK ulong 1
76global NaCnt ulong 1
77global NaHit ulong 1
78
79note Facts of one header (path hdr, hn bytes) into the facts file out. Exits 90 on any tool refusal.
80fn na_facts hdr view uchar * hn ulong fo view uchar * to void
81na_tools hdr hn
82na_parse
83na_flush fo
84end
85
86note cc and readelf: build/nvml/abi.info and build/nvml/abi.mac for one header.
87fn na_tools hdr view uchar * hn ulong to void
88ng_cc
89hp_arg NaG3 len NaG3
90hp_arg NaFeu len NaFeu
91hp_arg NaInc len NaInc
92hp_arg hdr hn
93hp_arg NgDashC len NgDashC
94hp_arg NaLx len NaLx
95hp_arg NgC len NgC
96hp_arg NaNull len NaNull
97hp_arg NgDashO len NgDashO
98hp_arg NaObj len NaObj
99hp_exec -1 -1 0
100hp_start NgRe len NgRe
101hp_arg NaDi len NaDi
102hp_arg NaObj len NaObj
103ng_exec NaInfo 0
104hp_start NgRe len NgRe
105hp_arg NaDm len NaDm
106hp_arg NaObj len NaObj
107ng_exec NaMacr 0
108end
109
110note Both listings into the DIE and macro tables, then the NaSpec facts into NaOut.
111fn na_parse to void
112info = new uchar 1048576 0
113mac = new uchar 262144 0
114n = hp_read NaInfo len NaInfo info len info
115m = hp_read NaMacr len NaMacr mac len mac
116hp_require gt n 0
117hp_require gt m 0
118put NaDn 0 0
119put NaMn 0 0
120na_lines part info 0 n 0
121na_lines part mac 0 m 1
122put NaK 0 0
123put NaCnt 0 0
124na_spec part info 0 n part mac 0 m
125ng_need eq get NaCnt 0 55 NaLcnt
126end
127
128fn na_flush fo view uchar * to void
129o = new uchar 65536 0
130k = get NaK 0
131for i ulong k
132put o i get NaOut i
133end
134hp_write fo len fo o k
135end
136
137note kind 0: a DWARF info listing (DIE headers and attributes); kind 1: a macro listing.
138fn na_lines t view uchar * kind ulong to void
139p = ulong 0
140while lt p len t bound 999999
141q = na_eol t p
142if eq kind 0
143na_die t p q
144na_attr t p q
145else
146na_mline t p q
147end
148p = add q 1
149end
150end
151
152fn na_eol t view uchar * p ulong to ulong
153q = p
154while lt q len t bound 999999
155if eq get t q 10
156ret q
157end
158q = add q 1
159end
160ret q
161end
162
163fn na_tok t view uchar * s ulong q ulong to ulong
164k = s
165while lt k q bound 999999
166if eq get t k 32
167ret k
168end
169k = add k 1
170end
171ret q
172end
173
174fn na_find t view uchar * p ulong q ulong w view uchar * to ulong
175i = p
176while lt i q bound 999999
177if le add i len w q
178if ng_at t i w
179ret i
180end
181end
182i = add i 1
183end
184ret q
185end
186
187fn na_hv c ulong to ulong
188if and ge c 48 le c 57
189ret sub c 48
190end
191if and ge c 97 le c 102
192ret sub c 87
193end
194ret 16
195end
196
197note Lowercase hex digits from i up to the first other byte; NaNone without a digit or past 16.
198fn na_hex t view uchar * i ulong q ulong to ulong
199v = ulong 0
200k = i
201while lt k q bound 999999
202x = na_hv ulong get t k
203if eq x 16
204break
205end
206if ge sub k i 16
207ret NaNone
208end
209v = add mul v 16 x
210k = add k 1
211end
212if eq k i
213ret NaNone
214end
215ret v
216end
217
218note Exactly the bytes v..q-1 as an unsigned decimal of at most 19 digits, else NaNone.
219fn na_dec t view uchar * v ulong q ulong to ulong
220if ge v q
221ret NaNone
222end
223if gt sub q v 19
224ret NaNone
225end
226x = ulong 0
227k = v
228while lt k q bound 999999
229c = ulong get t k
230if or lt c 48 gt c 57
231ret NaNone
232end
233x = add mul x 10 sub c 48
234k = add k 1
235end
236ret x
237end
238
239note A DIE header line: " <DEPTH><HEX>: Abbrev Number: K (DW_TAG_NAME)". A null entry has no tag.
240fn na_die t view uchar * p ulong q ulong to void
241if lt sub q p 8
242ret
243end
244if ne get t p 32
245ret
246end
247if ne get t add p 1 60
248ret
249end
250i = add p 2
251d = ulong 0
252while lt i q bound 999999
253c = ulong get t i
254if or lt c 48 gt c 57
255break
256end
257d = add mul d 10 sub c 48
258i = add i 1
259end
260if ge add i 2 q
261ret
262end
263if ne get t i 62
264ret
265end
266if ne get t add i 1 60
267ret
268end
269off = na_hex t add i 2 q
270k = na_find t p q NaTagP
271if eq k q
272ret
273end
274na_new d off na_tagof t add k len NaTagP
275end
276
277fn na_tagof t view uchar * s ulong to ulong
278if ng_at t s NaTTd
279ret 1
280end
281if ng_at t s NaTPtr
282ret 2
283end
284if ng_at t s NaTSt
285ret 3
286end
287if ng_at t s NaTMem
288ret 4
289end
290if ng_at t s NaTEt
291ret 5
292end
293if ng_at t s NaTEn
294ret 6
295end
296ret 0
297end
298
299fn na_new d ulong off ulong tag ulong to void
300n = get NaDn 0
301hp_require lt n NaCap
302put NaOff n off
303put NaDep n d
304put NaTag n tag
305put NaNs n 0
306put NaNl n 0
307put NaSz n NaNone
308put NaTy n NaNone
309put NaLoc n NaNone
310put NaVal n 0
311put NaVf n 0
312put NaDn 0 add n 1
313end
314
315note Start of the text after the last ": " of the line p..q-1, or q.
316fn na_last t view uchar * p ulong q ulong to ulong
317if lt sub q p 2
318ret q
319end
320k = sub q 1
321while gt k p bound 999999
322if eq get t sub k 1 58
323if eq get t k 32
324ret add k 1
325end
326end
327k = sub k 1
328end
329ret q
330end
331
332note The attribute name w starts at a and ends at a space or a colon.
333fn na_isat t view uchar * a ulong q ulong w view uchar * to bool
334e = add a len w
335if ge e q
336ret false
337end
338if not ng_at t a w
339ret false
340end
341c = get t e
342if eq c 32
343ret true
344end
345ret eq c 58
346end
347
348note An attribute line " <HEX> DW_AT_NAME : VALUE" of the latest DIE.
349fn na_attr t view uchar * p ulong q ulong to void
350n = get NaDn 0
351if eq n 0
352ret
353end
354a = na_find t p q NaAtP
355if eq a q
356ret
357end
358v = na_last t p q
359if eq v q
360ret
361end
362i = sub n 1
363if na_isat t a q NaAName
364put NaNs i v
365put NaNl i sub q v
366ret
367end
368if na_isat t a q NaASize
369put NaSz i na_dec t v q
370ret
371end
372if na_isat t a q NaAType
373put NaTy i na_ref t v q
374ret
375end
376if na_isat t a q NaALoc
377put NaLoc i na_dec t v q
378ret
379end
380if na_isat t a q NaAVal
381na_sval t v q i
382end
383end
384
385note A type reference "<0xHEX>".
386fn na_ref t view uchar * v ulong q ulong to ulong
387if lt sub q v 4
388ret NaNone
389end
390if ne get t v 60
391ret NaNone
392end
393if ne get t add v 1 48
394ret NaNone
395end
396if ne get t add v 2 120
397ret NaNone
398end
399if ne get t sub q 1 62
400ret NaNone
401end
402ret na_hex t add v 3 sub q 1
403end
404
405note A constant "N" or "-N"; the DIE keeps its value only when the whole text is an integer.
406fn na_sval t view uchar * v ulong q ulong i ulong to void
407sg = eq get t v 45
408s = v
409if sg
410s = add v 1
411end
412x = na_dec t s q
413if eq x NaNone
414ret
415end
416if sg
417x = sub 0 x
418end
419put NaVal i x
420put NaVf i 1
421end
422
423note A macro line "DW_MACRO_define... macro : NAME VALUE" or "DW_MACRO_undef... macro : NAME".
424fn na_mline t view uchar * p ulong q ulong to void
425d = ulong 2
426if lt na_find t p q NaMDef q
427d = 1
428end
429if lt na_find t p q NaMUnd q
430d = 0
431end
432if eq d 2
433ret
434end
435m = na_find t p q NaMac
436if eq m q
437ret
438end
439s = add m len NaMac
440e = na_tok t s q
441if eq e s
442ret
443end
444n = get NaMn 0
445hp_require lt n NaCap
446put NaMs n s
447put NaMl n sub e s
448put NaMd n d
449vs = e
450if lt e q
451vs = add e 1
452end
453put NaVs n vs
454put NaVl n sub q vs
455put NaMn 0 add n 1
456end
457
458fn na_spec t view uchar * m view uchar * to void
459p = ulong 0
460while lt p len NaSpec bound 999999
461p = na_fact t m p
462end
463end
464
465note One NaSpec row at p: append its fact line; return the next row.
466fn na_fact t view uchar * m view uchar * p ulong to ulong
467q = na_eol NaSpec p
468s = add p 2
469e = na_tok NaSpec s q
470c = get NaSpec p
471put NaHit 0 0
472if eq c 83
473na_fs t s e
474end
475if eq c 79
476na_fo t s e q
477end
478if eq c 86
479na_fv t m s e
480end
481ng_need eq get NaHit 0 1 NaLfac
482na_out NgNl 0 1
483put NaCnt 0 add get NaCnt 0 1
484ret add q 1
485end
486
487fn na_fs t view uchar * s ulong e ulong to void
488na_out NaSzP 0 len NaSzP
489na_out NaSpec s sub e s
490na_out NaRp 0 len NaRp
491na_outn na_size t s sub e s
492end
493
494fn na_fo t view uchar * s ulong e ulong q ulong to void
495f = add e 1
496hp_require lt f q
497na_out NaOfP 0 len NaOfP
498na_out NaSpec s sub e s
499na_out NaCom 0 len NaCom
500na_out NaSpec f sub q f
501na_out NaRp 0 len NaRp
502na_outn na_offs t s sub e s f sub q f
503end
504
505fn na_fv t view uchar * m view uchar * s ulong e ulong to void
506na_out NaSpec s sub e s
507na_out NaSp1 0 1
508na_outn na_val t m s sub e s
509end
510
511fn na_out src view uchar * off ulong n ulong to void
512k = get NaK 0
513hp_require le add k n 65536
514for i ulong n
515put NaOut add k i get src add off i
516end
517put NaK 0 add k n
518end
519
520note A value as the C printf("%lld") of its 64 bits.
521fn na_outn v ulong to void
522d = new uchar 32 0
523x = v
524if ge v 9223372036854775808
525na_out HPMinus 0 1
526x = sub 0 v
527end
528n = hp_num x d
529na_out d 0 n
530end
531
532note The name of DIE i, or of macro i, equals the NaSpec name s..s+sl.
533fn na_dname t view uchar * i ulong s ulong sl ulong to bool
534ns = get NaNs i
535nl = get NaNl i
536ret na_name t ns nl s sl
537end
538
539fn na_mname m view uchar * i ulong s ulong sl ulong to bool
540ns = get NaMs i
541nl = get NaMl i
542ret na_name m ns nl s sl
543end
544
545note The listing name ns..ns+nl equals the NaSpec name s..s+sl.
546fn na_name t view uchar * ns ulong nl ulong s ulong sl ulong to bool
547if ne nl sl
548ret false
549end
550for i ulong nl
551if ne get t add ns i get NaSpec add s i
552ret false
553end
554end
555ret true
556end
557
558note The one typedef named s..s+sl, else NaNone.
559fn na_tdef t view uchar * s ulong sl ulong to ulong
560r = NaNone
561hits = ulong 0
562for i ulong get NaDn 0
563if eq get NaTag i 1
564if na_dname t i s sl
565r = i
566hits = add hits 1
567end
568end
569end
570if ne hits 1
571ret NaNone
572end
573ret r
574end
575
576fn na_byoff off ulong to ulong
577for i ulong get NaDn 0
578if eq get NaOff i off
579ret i
580end
581end
582ret NaNone
583end
584
585note Follow typedefs to the type they name (at most 8 steps).
586fn na_res i ulong to ulong
587k = i
588for step ulong 8
589if eq k NaNone
590ret NaNone
591end
592if ne get NaTag k 1
593ret k
594end
595r = get NaTy k
596if eq r NaNone
597ret NaNone
598end
599k = na_byoff r
600end
601ret NaNone
602end
603
604fn na_size t view uchar * s ulong sl ulong to ulong
605k = na_res na_tdef t s sl
606if eq k NaNone
607ret 0
608end
609z = get NaSz k
610if eq z NaNone
611ret 0
612end
613put NaHit 0 1
614ret z
615end
616
617fn na_offs t view uchar * s ulong sl ulong f ulong fl ulong to ulong
618k = na_res na_tdef t s sl
619if eq k NaNone
620ret 0
621end
622if ne get NaTag k 3
623ret 0
624end
625ret na_memb t k f fl
626end
627
628note The direct member f..f+fl of the structure DIE k.
629fn na_memb t view uchar * k ulong f ulong fl ulong to ulong
630d = get NaDep k
631j = add k 1
632while lt j get NaDn 0 bound 999999
633if le get NaDep j d
634ret 0
635end
636if eq get NaDep j add d 1
637if eq get NaTag j 4
638if na_dname t j f fl
639z = get NaLoc j
640if eq z NaNone
641ret 0
642end
643put NaHit 0 1
644ret z
645end
646end
647end
648j = add j 1
649end
650ret 0
651end
652
653note An enumerator (exactly one with a constant) or else a macro (exactly one define, no undef).
654fn na_val t view uchar * m view uchar * s ulong sl ulong to ulong
655r = ulong 0
656hits = ulong 0
657for i ulong get NaDn 0
658if eq get NaTag i 6
659if na_dname t i s sl
660if eq get NaVf i 1
661r = get NaVal i
662hits = add hits 1
663end
664end
665end
666end
667if eq hits 1
668put NaHit 0 1
669ret r
670end
671if gt hits 1
672ret 0
673end
674ret na_mval m s sl
675end
676
677fn na_mval m view uchar * s ulong sl ulong to ulong
678r = ulong 0
679hits = ulong 0
680for i ulong get NaMn 0
681if na_mname m i s sl
682hits = add hits 1
683r = i
684end
685end
686if ne hits 1
687ret 0
688end
689if ne get NaMd r 1
690ret 0
691end
692ret na_eval m get NaVs r get NaVl r
693end
694
695note A macro body N, -N, (N) or (-N), up to 4 levels of parentheses.
696fn na_eval m view uchar * vs ulong vl ulong to ulong
697a = vs
698b = add vs vl
699for step ulong 4
700if lt sub b a 3
701break
702end
703if ne get m a 40
704break
705end
706if ne get m sub b 1 41
707break
708end
709a = add a 1
710b = sub b 1
711end
712if ge a b
713ret 0
714end
715sg = eq get m a 45
716if sg
717a = add a 1
718end
719x = na_dec m a b
720if eq x NaNone
721ret 0
722end
723put NaHit 0 1
724if sg
725ret sub 0 x
726end
727ret x
728end
729
730note Widen gpuInstanceId in a copy of the generated header; its facts must differ from NVIDIA's.
731fn na_neg to void
732h = new uchar 65536 0
733d = new uchar 65536 0
734m = hp_read NgCH len NgCH h len h
735hp_require gt m 0
736k = na_wide part h 0 m d
737hp_write NaBadH len NaBadH d k
738na_facts NaBadH len NaBadH NaBadT
739hp_require not hp_cmp NaBadT len NaBadT NgCT len NgCT
740hp_wpart 1 NaNegOk 0 len NaNegOk
741end
742
743fn na_wide a view uchar * dst edit uchar 65536 to ulong
744k = ulong 0
745hits = ulong 0
746p = ulong 0
747while lt p len a bound 999999
748if ng_at a p NaWideF
749k = ng_put dst k NaWideT 0 len NaWideT
750p = add p len NaWideF
751hits = add hits 1
752else
753k = ng_put dst k a p 1
754p = add p 1
755end
756end
757ng_need eq hits 1 NaLneg
758ret k
759end