vllm.models.muse_spark.nvidia.specialized_decode.cutedsl.attention.qkv_front
¶
The Muse Spark attention front for decode batches (1 <= M <= 16) in one
launch: the QKV + o-gate projection (split-K BF16 GEMM, mma.sync, FP32
accumulate), then the per-head weightless RMS norm, interleaved RoPE, the y
store and the paged K/V insert. It writes what the projection GEMM followed by
fused_muse_spark_qknorm_rope_kv_insert writes for a BF16 KV cache, up to the
GEMM's summation order.
Structure: a thread-block cluster computes one head (64 output columns), its S CTAs splitting K into KSTRIPE-tile cyclic stripes. In each CTA a producer thread streams the W and x boxes into a shared-memory ring with TMA (128B swizzle), four consumer warps run mma.sync on them and an aux warp fetches the epilogue inputs. Each CTA sends its partial of token t to the owner CTA (rank t % S) with st.async; the owner sums the S partials in fixed rank order, rounds to BF16 and runs the epilogue. No global scratch, no atomics, no state across calls: the result depends on the launch shape only.
PDL: the kernel may start while its predecessor still runs. Before griddepcontrol.wait it reads only the weights, which no kernel writes inside a graph; every thread waits before it reads x, positions, slots or cos|sin and before any global store.
Classes:
-
QkvFrontKernel–One variant:
tiles8-token column tiles, astages-deep ring, K
Functions:
-
compile_qkv_front–The compiled variant, shared by every layer and shape it serves, with
-
fixed_rows–The kernel variant's row count: 8 specializes M == 8, 0 any other M.
-
hidden_rows_ok–Whether
tis a contiguous, 16-byte aligned bf16 [rows, 8192] -
k_split–The K split (cluster size) for an N-wide projection: one CTA per SM
-
kv_cache_layout_ok–Whether a KV cache has the layout the QKV front and attn2 read: bf16
-
launch–qkv_frontwithout its checks: for a callunsupportedtook with -
prepare–Compile the variants that N columns and these row counts take (before
-
qkv_front–Out [M, N] = x [M, 8192] @ weight [N, 8192]^T with the q and k heads
-
ring_stages–The ring depth at K split
split; it does not change the result. -
supports_shape–Whether a variant computes an N-wide projection with these KV heads.
-
token_tiles–8-token mma column tiles for M tokens.
-
unsupported–Why the kernel cannot take this call (with
out, also its output), -
variant–(tiles, stages, splits, fixed_m) of the kernel for N columns, M rows.
QkvFrontKernel
¶
One variant: tiles 8-token column tiles, a stages-deep ring, K
split splits (the cluster size) and fixed_m (8: M == 8, 0: any M of
the tile count).
Methods:
-
aux–Slots and cos|sin rows of this CTA's tokens into shared memory, and
-
consume–Consumer warp
warp: W rows 16 warp .. 16 warp + 15 over all 128 k -
finish–Epilogue of local token
u(head columns 2 lane, 2 lane + 1): the -
produce–The producer thread: the weights of stages 1..npre-1 and an L2
-
send–This CTA's partial of rows 16 warp + g (+8) for tokens 8 nt + 2 t
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/qkv_front.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 | |
aux(positions, cos_sin, slots, kv_cache, y, n, hq, hkv, rope, rank, head, ntok, s_cs, s_slot)
¶
Slots and cos|sin rows of this CTA's tokens into shared memory, and the L2 prefetch of their y and K/V destinations. Slots and positions can be written by the kernels before this one in a graph: read after the wait.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/qkv_front.py
consume(sbase, fb, eb, warp, lane, acc)
¶
Consumer warp warp: W rows 16 warp .. 16 warp + 15 over all 128 k
of every stage. The 32-k block b lives in box b / 2 at 16-byte chunks
2 t + (b & 1); A and B take the same k permutation. One accumulator set
per k block.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/qkv_front.py
finish(s_recv, u, ntok_max, cv, sn, slot, rope, head, hq, hkv, eps, y_row, kv_cache, lane)
¶
Epilogue of local token u (head columns 2 lane, 2 lane + 1): the
splits partials summed in rank order and rounded to BF16, then for q and
k heads the RMS norm and RoPE (cv, sn: this lane's cos and
sin), the y store and, for k and v heads, the cache row of slot.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/qkv_front.py
produce(w_map, x_map, sbase, fb, eb, rank, row0, lane)
¶
The producer thread: the weights of stages 1..npre-1 and an L2 prefetch of the next ring's weights, then (after the wait) the activations of those stages and the steady state.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/qkv_front.py
send(acc, s_recv, rb, warp, lane, rank, ntok_max, active_m)
¶
This CTA's partial of rows 16 warp + g (+8) for tokens 8 nt + 2 t
(+1), the k-block sets summed in fixed order, into the owner rank's
receive slot [rank][token / splits][row]: rows (r, r + 1) of one token
per lane, paired by one xor-4 shuffle (lanes g and g ^ 1 share t).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/qkv_front.py
_cache_row(kv_cache, slot, hkv, kv_head)
¶
Byte address of the [pages, hkv, 16, 128] BF16 cache row of slot
for KV head kv_head (64-bit: cache offsets exceed 2^31).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/qkv_front.py
_compile_and_call(device, n, m, *args)
¶
The (N, M) variant called on the current stream of device, which is
current: a first compile targets the inputs' device too.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/qkv_front.py
_k_tile(i, rank, splits)
¶
First k of the i-th k-tile cluster rank rank reduces.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/qkv_front.py
_k_tile_dynamic(i, rank, splits)
¶
_k_tile of a dynamic tile index.
_swizzled(row, chunk)
¶
Byte offset of 16-byte chunk chunk of row in a 128B-swizzled
box (1 KiB aligned).
compile_qkv_front(tiles, stages, splits, fixed_m, options='')
cached
¶
The compiled variant, shared by every layer and shape it serves, with
these extra compile options; called (TVM FFI) as fn(w, x, positions,
cos_sin, slots, kv_cache, y, m, n, hq, hkv, rope, eps, stream) with byte
addresses and the stream handle as ints.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/qkv_front.py
fixed_rows(m)
¶
The kernel variant's row count: 8 specializes M == 8, 0 any other M.
hidden_rows_ok(t)
¶
Whether t is a contiguous, 16-byte aligned bf16 [rows, 8192]
matrix, as x and the weight must be.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/qkv_front.py
k_split(n)
¶
The K split (cluster size) for an N-wide projection: one CTA per SM when a split of at least 4 allows it (largest power of two <= 8 with (n / 64) * split <= 152 CTAs), else two per SM (the same with 2 * 152 CTAs). 1 means no kernel fits.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/qkv_front.py
kv_cache_layout_ok(kv_cache, num_kv_heads)
¶
Whether a KV cache has the layout the QKV front and attn2 read: bf16
[pages, num_kv_heads, 16, 128] (K | V per slot), dense pages of dense
heads, 16-byte aligned.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/qkv_front.py
launch(x, weight, positions, cos_sin_cache, slot_mapping, kv_cache, out, eps)
¶
qkv_front without its checks: for a call unsupported took with
this out.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/qkv_front.py
prepare(n, rows=range(1, MAX_TOKENS + 1))
¶
Compile the variants that N columns and these row counts take (before CUDA graph capture).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/qkv_front.py
qkv_front(x, weight, positions, cos_sin_cache, slot_mapping, kv_cache, out, eps)
¶
Out [M, N] = x [M, 8192] @ weight [N, 8192]^T with the q and k heads
RMS-normalized (and rotated when cos_sin_cache is given), and the
normalized k and raw v heads written to the kv_cache rows of
slot_mapping (-1: none). N = (2 HQ + 2 HKV) * 64, HKV =
kv_cache.size(1). Launched with PDL on the current stream of x's device;
raises ValueError for a call outside the kernel (unsupported).
Graph-capturable once prepare has compiled the variant.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/qkv_front.py
ring_stages(n, split)
¶
The ring depth at K split split; it does not change the result.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/qkv_front.py
supports_shape(n, num_kv_heads)
¶
Whether a variant computes an N-wide projection with these KV heads.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/qkv_front.py
token_tiles(m)
¶
unsupported(x, weight, positions, cos_sin_cache, slot_mapping, kv_cache, out=None)
¶
Why the kernel cannot take this call (with out, also its output),
or None.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/qkv_front.py
variant(n, m)
¶
(tiles, stages, splits, fixed_m) of the kernel for N columns, M rows.