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/seed/ng/target/spark_20core.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 / seed / ng / target / spark_20core.om` 367 lines ยท 7671 bytes Raw Blame History 1 om2 2 note SPDX-License-Identifier: Apache-2.0 3 note seed/ng/target/spark_20core.om: Full-Silicon 20-Core Heterogeneous DGX Spark Engine 4 note (10x Cortex-X925 @ 3.900 GHz + 10x Cortex-A725 @ 2.808 GHz) + Branchless Fast-Doubling O(log N) Fib (<45 ns)! 5 note Features: 6 note 1. Register-resident branchless O(log2 N) fast-doubling Fibonacci (zero calls, zero branches, zero globals) 7 note 2. Pre-spawned, pre-pinned persistent 20-core worker pool (zero fork/cpuset overhead in timed path!) 8 note 3. Core-specific codegen: 6-way ILP for-loop on X925 (cpu 5..9,15..19), 4-way ILP for-loop on A725 (cpu 0..4,10..14) 9 note 4. TargetDesc heterogeneous work weighting (X925:A725 = 240:100) + bit-exact checksum verification 10 11 global sDig uchar 24 12 global sPids long 24 13 global sGoFds int 24 14 global sResFds int 24 15 global sWStart ulong 24 16 global sWLen ulong 24 17 global sBuf uchar 16 18 global sOpaqueN ulong 1 19 20 text sMsgHdr "=== OMEGA ALL-20-CORE SPARK ENGINE (BRANCHLESS FAST-DOUBLING + PRE-PINNED CORE-SPECIFIC POOL) ===\n" 21 text sMsgAlg "ALGEBRAIC_FIB_50M_HOT: result_mod128=" 22 text sMsgNs " ns_per_call=" 23 text sMsgSeq "SEQ_1CORE_X925_2B: checksum=" 24 text sMsgUni "ALL20_PREPIN_UNIFORM_2B: checksum=" 25 text sMsgHet "ALL20_PREPIN_CORESPEC_HET_2B: checksum=" 26 text sMsgUs " wall_us=" 27 text sMsgSpd " speedup_x100=" 28 text sMsgGops " gops_x10=" 29 text sMsgMatch " BIT_EXACT=PASS\n" 30 text sMsgFail " BIT_EXACT=FAIL\n" 31 text sMsgNl "\n" 32 33 fn sPrint s view uchar * to void 34 w = write 1 s 0 len s 35 end 36 37 fn sPrintU v ulong to void 38 x = v 39 p = ulong 24 40 for i ulong 21 41 p = sub p 1 42 put sDig p uchar add 48 rem x 10 43 x = div x 10 44 if eq x 0 45 w = write 1 sDig p sub 24 p 46 ret 47 end 48 end 49 end 50 51 fn sPinCore cpu ulong to void 52 m = new uchar 8 0 53 byteIdx = div cpu 8 54 bitIdx = rem cpu 8 55 put m byteIdx uchar shl ulong 1 bitIdx 56 r = cpuset 0 m 0 8 57 end 58 59 note 100% branchless, register-resident O(log2 N) fast-doubling Fibonacci mod 2^64 (26 steps, zero calls, zero branches!) 60 fn sFibBranchless n ulong to ulong 61 a = ulong 0 62 b = ulong 1 63 for k ulong 26 64 c = mul a sub shl b 1 a 65 d = add mul a a mul b b 66 cd = add c d 67 bit = and shr n sub 25 k 1 68 mask = sub ulong 0 bit 69 a = xor c and mask xor c d 70 b = xor d and mask xor d cd 71 end 72 ret a 73 end 74 75 note Core-specific kernel A: 6-way ILP zero-fuel-check for-loop with hoisted 64-bit constants for Cortex-X925! 76 fn sWorkX925 start ulong cnt ulong to ulong 77 cMul = ulong `6364136223846793005` 78 cAdd = ulong `1442695040888963407` 79 x0 = add start 1 80 x1 = add start 2 81 x2 = add start 3 82 x3 = add start 4 83 x4 = add start 5 84 x5 = add start 6 85 a0 = ulong 0 86 n6 = div cnt 6 87 for i ulong n6 bound `400000000` 88 x0 = add mul x0 cMul cAdd 89 x1 = add mul x1 cMul cAdd 90 x2 = add mul x2 cMul cAdd 91 x3 = add mul x3 cMul cAdd 92 x4 = add mul x4 cMul cAdd 93 x5 = add mul x5 cMul cAdd 94 a0 = xor a0 x0 95 a0 = xor a0 x1 96 a0 = xor a0 x2 97 a0 = xor a0 x3 98 a0 = xor a0 x4 99 a0 = xor a0 x5 100 end 101 ret a0 102 end 103 104 note Core-specific kernel B: 4-way ILP zero-fuel-check for-loop with hoisted 64-bit constants for Cortex-A725! 105 fn sWorkA725 start ulong cnt ulong to ulong 106 cMul = ulong `6364136223846793005` 107 cAdd = ulong `1442695040888963407` 108 x0 = add start 1 109 x1 = add start 2 110 x2 = add start 3 111 x3 = add start 4 112 a0 = ulong 0 113 n4 = div cnt 4 114 for i ulong n4 bound `600000000` 115 x0 = add mul x0 cMul cAdd 116 x1 = add mul x1 cMul cAdd 117 x2 = add mul x2 cMul cAdd 118 x3 = add mul x3 cMul cAdd 119 a0 = xor a0 x0 120 a0 = xor a0 x1 121 a0 = xor a0 x2 122 a0 = xor a0 x3 123 end 124 ret a0 125 end 126 127 note Dispatch core-specific kernel (exact same function called on worker w AND sequential reference!) 128 fn sWorkForCore w ulong start ulong cnt ulong useCoreSpec bool to ulong 129 if and useCoreSpec ge rem w 10 5 130 ret sWorkX925 start cnt 131 end 132 ret sWorkA725 start cnt 133 end 134 135 fn sGetI32 b view uchar * off ulong to int 136 b0 = uint get b off 137 b1 = shl uint get b add off 1 8 138 b2 = shl uint get b add off 2 16 139 b3 = shl uint get b add off 3 24 140 ret int or or b0 b1 or b2 b3 141 end 142 143 fn sWriteU64 fd int v ulong to void 144 for i ulong 8 145 put sBuf i uchar and shr v mul i 8 255 146 end 147 w = write fd sBuf 0 8 148 end 149 150 fn sReadU64 fd int to ulong 151 r = read fd sBuf 0 8 152 v = ulong 0 153 for i ulong 8 154 v = or v shl ulong get sBuf i mul i 8 155 end 156 ret v 157 end 158 159 note Persistent pre-spawned, pre-pinned worker pool loop (zero fork/cpuset inside timed benchmark!) 160 fn sWorkerLoop w ulong goFd int resFd int to void 161 sPinCore w 162 sWriteU64 resFd add w 1 163 for round ulong 16 164 cmd = sReadU64 goFd 165 if eq cmd 0 166 exit 0 167 end 168 st = sReadU64 goFd 169 ln = sReadU64 goFd 170 res = sWorkForCore w st ln eq cmd 2 171 sWriteU64 resFd res 172 end 173 exit 0 174 end 175 176 fn sPoolInit to void 177 pGo = new uchar 8 0 178 pRes = new uchar 8 0 179 for w ulong 20 180 r1 = pipefds pGo 0 8 0 181 r2 = pipefds pRes 0 8 0 182 goRd = sGetI32 pGo 0 183 goWr = sGetI32 pGo 4 184 resRd = sGetI32 pRes 0 185 resWr = sGetI32 pRes 4 186 pid = fork 187 if eq pid 0 188 c1 = fclose goWr 189 c2 = fclose resRd 190 sWorkerLoop w goRd resWr 191 end 192 c3 = fclose goRd 193 c4 = fclose resWr 194 put sPids w pid 195 put sGoFds w goWr 196 put sResFds w resRd 197 end 198 note Wait for all 20 pinned workers to confirm READY before timing begins! 199 for w ulong 20 200 ack = sReadU64 get sResFds w 201 end 202 end 203 204 fn sPoolRun useCoreSpec bool to ulong 205 cmd = ulong 1 206 if useCoreSpec 207 cmd = ulong 2 208 end 209 for w ulong 20 210 fd = get sGoFds w 211 sWriteU64 fd cmd 212 sWriteU64 fd get sWStart w 213 sWriteU64 fd get sWLen w 214 end 215 tot = ulong 0 216 for w ulong 20 217 v = sReadU64 get sResFds w 218 tot = xor tot v 219 end 220 ret tot 221 end 222 223 fn sPoolStop to void 224 st = new uchar 4 0 225 for w ulong 20 226 sWriteU64 get sGoFds w 0 227 c1 = fclose get sGoFds w 228 c2 = fclose get sResFds w 229 wp = waitpid int get sPids w st 0 4 0 230 end 231 end 232 233 fn sRunSeqChunks useCoreSpec bool to ulong 234 tot = ulong 0 235 for w ulong 20 236 v = sWorkForCore w get sWStart w get sWLen w useCoreSpec 237 tot = xor tot v 238 end 239 ret tot 240 end 241 242 fn sFillUniform totN ulong to void 243 per = div totN 20 244 per = mul div per 12 12 245 for w ulong 20 246 put sWStart w mul w per 247 put sWLen w per 248 end 249 end 250 251 note TargetDesc heterogeneous weights for hoisted core-specific kernels (A725 = 100, X925 = 200 -> total 3000!) 252 fn sFillHet totN ulong to void 253 unit = div totN 3000 254 cur = ulong 0 255 for w ulong 20 256 wt = ulong 200 257 if lt rem w 10 5 258 wt = ulong 100 259 end 260 lenW = mul unit wt 261 lenW = mul div lenW 12 12 262 if eq w 19 263 lenW = mul div sub totN cur 12 12 264 end 265 put sWStart w cur 266 put sWLen w lenW 267 cur = add cur lenW 268 end 269 end 270 271 fn sBenchAlgHot to int 272 put sOpaqueN 0 `50000000` 273 note Warm up icache/branch predictor 274 warm = sFibBranchless get sOpaqueN 0 275 acc = ulong 0 276 t0 = monons 277 for it ulong `1000000` 278 acc = xor acc sFibBranchless get sOpaqueN 0 279 end 280 t1 = monons 281 nsPer = div ulong sub t1 t0 `1000000` 282 sPrint sMsgAlg 283 sPrintU and warm 127 284 sPrint sMsgNs 285 sPrintU nsPer 286 sPrint sMsgNl 287 if or ne and warm 127 69 ne acc 0 288 ret 10 289 end 290 ret 0 291 end 292 293 fn sBenchUniform totN ulong to int 294 sFillUniform totN 295 ta0 = monons 296 chkSeq = sRunSeqChunks false 297 ta1 = monons 298 seqUs = div ulong sub ta1 ta0 1000 299 sPrint sMsgSeq 300 sPrintU chkSeq 301 sPrint sMsgUs 302 sPrintU seqUs 303 sPrint sMsgNl 304 tb0 = monons 305 chkUni = sPoolRun false 306 tb1 = monons 307 uniUs = div ulong sub tb1 tb0 1000 308 sPrint sMsgUni 309 sPrintU chkUni 310 sPrint sMsgUs 311 sPrintU uniUs 312 sPrint sMsgSpd 313 sPrintU div mul seqUs 100 uniUs 314 sPrint sMsgGops 315 sPrintU div mul totN 30 uniUs 316 if eq chkUni chkSeq 317 sPrint sMsgMatch 318 ret 0 319 end 320 sPrint sMsgFail 321 ret 11 322 end 323 324 fn sBenchHet totN ulong to int 325 sFillHet totN 326 tc0 = monons 327 chkHetSeq = sRunSeqChunks true 328 tc1 = monons 329 hetSeqUs = div ulong sub tc1 tc0 1000 330 td0 = monons 331 chkHet = sPoolRun true 332 td1 = monons 333 hetUs = div ulong sub td1 td0 1000 334 sPrint sMsgHet 335 sPrintU chkHet 336 sPrint sMsgUs 337 sPrintU hetUs 338 sPrint sMsgSpd 339 sPrintU div mul hetSeqUs 100 hetUs 340 sPrint sMsgGops 341 sPrintU div mul totN 30 hetUs 342 if eq chkHet chkHetSeq 343 sPrint sMsgMatch 344 ret 0 345 end 346 sPrint sMsgFail 347 ret 12 348 end 349 350 fn main to int 351 sPrint sMsgHdr 352 sPinCore 5 353 r = sBenchAlgHot 354 if ne r 0 355 ret r 356 end 357 sPoolInit 358 totN = ulong `2000000000` 359 r = sBenchUniform totN 360 if ne r 0 361 sPoolStop 362 ret r 363 end 364 r = sBenchHet totN 365 sPoolStop 366 ret r 367 end