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/gpu/bw_qmd.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 / gpu / bw_qmd.om` 264 lines ยท 5531 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note om/gpu/bw_qmd.om: Blackwell sm_121 QMD0/QMD1 builder and invariant verifier in pure OM-2. 3 note Replaces the QMD packing and verification logic of src/omega_blackwell_qmd.c. 4 note Word 36 dynamically sets MIN_ and TARGET_SM_CONFIG_SHARED_MEM_SIZE from shared_bytes: 5 note <= 32768 B -> 9 (32 KiB), <= 65536 B -> 17 (64 KiB), <= 98304 B -> 26 (100 KiB), 6 note keeping MAX = 26 (100 KiB). For shared_bytes <= 32768 this is bit-identical to 0x04b44808. 7 om2 8 9 const QMD_MAX_SMEM ulong 98304 10 11 fn u32lo v ulong to uint 12 ret uint and v 0xffffffff 13 end 14 15 fn qzero q edit uint 96 to void 16 for i ulong 96 17 put q i 0 18 end 19 end 20 21 fn resolve_tx m view ulong 16 to ulong 22 tx = get m 8 23 if ne tx 0 24 ret tx 25 end 26 tpb = get m 6 27 if ne tpb 0 28 ret tpb 29 end 30 ret 64 31 end 32 33 fn resolve_gx m view ulong 16 tx ulong to ulong 34 gx = get m 10 35 if ne gx 0 36 ret gx 37 end 38 gw = get m 7 39 if ne gw 0 40 ret gw 41 end 42 ne_val = get m 5 43 g = div add ne_val sub tx 1 tx 44 if eq g 0 45 ret 1 46 end 47 ret g 48 end 49 50 fn smem_cfg_for sb ulong to ulong 51 if le sb 32768 52 ret 9 53 end 54 if le sb 65536 55 ret 17 56 end 57 ret 26 58 end 59 60 export fn bw_qmd0 q edit uint 96 qmd1_va ulong to ulong 61 qzero q 62 put q 4 0x00800002 63 put q 10 0x00230000 64 put q 12 u32lo shr qmd1_va 8 65 put q 14 0x00500200 66 put q 34 0x00010001 67 put q 35 0x00000801 68 ret 0 69 end 70 71 fn qmd1_head m view ulong 16 q edit uint 96 to void 72 code_va = get m 0 73 sem_va = get m 3 74 qmd0_va = get m 4 75 put q 4 0x013f0000 76 put q 9 0x00000003 77 put q 10 0x00190000 78 put q 12 u32lo shr qmd0_va 8 79 put q 14 0x2f5003a4 80 put q 15 u32lo sem_va 81 put q 16 u32lo shr sem_va 32 82 put q 17 0x00000006 83 put q 19 0x81810000 84 put q 20 0x00000038 85 put q 22 0x04000000 86 put q 32 u32lo shr code_va 4 87 put q 33 u32lo or and shr code_va 36 0x1fffff shl ulong 0xa 21 88 end 89 90 fn qmd1_cbanks m view ulong 16 q edit uint 96 to void 91 cbank_va = get m 1 92 scratch_va = get m 2 93 code_va = get m 0 94 cb5 = add cbank_va 0x300 95 put q 42 u32lo shr cbank_va 6 96 put q 43 u32lo or and shr cbank_va 38 0x7ffff shl ulong 0x40 19 97 put q 44 u32lo shr scratch_va 6 98 put q 45 u32lo or and shr scratch_va 38 0x7ffff shl ulong 0x90 19 99 put q 52 u32lo shr cb5 6 100 put q 53 u32lo or and shr cb5 38 0x7ffff shl ulong 0x10 19 101 put q 56 u32lo shr scratch_va 6 102 put q 57 u32lo or and shr scratch_va 38 0x7ffff shl ulong 0x1000 19 103 put q 58 0x10300011 104 put q 59 u32lo shr code_va 8 105 end 106 107 fn qmd1_dims m view ulong 16 q edit uint 96 to void 108 tx = resolve_tx m 109 ty = get m 9 110 if eq ty 0 111 ty = ulong 1 112 end 113 gx = resolve_gx m tx 114 gy = get m 11 115 if eq gy 0 116 gy = ulong 1 117 end 118 gpr = get m 12 119 if lt gpr 16 120 gpr = ulong 16 121 end 122 put q 34 u32lo or and tx 0xffff shl and ty 0xffff 16 123 put q 35 u32lo or or ulong 1 shl and gpr 0x1ff 8 shl ulong 1 17 124 put q 37 0 125 put q 39 u32lo gx 126 put q 40 u32lo gy 127 put q 41 1 128 end 129 130 export fn bw_qmd1 m view ulong 16 q edit uint 96 to ulong 131 sb = get m 13 132 if gt sb QMD_MAX_SMEM 133 ret 1 134 end 135 qzero q 136 qmd1_head m q 137 qmd1_dims m q 138 s7 = ulong 8 139 if ne sb 0 140 s7 = div add sb 127 128 141 end 142 sc = smem_cfg_for sb 143 w36 = or or or shl sc 23 shl ulong 26 17 shl sc 11 s7 144 put q 36 u32lo w36 145 qmd1_cbanks m q 146 ret 0 147 end 148 149 export fn bw_qmd_verify q view uint 96 to ulong 150 ver = and shr get q 14 20 0xf 151 if ne ver 5 152 ret 1 153 end 154 qtype = and shr get q 4 23 0x7 155 if ne qtype 2 156 ret 1 157 end 158 if ne get q 37 0 159 ret 1 160 end 161 if eq get q 17 0 162 ret 1 163 end 164 pf = and shr get q 33 21 0x1ff 165 if ne pf 0xa 166 ret 1 167 end 168 if eq and get q 58 1 0 169 ret 1 170 end 171 ret 0 172 end 173 174 note The single-token hd256 record and direct launch share the same 25-word kernel ABI. 175 note Input addresses: QKV, K, plane bytes, RoPE, norm base, output, partials, counters. 176 note Scalars: layer, position, tokens per split, split count, max position, epsilon bits, output scale bits, log2 scale bits. 177 fn attn_addr args edit uint 25 i ulong va ulong to void 178 put args i u32lo va 179 put args add i 1 u32lo shr va 32 180 end 181 182 export fn bw_attn256_args s view ulong 16 args edit uint 25 to ulong 183 norm = add get s 4 mul get s 8 2048 184 attn_addr args 0 get s 0 185 attn_addr args 2 get s 1 186 attn_addr args 4 add get s 1 get s 2 187 attn_addr args 6 get s 3 188 attn_addr args 8 norm 189 attn_addr args 10 add norm 1024 190 attn_addr args 12 get s 5 191 attn_addr args 14 get s 6 192 attn_addr args 16 get s 7 193 put args 18 u32lo get s 9 194 put args 19 u32lo get s 10 195 put args 20 u32lo get s 11 196 put args 21 u32lo mul get s 12 512 197 put args 22 u32lo get s 13 198 put args 23 u32lo get s 14 199 put args 24 u32lo get s 15 200 ret 0 201 end 202 203 note Record one hd256 launch. The caller reserves a valid slot and publishes it after success. 204 note Slot fields: code, bank, scratch, semaphore, QMD1, declared registers, grid Y, output words. 205 export fn bw_attn256_record s view ulong 16 slot view ulong 8 driver view uint 224 bank edit uint 249 q1 edit uint 96 q0 edit uint 96 to ulong 206 gx = get s 11 207 gy = get slot 6 208 if eq gx 0 209 ret 1 210 end 211 if eq gy 0 212 ret 1 213 end 214 if eq get slot 0 0 215 ret 1 216 end 217 m = new ulong 16 0 218 for i ulong 4 219 put m i get slot i 220 end 221 put m 4 add get slot 4 512 222 put m 5 get slot 7 223 put m 8 256 224 put m 9 1 225 put m 10 gx 226 put m 11 gy 227 regs = get slot 5 228 if le regs 64 229 regs = ulong 64 230 else 231 regs = and add regs 7 0xfffffff8 232 end 233 put m 12 regs 234 put m 13 14896 235 if ne bw_qmd1 m q1 0 236 ret 1 237 end 238 if ne bw_qmd_verify q1 0 239 ret 1 240 end 241 if ne bw_qmd0 q0 get slot 4 0 242 ret 1 243 end 244 for i ulong 224 245 put bank i get driver i 246 end 247 va = get slot 1 248 put bank 68 u32lo shr va 32 249 put bank 69 u32lo va 250 put bank 210 u32lo shr add va 0x380 32 251 put bank 211 u32lo add va 0x380 252 put bank 212 u32lo shr add va 0x39c 32 253 put bank 213 u32lo add va 0x39c 254 put bank 216 256 255 put bank 217 1 256 put bank 220 u32lo gx 257 put bank 221 u32lo gy 258 args = new uint 25 0 259 status = bw_attn256_args s args 260 for i ulong 25 261 put bank add i 224 get args i 262 end 263 ret status 264 end