Commit 7252dc3
perf(q4_0): partial-vec dotQ4_0BlockMemSeg via scratch + SIMD FMA
Replaces the fully-scalar inner loop in dotQ4_0BlockMemSeg with the
two-stage pattern Q4_K used pre-#562: a scalar byte-pair unpack
writes 32 sign-corrected floats into a caller-supplied scratch
FloatArray (16 byte loads, two nibbles each — half the byte traffic
of the prior scalar dot product), then a FloatVector FMA reduction
takes the dot product against the matching input slice.
Per-block scratch is hoisted out of matmulF32Q4_0MemSeg's loops to
amortize allocation. A backwards-compatible no-codeBuf overload
preserves the prior signature for any external callers (creates a
fresh scratch on each invocation).
Q4_0 isn't dominant in modern quantized weights (Q4_K_M / Q4_K_S
cover Gemma 4, Llama, Qwen) but it was the last fully-scalar kernel
in JvmQuantizedVectorKernels — closing it brings the JVM Vector path
to parity across Q4_0, Q4_K, Q6_K, Q8_0.
A fully-fused ByteVector pipeline (a la PanamaVectorQ4KMatmulKernel)
is awkward for Q4_0's interleaved nibble layout — adjacent elements
share a byte, so getting codes in natural order needs a strided
gather or lane-interleave shuffle. Out of scope; if Q4_0 becomes a
hot path again, that's the next move.
Tests: cpu jvmTest 218/218 pass, including QuantizedMemSegMatmulTest's
parity coverage of the Q4_0 MemSeg matmul.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 00b80c0 commit 7252dc3
1 file changed
Lines changed: 62 additions & 11 deletions
File tree
- skainet-backends/skainet-backend-cpu/src/jvmMain/kotlin/sk/ainet/exec/tensor/ops
Lines changed: 62 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
518 | 518 | | |
519 | 519 | | |
520 | 520 | | |
521 | | - | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
522 | 524 | | |
523 | | - | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
524 | 538 | | |
525 | 539 | | |
526 | 540 | | |
527 | 541 | | |
528 | 542 | | |
529 | 543 | | |
| 544 | + | |
530 | 545 | | |
531 | 546 | | |
532 | 547 | | |
533 | 548 | | |
534 | 549 | | |
535 | 550 | | |
536 | 551 | | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | | - | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
544 | 559 | | |
545 | 560 | | |
546 | | - | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
547 | 580 | | |
548 | 581 | | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
549 | 598 | | |
550 | 599 | | |
551 | 600 | | |
| |||
569 | 618 | | |
570 | 619 | | |
571 | 620 | | |
| 621 | + | |
| 622 | + | |
572 | 623 | | |
573 | 624 | | |
574 | 625 | | |
575 | 626 | | |
576 | 627 | | |
577 | 628 | | |
578 | 629 | | |
579 | | - | |
| 630 | + | |
580 | 631 | | |
581 | 632 | | |
582 | 633 | | |
| |||
0 commit comments