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 / nvidia / driver / m16.om

172 lines · 4914 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note gpu/nvidia/driver/m16.om: the M16 checks that were still C in CUDApp m16/ (84b524ca).
3note m16_requalify.c check_proc_maps, m16_gpu_wait.c m16_gpu_wait_result_name and m16_gpu_wait_kind_name, and
4note m16_native.c m16_native_wait_marker_ge. The rest of the M16 decisions are in gpu/nvidia/om/engine/eng.om.
5note Needs OM-2 (unsized views): compose after an om2 part; gpu/nvidia/driver/parts.txt lists the order.
6
7text drv_m16t "libcuda.so|libcudart.so|PASS|TIMEOUT|STALLED|INVALID_STATE|ABORTED|UNKNOWN|fixed|sequence|unknown|"
8
9note piece w of drv_m16t starts at byte r[0] and has r[1] bytes; past the last piece it is empty
10fn drv_m16p w ulong r edit ulong 2 to void
11k = ulong 0
12i = ulong 0
13while and lt k w lt i len drv_m16t bound 9223372036854775807
14if eq get drv_m16t i 124
15k = add k 1
16end
17i = add i 1
18end
19put r 0 i
20put r 1 0
21if ge i len drv_m16t
22ret
23end
24while ne get drv_m16t i 124 bound 9223372036854775807
25i = add i 1
26end
27put r 1 sub i get r 0
28end
29
30note piece w of drv_m16t occurs in f at byte s
31fn drv_m16at f view uchar * s ulong w ulong to bool
32r = new ulong 2 0
33drv_m16p w r
34if gt add s get r 1 len f
35ret false
36end
37for i ulong get r 1 bound 9223372036854775807
38if ne get f add s i get drv_m16t add get r 0 i
39ret false
40end
41end
42ret true
43end
44
45note check_proc_maps: 1 when a line of the process map f (the bytes of /proc/self/maps) holds libcuda.so or
46note libcudart.so, else 0. As in the C, a NUL ends the part of a line that is searched. Lines are searched
47note whole; the C reads them in 511-byte pieces.
48fn drv_maps f view uchar * to ulong
49live = true
50for i ulong len f bound 9223372036854775807
51c = get f i
52if eq c 10
53live = true
54continue
55end
56if eq c 0
57live = false
58continue
59end
60if live
61if or drv_m16at f i 0 drv_m16at f i 1
62ret 1
63end
64end
65end
66ret 0
67end
68
69note m16_gpu_wait_result_name: the name of result r into r2 (piece start, length)
70fn drv_wres r long o edit ulong 2 to void
71w = ulong 7
72if and ge r 0 le r 4
73w = add ulong r 2
74end
75drv_m16p w o
76end
77
78note m16_gpu_wait_kind_name: 1 fixed, 2 sequence, any other kind unknown
79fn drv_wkind k long o edit ulong 2 to void
80w = ulong 10
81if eq k 1
82w = ulong 8
83end
84if eq k 2
85w = ulong 9
86end
87drv_m16p w o
88end
89
90note marker has reached target: (int32_t)(marker - target) >= 0 on the low 32 bits
91fn drv_reached marker ulong target ulong to bool
92ret eq and sub marker target 2147483648 0
93end
94
95note timeout_ms * 1000000 in nanoseconds, or 2^64 - 1 when that overflows (the C then never reads the clock
96note for the deadline). 2^64 - 1 is not a multiple of 1000000, so it never stands for a real duration.
97fn drv_wdur timeout ulong to ulong
98if gt timeout 18446744073709
99ret 18446744073709551615
100end
101ret mul timeout 1000000
102end
103
104note deadline now + dur, saturating at 2^64 - 1
105fn drv_wend now ulong dur ulong to ulong
106e = add now dur
107if lt e now
108ret 18446744073709551615
109end
110ret e
111end
112
113note One look of m16_native_wait_marker_ge: inloop tells whether the clock read before this look was still
114note before the deadline. 0: the u32 marker reached target, return 0; 1: not yet, sleep and look again;
115note 2: the look after the deadline failed, return -1. Both drv_wait_ge and gate.om hwge call it.
116fn drv_wstep inloop bool mk ulong tg ulong to ulong
117if drv_reached mk tg
118ret 0
119end
120if inloop
121ret 1
122end
123ret 2
124end
125
126note m16_native_wait_marker_ge on a mapped marker: handle h, byte offset off (4-aligned). 0 when the u32
127note marker reached target before the deadline or at the last look after it, -1 otherwise. A device path:
128note its hardware tier is NOT_RUN. gate.om runs drv_wdur, drv_wend and drv_wstep on a scripted clock; the
129note clock reads, the marker read and the sleep below are not run by any gate.
130fn drv_wait_ge h long off ulong target ulong timeout ulong to long
131dur = drv_wdur timeout
132endt = ulong 18446744073709551615
133if ne dur 18446744073709551615
134endt = drv_wend ulong monons dur
135end
136st = ulong 1
137while eq st 1 bound 9223372036854775807
138st = drv_wstep lt ulong monons endt mapget h off 4 target
139if eq st 1
140s = sleepns 50000
141end
142end
143if eq st 0
144ret 0
145end
146ret -1
147end
148
149note m16_native_enqueue_methods: count method words fit the pushbuffer of pbsize bytes and the u32 word count
150note nvrm_enqueue takes (0 < count <= 2^32 - 1 and count <= pbsize / 4). The copy and the enqueue stay with the
151note device shell.
152fn drv_enqok count ulong pbsize ulong to bool
153if eq count 0
154ret false
155end
156if gt count 4294967295
157ret false
158end
159ret le count div pbsize 4
160end
161
162note m16_native_alloc_memory: the first legacy slot whose handle is 0, or len hs when every slot is taken
163note (the C then returns -1). If nvrm_alloc then fails, the C returns -1 without trying a later slot;
164note nvrm_alloc writes the handle only on success, so that slot stays 0 and the next call picks it again.
165fn drv_slot hs view uint * to ulong
166for i ulong len hs bound 9223372036854775807
167if eq get hs i 0
168ret i
169end
170end
171ret len hs
172end