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/CUDApp/blob/main/om/session/reserve.om # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / om / session / reserve.om` 158 lines · 2663 bytes Raw Blame History 1 om2 2 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 3 note Residual omega_gpu_mem_reserve.c parsing, C-locale strtoull and sscanf contracts. 4 note The C shell borrows the getenv/fgets bytes; this unit neither copies them nor allocates. 5 note Optional sign, C whitespace, decimal prefix, overflow saturation even for a negative input. 6 note Environment values require full consumption; MemAvailable only requires a conversion. 7 note Chunked loops cover Linux argument limits without a new 512-byte parser ceiling. 8 note op 0: environment MiB (empty/invalid -> 4096), op 1: MemAvailable line (1 and out0 kB, else 0). 9 note op 2: saturating MiB-to-byte conversion of value; b is unused. out1 is the numeric end offset. 10 11 fn rs_white c uchar to bool 12 ret or eq c 32 and ge c 9 le c 13 13 end 14 15 fn rs_skip b view uchar * pos ulong to ulong 16 i = pos 17 while lt i len b bound 999999 18 for j ulong 256 19 if ge i len b 20 ret i 21 end 22 if not rs_white get b i 23 ret i 24 end 25 i = add i 1 26 end 27 end 28 ret i 29 end 30 31 fn rs_push dst edit ulong 2 c uchar to void 32 v = get dst 0 33 d = ulong sub c 48 34 if gt v div sub ulong `18446744073709551615` d 10 35 put dst 1 1 36 end 37 if eq get dst 1 0 38 put dst 0 add mul v 10 d 39 end 40 end 41 42 fn rs_number b view uchar * pos ulong dst edit ulong 2 to bool 43 i = rs_skip b pos 44 minus = false 45 if lt i len b 46 if or eq get b i 43 eq get b i 45 47 minus = eq get b i 45 48 i = add i 1 49 end 50 end 51 start = i 52 put dst 0 0 53 put dst 1 0 54 done = false 55 while lt i len b bound 999999 56 for j ulong 256 57 if ge i len b 58 done = true 59 break 60 end 61 c = get b i 62 if or lt c 48 gt c 57 63 done = true 64 break 65 end 66 rs_push dst c 67 i = add i 1 68 end 69 if done 70 break 71 end 72 end 73 if eq i start 74 ret false 75 end 76 if eq get dst 1 0 77 if minus 78 put dst 0 sub ulong 0 get dst 0 79 end 80 else 81 put dst 0 `18446744073709551615` 82 end 83 put dst 1 i 84 ret true 85 end 86 87 fn rs_prefix b view uchar * to bool 88 if lt len b 13 89 ret false 90 end 91 note The exact literal prefix is MemAvailable: (from the retained sscanf format). 92 if ne get b 0 77 93 ret false 94 end 95 if ne get b 1 101 96 ret false 97 end 98 if ne get b 2 109 99 ret false 100 end 101 if ne get b 3 65 102 ret false 103 end 104 if ne get b 4 118 105 ret false 106 end 107 if ne get b 5 97 108 ret false 109 end 110 if ne get b 6 105 111 ret false 112 end 113 if ne get b 7 108 114 ret false 115 end 116 if ne get b 8 97 117 ret false 118 end 119 if ne get b 9 98 120 ret false 121 end 122 if ne get b 10 108 123 ret false 124 end 125 if ne get b 11 101 126 ret false 127 end 128 ret eq get b 12 58 129 end 130 131 fn memreserve op ulong b view uchar * value ulong dst edit ulong 2 to ulong 132 if eq op 2 133 if gt value `17592186044415` 134 ret `18446744073709551615` 135 end 136 ret shl value 20 137 end 138 if eq op 0 139 if eq len b 0 140 ret 4096 141 end 142 if rs_number b 0 dst 143 if eq get dst 1 len b 144 ret get dst 0 145 end 146 end 147 ret 4096 148 end 149 if eq op 1 150 if rs_prefix b 151 if rs_number b 13 dst 152 ret 1 153 end 154 end 155 ret 0 156 end 157 ret 0 158 end