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