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/aien-sovereign-core-mv/blob/main/om/qwen-native/linear/linear.om # aien-sovereign-core-mv AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-sovereign-core-mv / om / qwen-native / linear / linear.om` 257 lines ยท 4523 bytes Raw Blame History 1 note SPDX-License-Identifier: AGPL-3.0-only 2 note One CTA per output row, one warp per CTA. K must be a positive multiple of 32. 3 note Constant bank 0 at 896: five u64 pointers W,S,X,Y,decode then K,row bytes,scale columns. 4 fn lqnarr d uint a uint half bool to void 5 kind = uint 4 6 if half 7 kind = 6 8 end 9 gkvar or or 31105 shl d 16 shl a 24 4 xor `203299072` shl kind 9 false 10 end 11 fn lqemit fmt uint to ulong 12 base = mul ulong fmt 16384 13 put gkat 0 base 14 put gkpend 0 0 15 gks2r 0 33 false 16 gks2r 2 37 true 17 note Load the global memory descriptor to UR4 as in grpro. 18 gkq `4278482860` 27392 `134220288` or gkcw 4 2 7 get gkpend 0 8192 19 put gkpend 0 4 20 gkldc64 10 896 21 gkldc64 14 912 22 gkldc64 16 920 23 gkldc 4 936 false 24 gkldc 5 940 true 25 gkimadwr 10 2 5 10 26 gkimadw 16 2 4 16 27 if eq fmt 1 28 gkldc64 12 904 29 gkldc64 18 928 30 gkldc 5 944 false 31 gkshr 3 2 7 32 gkimadi 5 5 2 255 33 gkimadwr 12 3 5 12 34 end 35 gkmovz 24 36 gkimadi 3 0 1 255 37 top = div get gkat 0 16 38 put gkpend 0 63 39 gkimadw 20 3 4 14 40 gkldg 25 20 0 false 41 if eq fmt 1 42 gkimadw 20 3 1 10 43 lqnarr 26 20 false 44 gkimadw 20 26 4 18 45 gkldg 26 20 0 false 46 gkshr 27 3 7 47 gkimadw 20 27 2 12 48 lqnarr 27 20 true 49 gkimadi 27 27 65536 255 50 gkfmulf 26 26 27 51 else 52 gkimadw 20 3 2 10 53 lqnarr 26 20 true 54 gkimadi 26 26 65536 255 55 end 56 gkffmaf 24 26 25 24 57 gkmovi 5 32 58 gkiadd 3 3 5 59 gkisetp 0 3 4 1 60 gkbra 0 top 61 for i uint 5 62 grshfl 25 24 shr uint 16 i 63 grfadd 24 24 25 64 end 65 gkisge 0 0 1 66 gkstgp 16 24 0 false 8 67 gkexit 68 put gkthr fmt 32 69 put gkgpr fmt 32 70 put gksm fmt 0 71 ret sub get gkat 0 base 72 end 73 note Construct the complete E4M3FN lookup, including signed zero and both NaNs. 74 fn lqbits b uint to uint 75 sg = shl and b 128 24 76 mag = and b 127 77 if eq mag 127 78 ret or sg `2143289344` 79 end 80 if lt mag 8 81 ret or sg bitcast uint mul f32 mag bitcast f32 uint `989855744` 82 end 83 ret or sg shl add mag 960 20 84 end 85 global lqready uint 1 86 global lqowned uint 1 87 fn lqopen to bool 88 if ne get nvstate 0 0 89 ret false 90 end 91 put lqready 0 0 92 put lqowned 0 1 93 if not nvfull 94 ret false 95 end 96 if not nvchan 97 ret false 98 end 99 for i ulong 5 100 n = ulong 4096 101 if or or eq i 0 eq i 2 eq i 4 102 n = 65536 103 end 104 h = nvalloc n false 105 if le h 0 106 ret false 107 end 108 put gbmem i h 109 end 110 code = get gbmem 4 111 for fmt uint 2 112 n = lqemit fmt 113 off = mul ulong fmt 16384 114 if or gt n 16384 ne mapwrite code off gkcode off n long n 115 ret false 116 end 117 end 118 for b uint 256 119 if ne mapset code add 32768 mul ulong b 4 4 ulong lqbits b 0 120 ret false 121 end 122 end 123 put lqready 0 1 124 ret true 125 end 126 fn lqclose to bool 127 put lqready 0 0 128 if eq get lqowned 0 0 129 ret true 130 end 131 if not nvstop 132 ret false 133 end 134 put lqowned 0 0 135 ret true 136 end 137 note Caller describes four logical slices, indexed W,S,X,Y, in its owned mappings. 138 global lqmap long 4 139 global lqoff ulong 4 140 global lqlen ulong 4 141 fn lqgeom fmt uint m uint k uint sr uint sc uint to bool 142 if or or gt fmt 1 eq m 0 eq k 0 143 ret false 144 end 145 note Row stride is a u32 byte count and grid.x is a positive signed 31-bit extent. 146 if or gt m `2147483647` and eq fmt 0 gt k `2147483647` 147 ret false 148 end 149 if ne rem k 32 0 150 ret false 151 end 152 if or ne get lqlen 2 mul ulong k 4 ne get lqlen 3 mul ulong m 4 153 ret false 154 end 155 ws = ulong 2 156 if eq fmt 1 157 ws = 1 158 if ne sr add div sub m 1 128 1 159 ret false 160 end 161 if ne sc add div sub k 1 128 1 162 ret false 163 end 164 else 165 if or ne sr 0 ne sc 0 166 ret false 167 end 168 end 169 if ne get lqlen 0 mul mul ulong m ulong k ws 170 ret false 171 end 172 ret eq get lqlen 1 mul mul ulong sr ulong sc 2 173 end 174 fn lqvalid fmt uint to bool 175 for i ulong 4 176 if or ne i 1 eq fmt 1 177 h = get lqmap i 178 slot = nvfind h 179 if eq slot 96 180 ret false 181 end 182 if ne get nvmflag slot 15 183 ret false 184 end 185 for j ulong 5 186 if eq h get gbmem j 187 ret false 188 end 189 end 190 if or eq h get nvfifo 0 eq h get nvnotify 0 191 ret false 192 end 193 size = get nvmlen slot 194 off = get lqoff i 195 n = get lqlen i 196 if or gt off size gt n sub size off 197 ret false 198 end 199 al = ulong 4 200 if eq i 1 201 al = 2 202 end 203 if eq i 0 204 al = sub ulong 2 ulong fmt 205 end 206 if ne rem off al 0 207 ret false 208 end 209 if and ne i 3 eq h get lqmap 3 210 yo = get lqoff 3 211 if ge yo off 212 if lt sub yo off n 213 ret false 214 end 215 else 216 if lt sub off yo get lqlen 3 217 ret false 218 end 219 end 220 end 221 end 222 end 223 ret true 224 end 225 fn lqpack fmt uint m uint k uint sc uint to void 226 for i ulong 5 227 va = ulong 0 228 if eq i 4 229 va = add mapaddr get gbmem 4 32768 230 else 231 if or ne i 1 eq fmt 1 232 va = add mapaddr get lqmap i get lqoff i 233 end 234 end 235 put gkarg mul i 2 gblo va 236 put gkarg add mul i 2 1 gbhi va 237 end 238 put gkarg 10 k 239 put gkarg 11 mul k sub uint 2 fmt 240 put gkarg 12 sc 241 put gkna 0 13 242 put gkinv 0 1 243 gkbuild fmt m 1 1 244 end 245 fn lqrun fmt uint m uint k uint sr uint sc uint to bool 246 if or eq get lqready 0 0 ne get nvfault 0 0 247 ret false 248 end 249 if not lqgeom fmt m k sr sc 250 ret false 251 end 252 if not lqvalid fmt 253 ret false 254 end 255 lqpack fmt m k sc 256 ret ge gksend 0 257 end