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/om/arboris_arena.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 / om / arboris_arena.om` 238 lines ยท 6208 bytes Raw Blame History 1 note SPDX-License-Identifier: AGPL-3.0-only 2 note ARBR v1 GraphMeta is 16 little-endian ulong words. Inputs are magic, 3 note soma/branch/synapse counts, padded FP16 dimension, max branches, active 4 note bank, epoch, generation, and parameter payload bytes (word 10). 5 note Outputs are topology bytes (9), single-bank bytes (11), reserved VA 6 note span (12), and conservative CTA scratch bytes (13). Word 14 must be zero. 7 note Word 15 is owned by the sealing layer. Planning neither seals nor maps. 8 om2 9 const arboris_magic ulong 0x4152425200000001 10 const handle_limit ulong 0xffffffff 11 note Matches the QMD builder in om/gpu/bw_qmd.om. 12 const qmd_scratch_limit ulong 98304 13 14 fn aligned_size n ulong alignment ulong limit ulong to ulong 15 if or eq n 0 gt n limit 16 ret 0 17 end 18 padding = and sub ulong 0 n sub alignment 1 19 if gt padding sub limit n 20 ret 0 21 end 22 ret add n padding 23 end 24 25 fn positive_product a ulong b ulong limit ulong to ulong 26 if eq b 0 27 ret 0 28 end 29 if gt a div limit b 30 ret 0 31 end 32 ret mul a b 33 end 34 35 fn valid_counts m view ulong 16 to bool 36 somas = get m 1 37 branches = get m 2 38 if or eq somas 0 gt somas handle_limit 39 ret false 40 end 41 if or eq branches 0 gt branches handle_limit 42 ret false 43 end 44 if gt get m 3 handle_limit 45 ret false 46 end 47 maxbr = get m 5 48 ret and ne maxbr 0 le maxbr branches 49 end 50 51 fn topology_words m view ulong 16 to ulong 52 note Each count is checked against the 32-bit wire field before this sum. 53 ret add add get m 1 2 add mul get m 2 2 get m 3 54 end 55 56 fn cta_scratch m view ulong 16 to ulong 57 note State is FP16, but one stored branch potential has four bytes per coordinate. 58 note Each CTA owns at most 256 coordinates. Grid Y covers the other tiles. 59 tile = get m 4 60 if gt tile 256 61 tile = ulong 256 62 end 63 accum_row = mul tile 4 64 per_soma = positive_product get m 5 accum_row qmd_scratch_limit 65 if le per_soma div qmd_scratch_limit 4 66 ret mul per_soma 4 67 end 68 ret qmd_scratch_limit 69 end 70 71 fn page_layout payload view ulong 6 page ulong budget ulong starts edit ulong 6 to ulong 72 cursor = ulong 0 73 for i ulong 6 74 put starts i cursor 75 extent = aligned_size get payload i page sub budget cursor 76 if eq extent 0 77 ret 0 78 end 79 cursor = add cursor extent 80 if lt i 5 81 if gt page sub budget cursor 82 ret 0 83 end 84 cursor = add cursor page 85 end 86 end 87 ret cursor 88 end 89 90 note Offsets are relative to a page-aligned reservation. Indices 0..5 name 91 note GraphMeta, topology, parameters, ping, pong and receipt. One unmapped 92 note page follows each mapped range except the receipt. Page padding is mapped. 93 note budget bounds the reservation including holes. Every refusal leaves both 94 note outputs unchanged. page must be a supported mapping granule from the mapper. 95 export fn arboris_plan_arena m edit ulong 16 budget ulong page ulong offsets edit ulong 6 to ulong 96 if ne get m 0 arboris_magic 97 ret 1 98 end 99 if or ne get m 14 0 gt get m 6 1 100 ret 2 101 end 102 if not valid_counts m 103 ret 3 104 end 105 dim = get m 4 106 if or eq dim 0 ne and dim 7 0 107 ret 4 108 end 109 if or lt page 4096 ne and page sub page 1 0 110 ret 5 111 end 112 payload = new ulong 6 0 113 starts = new ulong 6 0 114 put payload 0 128 115 put payload 1 aligned_size positive_product topology_words m 4 budget 128 budget 116 put payload 2 get m 10 117 row = positive_product dim 2 budget 118 bank = aligned_size positive_product get m 1 row budget 128 budget 119 put payload 3 bank 120 put payload 4 bank 121 put payload 5 64 122 shared = cta_scratch m 123 if eq shared 0 124 ret 7 125 end 126 cursor = page_layout payload page budget starts 127 if eq cursor 0 128 ret 8 129 end 130 put m 9 get payload 1 131 put m 11 bank 132 put m 12 cursor 133 put m 13 shared 134 for i ulong 6 135 put offsets i get starts i 136 end 137 ret 0 138 end 139 140 fn csr_valid data view uint * start ulong count ulong terminal ulong max_fanout ulong to bool 141 if ne get data start 0 142 ret false 143 end 144 prev = ulong 0 145 for i ulong count bound handle_limit 146 next = ulong get data add start add i 1 147 if or lt next prev gt next terminal 148 ret false 149 end 150 if gt sub next prev max_fanout 151 ret false 152 end 153 prev = next 154 end 155 ret eq prev terminal 156 end 157 158 note data spans the logical topology payload, excluding alignment padding. 159 note Branch metadata interpretation belongs to the model format. 160 export fn arboris_check_csr m view ulong 16 data view uint * to ulong 161 if or ne get m 0 arboris_magic not valid_counts m 162 ret 1 163 end 164 if ne len data topology_words m 165 ret 2 166 end 167 somas = get m 1 168 branches = get m 2 169 synapses = get m 3 170 if not csr_valid data 0 somas branches get m 5 171 ret 3 172 end 173 if not csr_valid data add somas 1 branches synapses synapses 174 ret 4 175 end 176 first = add add somas branches 2 177 for k ulong synapses bound handle_limit 178 if ge ulong get data add first k somas 179 ret 5 180 end 181 end 182 ret 0 183 end 184 185 note ARBS v1 sparse header. Words 1..5 are nodes, batch, directed arcs, 186 note planes per bank (1 compounded, 2 upstream), reserved zero. Epoch, 187 note generation, bank selector and offsets follow the ARBR contract. 188 const arboris_sparse_magic ulong 0x4152425300000001 189 export fn arboris_plan_sparse m edit ulong 16 budget ulong page ulong offsets edit ulong 6 to ulong 190 if or ne get m 0 arboris_sparse_magic ne get m 14 0 191 ret 1 192 end 193 if or gt get m 6 1 ne get m 5 0 194 ret 1 195 end 196 n = get m 1 197 batch = get m 2 198 arcs = get m 3 199 planes = get m 4 200 if or eq n 0 gt n 0x1fffffff 201 ret 2 202 end 203 if or eq batch 0 gt batch 65535 204 ret 2 205 end 206 if or gt arcs 0xffffffff or eq planes 0 gt planes 2 207 ret 2 208 end 209 if or lt page 4096 ne and page sub page 1 0 210 ret 3 211 end 212 extents = new ulong 6 0 213 starts = new ulong 6 0 214 put extents 0 128 215 put extents 1 mul add add n arcs 4 4 216 params = mul arcs 4 217 put extents 2 params 218 if eq params 0 219 put extents 2 4 220 end 221 state = positive_product mul mul n 4 planes batch budget 222 put extents 3 state 223 put extents 4 state 224 put extents 5 64 225 total = page_layout extents page budget starts 226 if eq total 0 227 ret 4 228 end 229 put m 9 get extents 1 230 put m 10 params 231 put m 11 state 232 put m 12 total 233 put m 13 0 234 for i ulong 6 235 put offsets i get starts i 236 end 237 ret 0 238 end