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/CUDApp/blob/main/tests/models/quant-caller.om # CUDApp CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit. 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 `CUDApp / tests / models / quant-caller.om` 514 lines · 7444 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note Concatenate quant.om and existing fp8/mxfp4/nvfp4 models before this caller. 3 fn qt_base d edit ulong 48 fmt ulong cols ulong to void 4 for i ulong 48 5 put d i 0 6 end 7 put d 0 1 8 put d 1 fmt 9 put d 2 8 10 put d 11 1 11 put d 13 1 12 put d 14 8 13 put d 15 1 14 put d 17 1 15 put d 18 cols 16 put d 19 2 17 put d 24 1 18 put d 25 cols 19 put d 27 1 20 put d 30 cols 21 put d 33 cols 22 put d 36 cols 23 put d 41 cols 24 if ge fmt 4 25 put d 24 2 26 put d 4 2 27 put d 5 1 28 put d 6 32 29 if eq fmt 5 30 put d 4 3 31 put d 6 16 32 end 33 if lt fmt 6 34 put d 2 4 35 put d 14 4 36 end 37 put d 25 quant_ceil cols div ulong 8 get d 2 38 put d 30 get d 25 39 put d 26 quant_ceil cols get d 6 40 put d 31 get d 26 41 put d 32 1 42 put d 41 mul quant_ceil cols get d 6 get d 6 43 put d 33 quant_ceil get d 41 div ulong 8 get d 2 44 put d 36 get d 33 45 put d 34 get d 26 46 put d 35 get d 4 47 put d 37 get d 31 48 end 49 end 50 fn qt_wire to uint 51 d = new ulong 48 0 52 p = new ulong 48 0 53 wire = new uchar 384 0 54 other = new uchar 384 0 55 qt_base d 4 3 56 if ne quant_write d wire 0 57 ret 1 58 end 59 if ne quant_read wire p 0 60 ret 2 61 end 62 for i ulong 48 63 if ne get p i get d i 64 ret 3 65 end 66 end 67 if ne quant_write p other 0 68 ret 4 69 end 70 if ne quant_hash wire quant_hash other 71 ret 5 72 end 73 put p 28 1 74 if ne quant_write p other 0 75 ret 6 76 end 77 if ne quant_shash wire quant_shash other 78 ret 7 79 end 80 if eq quant_hash wire quant_hash other 81 ret 8 82 end 83 ret 0 84 end 85 fn qt_nib src view uchar 65536 i ulong to uint 86 v = uint get src div i 2 87 ret and shr v uint mul rem i 2 4 15 88 end 89 fn qt_numer src view uchar 65536 sc view uchar 1024 dst view uchar 65536 ds view uchar 1024 fmt ulong cols ulong to uint 90 block = ulong 32 91 if eq fmt 5 92 block = 16 93 end 94 for i ulong cols 95 a = uint get src i 96 b = uint get dst i 97 if eq fmt 6 98 a = e4m3bits a 99 b = e4m3bits b 100 else 101 a = qt_nib src i 102 b = qt_nib dst i 103 if eq fmt 4 104 a = mxfp4bits a uint get sc div i block 105 b = mxfp4bits b uint get ds div i block 106 else 107 a = nvfp4bits a uint get sc div i block 108 b = nvfp4bits b uint get ds div i block 109 end 110 end 111 if ne a b 112 ret 1 113 end 114 end 115 ret 0 116 end 117 fn qt_blocks fmt ulong cols ulong to uint 118 d = new ulong 48 0 119 src = new uchar 65536 0 120 sc = new uchar 1024 0 121 dst = new uchar 65536 255 122 ds = new uchar 1024 255 123 qt_base d fmt cols 124 for i ulong get d 30 125 put src i uchar and i 255 126 end 127 if eq get d 2 4 128 if ne rem cols 2 0 129 pos = div cols 2 130 put src pos and get src pos 15 131 end 132 end 133 for i ulong get d 31 134 put sc i 127 135 if eq fmt 5 136 put sc i 56 137 end 138 end 139 if eq fmt 6 140 for i ulong cols 141 if eq and get src i 127 127 142 put src i 0 143 end 144 end 145 end 146 if ne quant_repack d src sc dst ds 0 147 ret 6 148 end 149 for i ulong get d 30 150 if ne get src i get dst i 151 ret 7 152 end 153 end 154 for i ulong get d 36 155 if ge i get d 30 156 if ne get dst i 0 157 ret 8 158 end 159 end 160 end 161 for i ulong get d 31 162 if ne get sc i get ds i 163 ret 9 164 end 165 end 166 note Independently implemented source numeric decoder consumes actual packed output. 167 if ne qt_numer src sc dst ds fmt cols 0 168 ret 10 169 end 170 ret 0 171 end 172 fn qt_fp8 fmt ulong to uint 173 d = new ulong 48 0 174 src = new uchar 65536 0 175 sc = new uchar 1024 0 176 dst = new uchar 65536 255 177 ds = new uchar 1024 255 178 qt_base d fmt 256 179 put d 12 1 180 for i ulong 256 181 put src i uchar i 182 end 183 if ne quant_repack d src sc dst ds 0 184 ret 1 185 end 186 for i ulong 256 187 if ne get src i get dst i 188 ret 2 189 end 190 end 191 put d 12 0 192 if ne quant_repack d src sc dst ds 5 193 ret 3 194 end 195 for i ulong 256 196 if eq fmt 2 197 if eq and i 127 127 198 put src i 0 199 end 200 else 201 if ge and i 127 124 202 put src i 0 203 end 204 end 205 end 206 if ne quant_repack d src sc dst ds 0 207 ret 4 208 end 209 ret 0 210 end 211 fn qt_negative to uint 212 d = new ulong 48 0 213 src = new uchar 65536 0 214 sc = new uchar 1024 0 215 dst = new uchar 65536 211 216 ds = new uchar 1024 213 217 qt_base d 4 3 218 put sc 0 255 219 if ne quant_repack d src sc dst ds 6 220 ret 1 221 end 222 if or ne get dst 0 211 ne get ds 0 213 223 ret 2 224 end 225 put sc 0 127 226 put src 1 240 227 if ne quant_repack d src sc dst ds 4 228 ret 3 229 end 230 put src 1 0 231 put d 31 0 232 if ne quant_check d 3 233 ret 4 234 end 235 put d 31 1 236 put d 25 0 237 if ne quant_check d 3 238 ret 5 239 end 240 put d 25 2 241 put d 27 3 242 if ne quant_check d 4 243 ret 6 244 end 245 put d 27 1 246 put d 39 1 247 if ne quant_check d 1 248 ret 7 249 end 250 put d 39 0 251 put d 42 1 252 if ne quant_check d 1 253 ret 8 254 end 255 put d 42 0 256 put d 17 `18446744073709551615` 257 if ne quant_check d 3 258 ret 9 259 end 260 put d 17 1 261 put d 7 1 262 if ne quant_check d 7 263 ret 10 264 end 265 put d 7 0 266 put d 32 0 267 if ne quant_check d 4 268 ret 11 269 end 270 put d 32 1 271 put d 41 31 272 if ne quant_check d 4 273 ret 12 274 end 275 put d 41 32 276 put d 9 2 277 if ne quant_check d 1 278 ret 13 279 end 280 put d 9 0 281 put d 1 7 282 if ne quant_check d 1 283 ret 14 284 end 285 ret 0 286 end 287 fn qt_ints to uint 288 d = new ulong 48 0 289 wire = new uchar 384 0 290 p = new ulong 48 0 291 qt_base d 2 8 292 put d 1 1 293 put d 3 1 294 put d 11 0 295 put d 13 0 296 for bits ulong 8 297 put d 2 add bits 1 298 put d 14 add bits 1 299 put d 7 1 300 put d 8 sub shl ulong 1 add bits 1 1 301 if ne quant_sem d 0 302 ret 1 303 end 304 if ne quant_write d wire 0 305 ret 2 306 end 307 if ne quant_read wire p 0 308 ret 3 309 end 310 if ne quant_check p 2 311 ret 4 312 end 313 put d 8 shl ulong 1 add bits 1 314 if ne quant_sem d 7 315 ret 5 316 end 317 end 318 ret 0 319 end 320 fn qt_foldcase to uint 321 d = new ulong 48 0 322 src = new uchar 65536 0 323 sc = new uchar 1024 0 324 dst = new uchar 65536 255 325 ds = new uchar 1024 255 326 qt_base d 2 256 327 put d 17 128 328 put d 4 1 329 put d 5 128 330 put d 6 128 331 put d 24 3 332 put d 26 4 333 put d 30 mul ulong 128 256 334 put d 31 4 335 put d 34 8 336 put d 35 4 337 put d 36 get d 30 338 put d 37 8 339 put d 40 1 340 note BF16 source patterns 0 and sign-bit-only preserve signed zero. 341 put sc 3 128 342 if ne quant_repack d src sc dst ds 0 343 ret 1 344 end 345 if ne get ds 7 128 346 ret 2 347 end 348 put sc 0 128 349 put sc 1 127 350 if ne quant_repack d src sc dst ds 6 351 ret 3 352 end 353 put sc 0 0 354 put sc 1 128 355 if ne quant_repack d src sc dst ds 0 356 ret 4 357 end 358 if ne get ds 3 128 359 ret 5 360 end 361 put sc 0 128 362 put sc 1 63 363 if ne quant_repack d src sc dst ds 0 364 ret 6 365 end 366 if ne bitcast uint quant_fold sc 0 shl add uint 127 56 23 367 ret 7 368 end 369 ret 0 370 end 371 fn qt_strides to uint 372 d = new ulong 48 0 373 src = new uchar 65536 0 374 sc = new uchar 1024 0 375 dst = new uchar 65536 255 376 ds = new uchar 1024 255 377 qt_base d 4 3 378 put d 17 2 379 put d 25 4 380 put d 26 2 381 put d 27 32 382 put d 28 3 383 put d 29 2 384 put d 30 16 385 put d 31 6 386 put d 33 32 387 put d 34 2 388 put d 36 64 389 put d 37 4 390 put src 3 33 391 put src 4 3 392 put src 7 67 393 put src 8 5 394 put sc 2 127 395 put sc 4 128 396 if ne quant_repack d src sc dst ds 0 397 ret 1 398 end 399 if or ne get dst 0 33 ne get dst 1 3 400 ret 2 401 end 402 if or ne get dst 32 67 ne get dst 33 5 403 ret 3 404 end 405 if or ne get ds 0 127 ne get ds 2 128 406 ret 4 407 end 408 if or ne get ds 1 0 ne get ds 3 0 409 ret 5 410 end 411 for i ulong 64 412 if gt rem i 32 1 413 if ne get dst i 0 414 ret 6 415 end 416 end 417 end 418 put d 28 `18446744073709551615` 419 if ne quant_repack d src sc dst ds 3 420 ret 7 421 end 422 ret 0 423 end 424 fn qt_boundone fmt ulong scale uchar want uint to uint 425 d = new ulong 48 0 426 src = new uchar 65536 0 427 sc = new uchar 1024 0 428 dst = new uchar 65536 211 429 ds = new uchar 1024 213 430 qt_base d fmt 1 431 put sc 0 scale 432 if ne quant_repack d src sc dst ds want 433 ret 1 434 end 435 if eq want 0 436 if ne get ds 0 scale 437 ret 2 438 end 439 else 440 if ne get dst 0 211 441 ret 3 442 end 443 if ne get ds 0 213 444 ret 3 445 end 446 end 447 ret 0 448 end 449 fn qt_boundaries to uint 450 for f ulong 3 451 if ne qt_boundone add f 4 0 0 0 452 ret 1 453 end 454 if ne qt_boundone add f 4 126 0 0 455 ret 2 456 end 457 if ne qt_boundone add f 4 255 6 0 458 ret 3 459 end 460 if eq f 1 461 if ne qt_boundone 5 127 6 0 462 ret 4 463 end 464 if ne qt_boundone 5 254 6 0 465 ret 5 466 end 467 else 468 if ne qt_boundone add f 4 127 0 0 469 ret 6 470 end 471 if ne qt_boundone add f 4 254 0 0 472 ret 7 473 end 474 end 475 end 476 ret 0 477 end 478 fn main to int 479 if ne qt_wire 0 480 ret 7 481 end 482 for fmt ulong 3 483 for k ulong 65 484 if ne qt_blocks add fmt 4 add k 1 0 485 ret 1 486 end 487 end 488 end 489 if ne qt_fp8 2 0 490 ret 2 491 end 492 if ne qt_fp8 3 0 493 ret 3 494 end 495 if ne qt_negative 0 496 ret 4 497 end 498 if ne qt_ints 0 499 ret 5 500 end 501 if ne qt_foldcase 0 502 ret 6 503 end 504 if ne qt_consumer 0 505 ret 8 506 end 507 if ne qt_strides 0 508 ret 9 509 end 510 if ne qt_boundaries 0 511 ret 10 512 end 513 ret 0 514 end