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/gpu/encrun.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 / gpu / encrun.om` 159 lines ยท 3769 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note seed/ng/gpu/encrun.om: conformance harness for the sm_121 encoder ng consumes (Hive NG lane ng-gpu, D10). 3 note Not an encoder: it composes AFTER gpu/nvidia/om/encoder/bw_enc_sm121.om (the sha in seed/ng/cudapp.lock): 4 note cat gpu/nvidia/om/encoder/bw_enc_sm121.om seed/ng/gpu/encrun.om | seed/out/omc > encrun 5 note Program mode, AArch64 Linux. stdin is a stream of NGBWENC1 frames, stdout one result frame per input frame. 6 note Input frame (every word a 64-bit little-endian unsigned): 7 note 8 bytes "NGBWENC1" | n | pad | 288 words phys | n*8 words ins (none when n > 1024) 8 note phys and ins are exactly the arrays bw_enc_sm121 takes (see its header): 8 words per solved BlackwellIR 9 note instruction, vreg 0..255 then uvreg 256..287 physical registers. ins words past n*8 are zero, as the 10 note CUDApp C caller zeroes them. pad 1: NOP-pad to a multiple of 8, at least 32 instructions. 11 note Output frame: one word r (the bytes encoded; 0 = refused) then the r code bytes. 12 note Exit: 0 after a whole number of frames; 2 bad magic; 3 truncated frame; 4 read error; 5 write error, 13 note each with one stderr line. Output written before an error stays written. 14 15 text g_emag "NGBWENC1" 16 text g_em2 "encrun: bad frame magic\n" 17 text g_em3 "encrun: truncated frame\n" 18 text g_em4 "encrun: read error\n" 19 text g_em5 "encrun: write error\n" 20 21 fn gp_efail c ulong to int 22 if eq c 2 23 k = write 2 g_em2 0 len g_em2 24 end 25 if eq c 3 26 k = write 2 g_em3 0 len g_em3 27 end 28 if eq c 4 29 k = write 2 g_em4 0 len g_em4 30 end 31 if eq c 5 32 k = write 2 g_em5 0 len g_em5 33 end 34 ret int c 35 end 36 37 note exactly n bytes of stdin into b from 0: n, fewer only at the end of input, -1 on a read error 38 fn gp_eread b edit uchar 65536 n ulong to long 39 got = ulong 0 40 note every pass consumes at least one byte of at most 65536 41 while lt got n bound 65537 42 k = read 0 b got sub n got 43 if lt k 0 44 ret -1 45 end 46 if eq k 0 47 ret long got 48 end 49 got = add got ulong k 50 end 51 ret long got 52 end 53 54 note all n bytes of b to stdout: 0, or 1 on a write error or a zero-length write 55 fn gp_ewrite b view uchar 16392 n ulong to ulong 56 wr = ulong 0 57 while lt wr n bound 16393 58 k = write 1 b wr sub n wr 59 if le k 0 60 ret 1 61 end 62 wr = add wr ulong k 63 end 64 ret 0 65 end 66 67 fn gp_ele b view uchar 65536 off ulong to ulong 68 w = ulong 0 69 for i ulong 8 70 w = or w shl ulong get b add off i mul i 8 71 end 72 ret w 73 end 74 75 note one frame body after the 24 header bytes into phys and ins; gives 0, or the exit code 76 fn gp_eframe ib edit uchar 65536 n ulong ins edit ulong 8192 phys edit ulong 288 to ulong 77 k = gp_eread ib 2304 78 if lt k 0 79 ret 4 80 end 81 if ne k 2304 82 ret 3 83 end 84 for i ulong 288 85 put phys i gp_ele ib mul i 8 86 end 87 for i ulong 8192 88 put ins i 0 89 end 90 rows = n 91 if gt n 1024 92 rows = 0 93 end 94 if gt rows 0 95 nb = mul rows 64 96 k = gp_eread ib nb 97 if lt k 0 98 ret 4 99 end 100 if ne ulong k nb 101 ret 3 102 end 103 for i ulong mul rows 8 104 put ins i gp_ele ib mul i 8 105 end 106 end 107 ret 0 108 end 109 110 note encode one frame and write its result frame; gives 0, or the exit code 111 fn gp_eout ins view ulong 8192 phys view ulong 288 n ulong pad ulong ob edit uchar 16392 to ulong 112 code = new uchar 16384 0 113 r = bw_enc_sm121 ins phys n pad code 114 for i ulong 8 115 put ob i uchar and shr r mul i 8 255 116 end 117 for i ulong r 118 put ob add i 8 get code i 119 end 120 if ne gp_ewrite ob add r 8 0 121 ret 5 122 end 123 ret 0 124 end 125 126 fn main to int 127 ib = new uchar 65536 0 128 ins = new ulong 8192 0 129 phys = new ulong 288 0 130 ob = new uchar 16392 0 131 note at most `1000000` frames: each frame is at least 2328 bytes 132 while true bound `1000000` 133 k = gp_eread ib 24 134 if lt k 0 135 ret gp_efail 4 136 end 137 if eq k 0 138 ret 0 139 end 140 if ne k 24 141 ret gp_efail 3 142 end 143 for i ulong 8 144 if ne get ib i get g_emag i 145 ret gp_efail 2 146 end 147 end 148 n = gp_ele ib 8 149 pad = gp_ele ib 16 150 c = gp_eframe ib n ins phys 151 if eq c 0 152 c = gp_eout ins phys n pad ob 153 end 154 if ne c 0 155 ret gp_efail c 156 end 157 end 158 ret 0 159 end