interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / gpu / qual / non_nvidia_qual.om

259 lines · 5598 bytes Raw Blame History
1om2
2note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3note gpu/qual/non_nvidia_qual.om: pure-Omega non-NVIDIA physical GPU discovery & qualification runner.
4note Compiles for BOTH AArch64 Linux and target x86linux (prefix 'target x86linux' before om2).
5note Compose after seed/ng/sha256.om:
6note { printf 'om2\n'; cat seed/ng/sha256.om gpu/qual/non_nvidia_qual.om | grep -v '^om2$'; } | seed/out/omc > non_nvidia_qual
7note
8note Usage:
9note non_nvidia_qual [--root DIR]
10note
11note Scans PCI devices (<root>/sys/bus/pci/devices), AMD KFD (<root>/dev/kfd),
12note DRM render nodes (<root>/dev/dri/renderD128), and OpenCL/Vulkan ICD directories to verify
13note physical non-NVIDIA GPU attachment (AMD 0x1002, Intel 0x8086, Apple/other non-0x10de).
14note Never mislabels NVIDIA-only or CPU-only hosts as non-NVIDIA GPU qualification!
15note
16note Exit codes:
17note 0 PHYSICAL_NON_NVIDIA_DETECTED (AMD KFD and/or Intel Xe / non-NVIDIA DRM render node ready)
18note 2 usage error
19note 3 BLOCKED_HARDWARE (no physical non-NVIDIA GPU attached on this host)
20
21text nq_froot "--root"
22text nq_ppci "/sys/bus/pci/devices"
23text nq_pven "/vendor"
24text nq_pdev "/device"
25text nq_pcls "/class"
26text nq_pkfd "/dev/kfd"
27text nq_pdri "/dev/dri/renderD128"
28text nq_pocl "/etc/OpenCL/vendors"
29text nq_hdr "OMEGA-NON-NVIDIA-GPU-QUAL v1\n"
30text nq_amd "GPU_AMD_PCI count="
31text nq_int "GPU_INTEL_PCI count="
32text nq_nv "GPU_NVIDIA_PCI count="
33text nq_kfd "DEV_KFD="
34text nq_dri "DEV_DRI_RENDERD128="
35text nq_ocl "OPENCL_ICD_DIR="
36text nq_yes "present\n"
37text nq_no "absent\n"
38text nq_ready "VERDICT=NON_NVIDIA_HARDWARE_PRESENT (run vendor hardware gate: gpu/amd or gpu/intel or gpu/spirv)\n"
39text nq_blk "VERDICT=BLOCKED_HARDWARE reason=no_physical_non_nvidia_gpu_attached\n"
40text nq_use "usage: non_nvidia_qual [--root DIR]\n"
41
42global nq_root uchar 2048
43global nq_rlen ulong 1
44global nq_path uchar 4096
45global nq_tmp uchar 4096
46global nq_dents uchar 16384
47global nq_cnt ulong 8
48global nq_num uchar 24
49
50fn nq_wnum v ulong to void
51n = ulong 0
52x = v
53while true bound 20
54put nq_num sub 23 n uchar add 48 rem x 10
55n = add n 1
56x = div x 10
57if eq x 0
58break
59end
60end
61r = write 1 nq_num sub 24 n n
62nl = new uchar 1 10
63r = write 1 nl 0 1
64end
65
66fn nq_mkpath suffix view uchar * to ulong
67rl = get nq_rlen 0
68for i ulong rl bound 2048
69put nq_path i get nq_root i
70end
71for i ulong len suffix bound 2048
72put nq_path add rl i get suffix i
73end
74ret add rl len suffix
75end
76
77fn nq_readhex plen ulong to ulong
78fd = fopen nq_path 0 plen 0 0
79if lt fd 0
80ret 0
81end
82got = read int fd nq_tmp 0 64
83r = fclose int fd
84if le got 0
85ret 0
86end
87p = ulong 0
88if ge got 2
89if and eq get nq_tmp 0 48 or eq get nq_tmp 1 120 eq get nq_tmp 1 88
90p = ulong 2
91end
92end
93v = ulong 0
94while lt p ulong got bound 32
95c = ulong get nq_tmp p
96if and ge c 48 le c 57
97v = add mul v 16 sub c 48
98else
99if and ge c 97 le c 102
100v = add mul v 16 add 10 sub c 97
101else
102if and ge c 65 le c 70
103v = add mul v 16 add 10 sub c 65
104else
105break
106end
107end
108end
109p = add p 1
110end
111ret v
112end
113
114global nq_bdf uchar 64
115
116fn nq_check_bdf nl ulong to void
117if eq nl 0
118ret
119end
120if and eq nl 1 eq get nq_bdf 0 46
121ret
122end
123if and eq nl 2 and eq get nq_bdf 0 46 eq get nq_bdf 1 46
124ret
125end
126bp = nq_mkpath nq_ppci
127put nq_path bp 47
128bp = add bp 1
129for k ulong nl bound 64
130put nq_path add bp k get nq_bdf k
131end
132bp = add bp nl
133for k ulong len nq_pcls
134put nq_path add bp k get nq_pcls k
135end
136cls = nq_readhex add bp len nq_pcls
137basecls = shr cls 16
138if ne basecls 3
139ret
140end
141for k ulong len nq_pven
142put nq_path add bp k get nq_pven k
143end
144ven = nq_readhex add bp len nq_pven
145if eq ven 4098
146put nq_cnt 0 add get nq_cnt 0 1
147ret
148end
149if eq ven 32902
150put nq_cnt 1 add get nq_cnt 1 1
151ret
152end
153if eq ven 4318
154put nq_cnt 2 add get nq_cnt 2 1
155end
156end
157
158fn nq_scan_pci to void
159plen = nq_mkpath nq_ppci
160fd = fopen nq_path 0 plen 0 0
161if lt fd 0
162ret
163end
164while true bound 256
165got = getdnts int fd nq_dents 0 16384
166if le got 0
167break
168end
169pos = ulong 0
170while lt pos ulong got bound 1024
171reclen = or ulong get nq_dents add pos 16 shl ulong get nq_dents add pos 17 8
172if eq reclen 0
173break
174end
175ns = add pos 19
176nl = ulong 0
177while lt add ns nl add pos reclen bound 64
178b = get nq_dents add ns nl
179if eq b 0
180break
181end
182put nq_bdf nl b
183nl = add nl 1
184end
185nq_check_bdf nl
186pos = add pos reclen
187end
188end
189r = fclose int fd
190end
191
192fn main to int
193ac = argcnt
194if eq ac 3
195n1 = argread 1 nq_tmp 0 64
196if ne n1 long len nq_froot
197r = write 2 nq_use 0 len nq_use
198ret 2
199end
200for i ulong len nq_froot
201if ne get nq_tmp i get nq_froot i
202r = write 2 nq_use 0 len nq_use
203ret 2
204end
205end
206n2 = argread 2 nq_root 0 2048
207if lt n2 0
208r = write 2 nq_use 0 len nq_use
209ret 2
210end
211put nq_rlen 0 ulong n2
212else
213if ne ac 1
214r = write 2 nq_use 0 len nq_use
215ret 2
216end
217put nq_rlen 0 0
218end
219
220nq_scan_pci
221has_kfd = eq faccess nq_path 0 nq_mkpath nq_pkfd 0 0
222has_dri = eq faccess nq_path 0 nq_mkpath nq_pdri 0 0
223has_ocl = eq faccess nq_path 0 nq_mkpath nq_pocl 0 0
224
225r = write 1 nq_hdr 0 len nq_hdr
226r = write 1 nq_amd 0 len nq_amd
227nq_wnum get nq_cnt 0
228r = write 1 nq_int 0 len nq_int
229nq_wnum get nq_cnt 1
230r = write 1 nq_nv 0 len nq_nv
231nq_wnum get nq_cnt 2
232r = write 1 nq_kfd 0 len nq_kfd
233if has_kfd
234r = write 1 nq_yes 0 len nq_yes
235else
236r = write 1 nq_no 0 len nq_no
237end
238r = write 1 nq_dri 0 len nq_dri
239if has_dri
240r = write 1 nq_yes 0 len nq_yes
241else
242r = write 1 nq_no 0 len nq_no
243end
244r = write 1 nq_ocl 0 len nq_ocl
245if has_ocl
246r = write 1 nq_yes 0 len nq_yes
247else
248r = write 1 nq_no 0 len nq_no
249end
250
251amd_ready = and gt get nq_cnt 0 0 has_kfd
252intel_ready = and gt get nq_cnt 1 0 has_dri
253if or amd_ready intel_ready
254r = write 1 nq_ready 0 len nq_ready
255ret 0
256end
257r = write 1 nq_blk 0 len nq_blk
258ret 3
259end