aien-train
AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.
Brought by drakestapleton
aien-train / native / btwave / wave_ipc.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-only |
| 2 | note BTWAVE-P0: Multi-Process Duplex Waveguide IPC on Cortex-X925 (native/btwave/wave_ipc.om). |
| 3 | note Uses raw 80-byte binary/ternary frames over Linux pipefds (zero JSON/Protobuf), |
| 4 | note pinning Node A to Cortex-X925 core 16 and forked Node B to Cortex-X925 core 17 |
| 5 | note via cpuset + cpunow, with monons round-trip telemetry and live Give-Before-Take |
| 6 | note reciprocal ledger settlement. |
| 7 | |
| 8 | const FLEN ulong 80 |
| 9 | |
| 10 | note Telemetry output from ipc_run: |
| 11 | note 0 coreA, 1 coreB, 2 rounds, 3 contrib, 4 extract, 5 odraft_rc, 6 elapsed_ns, 7 chain_lo64 |
| 12 | global IpcOut long 8 |
| 13 | |
| 14 | fn pin_core c ulong to long |
| 15 | requires and lt c 64 and ne c 3 and ne c 7 ne c 15 |
| 16 | m = new uchar 16 0 |
| 17 | bi = shr c 3 |
| 18 | bt = and c 7 |
| 19 | put m bi uchar shl uint 1 uint bt |
| 20 | ret cpuset 0 m 0 16 |
| 21 | end |
| 22 | |
| 23 | fn write_all fd int buf view uchar * n ulong to long |
| 24 | off = ulong 0 |
| 25 | while lt off n bound 1024 |
| 26 | nw = write fd buf off sub n off |
| 27 | if le nw 0 |
| 28 | ret -1 |
| 29 | end |
| 30 | off = add off ulong nw |
| 31 | end |
| 32 | ret 0 |
| 33 | end |
| 34 | |
| 35 | fn read_all fd int buf edit uchar * n ulong to long |
| 36 | off = ulong 0 |
| 37 | while lt off n bound 1024 |
| 38 | nr = read fd buf off sub n off |
| 39 | if le nr 0 |
| 40 | ret -1 |
| 41 | end |
| 42 | off = add off ulong nr |
| 43 | end |
| 44 | ret 0 |
| 45 | end |
| 46 | |
| 47 | fn pack_hdr op uint seq uint to WaveDup |
| 48 | tag = or 0x42540000 or shl and op 0xff 8 and seq 0xff |
| 49 | ret wdup_tag tag |
| 50 | end |
| 51 | |
| 52 | fn unpack_hdr raw ulong op uint seq uint to bool |
| 53 | wd = WaveDupmk raw |
| 54 | tag = or 0x42540000 or shl and op 0xff 8 and seq 0xff |
| 55 | ret wdup_chk wd tag |
| 56 | end |
| 57 | |
| 58 | fn rcpt_chain ch view uchar 32 ep ulong w ulong y long outd edit uchar 32 to void |
| 59 | msg = new uchar 56 0 |
| 60 | for i ulong 32 unroll |
| 61 | put msg i get ch i |
| 62 | end |
| 63 | wr64le msg 32 ep |
| 64 | wr64le msg 40 w |
| 65 | wr64le msg 48 u64_tc y |
| 66 | sha256_slice view msg outd |
| 67 | end |
| 68 | |
| 69 | fn child_give_exec rxw Trit32 sc long reqe ulong bch edit uchar 32 tx edit uchar 80 to long |
| 70 | dg = new uchar 32 0 |
| 71 | d0 = dit 1 |
| 72 | decs = h16dec rxw |
| 73 | if lt decs 0 |
| 74 | d1 = dit int d0 |
| 75 | ret sub -1 mul 0 d1 |
| 76 | end |
| 77 | jw = job_wave ulong decs |
| 78 | yv = wave_eval jw sc |
| 79 | rcpt_chain bch reqe open jw yv dg |
| 80 | for i ulong 32 unroll |
| 81 | put bch i get dg i |
| 82 | put tx add 48 i get dg i |
| 83 | end |
| 84 | wr64le tx 32 open jw |
| 85 | scb = scrub 64 |
| 86 | d2 = dit int d0 |
| 87 | ret add scb mul 0 d2 |
| 88 | end |
| 89 | |
| 90 | fn child_give_round rfd int wfd int seq uint bch edit uchar 32 cn long to int |
| 91 | rx = new uchar 80 0 |
| 92 | tx = new uchar 80 0 |
| 93 | if lt read_all rfd rx FLEN 0 |
| 94 | ret 21 |
| 95 | end |
| 96 | if not unpack_hdr rd64le view rx 0 10 seq |
| 97 | ret 22 |
| 98 | end |
| 99 | reqe = rd64le view rx 8 |
| 100 | wu = rd64le view rx 16 |
| 101 | sc = i64_tc rd64le view rx 24 |
| 102 | rxw = Trit32mk rd64le view rx 32 |
| 103 | if lt child_give_exec rxw sc reqe bch tx 0 |
| 104 | ret 23 |
| 105 | end |
| 106 | hdr = pack_hdr 1 seq |
| 107 | wr64le tx 0 open hdr |
| 108 | wr64le tx 8 reqe |
| 109 | wr64le tx 16 wu |
| 110 | wr64le tx 24 u64_tc sc |
| 111 | wr64le tx 40 u64_tc cn |
| 112 | if lt write_all wfd view tx FLEN 0 |
| 113 | ret 24 |
| 114 | end |
| 115 | if lt read_all rfd rx FLEN 0 |
| 116 | ret 25 |
| 117 | end |
| 118 | if not unpack_hdr rd64le view rx 0 20 seq |
| 119 | ret 26 |
| 120 | end |
| 121 | if ne i64_tc rd64le view rx 40 0 |
| 122 | ret 27 |
| 123 | end |
| 124 | ret 0 |
| 125 | end |
| 126 | |
| 127 | fn child_take_round rfd int wfd int seq uint ep ulong tu ulong bch edit uchar 32 to long |
| 128 | rx = new uchar 80 0 |
| 129 | tx = new uchar 80 0 |
| 130 | sym = add 9 and ulong seq 7 |
| 131 | jw = job_wave sym |
| 132 | hdr = pack_hdr 2 seq |
| 133 | wr64le tx 0 open hdr |
| 134 | wr64le tx 8 ep |
| 135 | wr64le tx 16 tu |
| 136 | wr64le tx 24 u64_tc 2 |
| 137 | wr64le tx 32 open jw |
| 138 | wr64le tx 40 sym |
| 139 | for i ulong 32 unroll |
| 140 | put tx add 48 i get bch i |
| 141 | end |
| 142 | if lt write_all wfd view tx FLEN 0 |
| 143 | ret -99 |
| 144 | end |
| 145 | if lt read_all rfd rx FLEN 0 |
| 146 | ret -98 |
| 147 | end |
| 148 | if not unpack_hdr rd64le view rx 0 20 seq |
| 149 | ret -97 |
| 150 | end |
| 151 | st = i64_tc rd64le view rx 40 |
| 152 | if eq st 0 |
| 153 | for i ulong 32 unroll |
| 154 | put bch i get rx add 48 i |
| 155 | end |
| 156 | end |
| 157 | ret st |
| 158 | end |
| 159 | |
| 160 | fn ipc_node_b rfd int wfd int to void |
| 161 | bch = new uchar 32 0 |
| 162 | if lt pin_core 17 0 |
| 163 | exit 30 |
| 164 | end |
| 165 | cn = cpunow |
| 166 | if ne cn 17 |
| 167 | exit 31 |
| 168 | end |
| 169 | for k ulong 4 |
| 170 | rc = child_give_round rfd wfd uint k bch cn |
| 171 | if ne rc 0 |
| 172 | exit rc |
| 173 | end |
| 174 | end |
| 175 | od = child_take_round rfd wfd 4 5 300 bch |
| 176 | if ne od -10 |
| 177 | exit 32 |
| 178 | end |
| 179 | for k ulong 3 |
| 180 | tk = child_take_round rfd wfd uint add 5 k add 5 k 60 bch |
| 181 | if ne tk 0 |
| 182 | exit 33 |
| 183 | end |
| 184 | end |
| 185 | x1 = fclose rfd |
| 186 | x2 = fclose wfd |
| 187 | exit 0 |
| 188 | end |
| 189 | |
| 190 | fn rx_rcpt_ok rx view uchar 80 expd view uchar 32 to bool |
| 191 | rxd = new uchar 32 0 |
| 192 | for i ulong 32 unroll |
| 193 | put rxd i get rx add 48 i |
| 194 | end |
| 195 | ret rcpt_eq expd rxd |
| 196 | end |
| 197 | |
| 198 | fn host_give_round wfd int rfd int seq uint sym ulong to long |
| 199 | tx = new uchar 80 0 |
| 200 | rx = new uchar 80 0 |
| 201 | expd = new uchar 32 0 |
| 202 | noisy = t32flip t32flip h16enc sym 2 11 |
| 203 | reqe = add get Lstate 0 1 |
| 204 | wr64le tx 0 open pack_hdr 10 seq |
| 205 | wr64le tx 8 reqe |
| 206 | wr64le tx 16 60 |
| 207 | wr64le tx 24 u64_tc 3 |
| 208 | wr64le tx 32 open noisy |
| 209 | wr64le tx 40 0 |
| 210 | if lt write_all wfd view tx FLEN 0 |
| 211 | ret -41 |
| 212 | end |
| 213 | if lt read_all rfd rx FLEN 0 |
| 214 | ret -42 |
| 215 | end |
| 216 | if not unpack_hdr rd64le view rx 0 1 seq |
| 217 | ret -43 |
| 218 | end |
| 219 | rw = rd64le view rx 32 |
| 220 | if ne rw open job_wave sym |
| 221 | ret -46 |
| 222 | end |
| 223 | jw = Trit32mk rw |
| 224 | yv = wave_eval jw 3 |
| 225 | ldg_rcpt reqe open jw yv expd |
| 226 | if not rx_rcpt_ok rx expd |
| 227 | ret -44 |
| 228 | end |
| 229 | ldg_commit_give reqe 60 yv expd |
| 230 | wr64le tx 0 open pack_hdr 20 seq |
| 231 | wr64le tx 40 u64_tc 0 |
| 232 | if lt write_all wfd view tx FLEN 0 |
| 233 | ret -45 |
| 234 | end |
| 235 | ret i64_tc rd64le view rx 40 |
| 236 | end |
| 237 | |
| 238 | fn host_take_round wfd int rfd int seq uint to long |
| 239 | rx = new uchar 80 0 |
| 240 | tx = new uchar 80 0 |
| 241 | ev = new long 7 0 |
| 242 | if lt read_all rfd rx FLEN 0 |
| 243 | ret -51 |
| 244 | end |
| 245 | if not unpack_hdr rd64le view rx 0 2 seq |
| 246 | ret -52 |
| 247 | end |
| 248 | reqe = rd64le view rx 8 |
| 249 | tu = rd64le view rx 16 |
| 250 | sc = i64_tc rd64le view rx 24 |
| 251 | sym = rd64le view rx 40 |
| 252 | anc = rd64le view rx 48 |
| 253 | put ev 0 2 |
| 254 | put ev 1 long reqe |
| 255 | put ev 2 0 |
| 256 | put ev 3 long tu |
| 257 | put ev 4 sc |
| 258 | put ev 5 long sym |
| 259 | put ev 6 0 |
| 260 | if ne anc ldg_chid |
| 261 | put ev 6 5 |
| 262 | end |
| 263 | st = ldg_step ev |
| 264 | ack = pack_hdr 20 seq |
| 265 | wr64le tx 0 open ack |
| 266 | wr64le tx 40 u64_tc st |
| 267 | for i ulong 32 unroll |
| 268 | put tx add 48 i get Lchain i |
| 269 | end |
| 270 | if lt write_all wfd view tx FLEN 0 |
| 271 | ret -53 |
| 272 | end |
| 273 | ret st |
| 274 | end |
| 275 | |
| 276 | fn ipc_spawn p2c view uchar 8 c2p view uchar 8 to long |
| 277 | ar = int rd32le p2c 0 |
| 278 | aw = int rd32le p2c 4 |
| 279 | br = int rd32le c2p 0 |
| 280 | bw = int rd32le c2p 4 |
| 281 | pid = fork |
| 282 | if lt pid 0 |
| 283 | ret -60 |
| 284 | end |
| 285 | if eq pid 0 |
| 286 | x1 = fclose aw |
| 287 | x2 = fclose br |
| 288 | ipc_node_b ar bw |
| 289 | end |
| 290 | x3 = fclose ar |
| 291 | x4 = fclose bw |
| 292 | ret pid |
| 293 | end |
| 294 | |
| 295 | fn ipc_host_rounds aw int br int res edit long 2 to int |
| 296 | cnb = long -1 |
| 297 | for k ulong 4 |
| 298 | cnb = host_give_round aw br uint k add mul k 5 1 |
| 299 | if lt cnb 0 |
| 300 | ret 65 |
| 301 | end |
| 302 | end |
| 303 | od = host_take_round aw br 4 |
| 304 | if ne od -10 |
| 305 | ret 66 |
| 306 | end |
| 307 | for k ulong 3 |
| 308 | tk = host_take_round aw br uint add 5 k |
| 309 | if ne tk 0 |
| 310 | ret 67 |
| 311 | end |
| 312 | end |
| 313 | note Pipe ends aw and br are closed by ipc_run on every path, so a refusal above |
| 314 | note gives node B end-of-file instead of leaving both processes blocked. |
| 315 | put res 0 cnb |
| 316 | put res 1 od |
| 317 | ret 0 |
| 318 | end |
| 319 | |
| 320 | note Close the host pipe ends (p2c write, c2p read) so node B sees end-of-file. |
| 321 | fn ipc_shut p2c view uchar 8 c2p view uchar 8 to void |
| 322 | xa = fclose int rd32le p2c 4 |
| 323 | xb = fclose int rd32le c2p 0 |
| 324 | end |
| 325 | |
| 326 | fn ipc_run to int |
| 327 | p2c = new uchar 8 0 |
| 328 | c2p = new uchar 8 0 |
| 329 | wst = new uchar 4 0 |
| 330 | res = new long 2 0 |
| 331 | if lt pipefds p2c 0 8 0 0 |
| 332 | ret 61 |
| 333 | end |
| 334 | if lt pipefds c2p 0 8 0 0 |
| 335 | ret 62 |
| 336 | end |
| 337 | ldg_reset |
| 338 | t0 = monons |
| 339 | pid = ipc_spawn p2c c2p |
| 340 | if lt pid 0 |
| 341 | ret 63 |
| 342 | end |
| 343 | if lt pin_core 16 0 |
| 344 | ret 64 |
| 345 | end |
| 346 | cna = cpunow |
| 347 | rrc = ipc_host_rounds int rd32le p2c 4 int rd32le c2p 0 res |
| 348 | ipc_shut p2c c2p |
| 349 | wp = waitpid int pid wst 0 4 0 |
| 350 | t1 = monons |
| 351 | if ne rrc 0 |
| 352 | ret rrc |
| 353 | end |
| 354 | st = rd32le view wst 0 |
| 355 | if or lt wp 0 ne st 0 |
| 356 | ret 68 |
| 357 | end |
| 358 | if or ne cna 16 ne get res 0 17 |
| 359 | ret 69 |
| 360 | end |
| 361 | put IpcOut 0 cna |
| 362 | put IpcOut 1 get res 0 |
| 363 | put IpcOut 2 8 |
| 364 | put IpcOut 3 long get Lstate 1 |
| 365 | put IpcOut 4 long get Lstate 2 |
| 366 | put IpcOut 5 get res 1 |
| 367 | put IpcOut 6 sub t1 t0 |
| 368 | put IpcOut 7 i64_tc ldg_chid |
| 369 | ret 0 |
| 370 | end |