Commit e79ffe3
ggml-cuda: pad matmul weight rows to avoid cache-set aliasing
Weight matrices whose packed row size is a multiple of 2048 bytes map every row
onto the same L2 cache sets, so a matmul walking down a column thrashes a single
set. On RDNA3.5 this shows up as lost bandwidth in the FFN and attention GEMMs.
Add one cache line (128 B) to the row stride of such weights at buffer-init time
so consecutive rows land in different sets. get_alloc_size reserves the extra
bytes, and the loader uploads the packed file data with a strided 2D copy since
the destination rows are no longer adjacent. The gaps are zeroed so they cannot
hold NaNs.
Quantized weights are excluded: 128 is not a multiple of their block size and
would misalign the block-indexed kernels. The matmul paths need no change --
cuBLAS, mmf and mmvf all take the leading dimension from nb[1] already.
The loader flags the eligible tensors with GGML_TENSOR_FLAG_PAD_ROWS, reusing
llm_tensor_info_for() to tell a matmul weight from a bias or a norm; the
token-embedding/output duplication rule it shares with the buffer-type selection
is factored into resolve_tn_tensor() so the two cannot drift.
Gated to RDNA3.5; disable with GGML_CUDA_NO_PAD_WEIGHTS.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 3c53e42 commit e79ffe3
3 files changed
Lines changed: 86 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
648 | 648 | | |
649 | 649 | | |
650 | 650 | | |
651 | | - | |
652 | | - | |
653 | | - | |
654 | | - | |
655 | | - | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
656 | 657 | | |
657 | 658 | | |
658 | 659 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
761 | 761 | | |
762 | 762 | | |
763 | 763 | | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
764 | 791 | | |
765 | 792 | | |
766 | 793 | | |
| |||
769 | 796 | | |
770 | 797 | | |
771 | 798 | | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
772 | 810 | | |
773 | 811 | | |
774 | 812 | | |
| |||
929 | 967 | | |
930 | 968 | | |
931 | 969 | | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
932 | 975 | | |
933 | 976 | | |
934 | 977 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1038 | 1038 | | |
1039 | 1039 | | |
1040 | 1040 | | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
1041 | 1052 | | |
1042 | 1053 | | |
1043 | 1054 | | |
| |||
1079 | 1090 | | |
1080 | 1091 | | |
1081 | 1092 | | |
1082 | | - | |
1083 | | - | |
1084 | | - | |
1085 | | - | |
1086 | | - | |
1087 | | - | |
1088 | | - | |
1089 | | - | |
1090 | 1093 | | |
1091 | 1094 | | |
1092 | | - | |
| 1095 | + | |
1093 | 1096 | | |
1094 | 1097 | | |
1095 | 1098 | | |
| |||
1271 | 1274 | | |
1272 | 1275 | | |
1273 | 1276 | | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
1274 | 1287 | | |
1275 | 1288 | | |
1276 | 1289 | | |
| |||
1527 | 1540 | | |
1528 | 1541 | | |
1529 | 1542 | | |
1530 | | - | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
1531 | 1550 | | |
1532 | 1551 | | |
1533 | 1552 | | |
| |||
1554 | 1573 | | |
1555 | 1574 | | |
1556 | 1575 | | |
| 1576 | + | |
| 1577 | + | |
1557 | 1578 | | |
1558 | 1579 | | |
1559 | 1580 | | |
| |||
1570 | 1591 | | |
1571 | 1592 | | |
1572 | 1593 | | |
1573 | | - | |
| 1594 | + | |
1574 | 1595 | | |
1575 | 1596 | | |
1576 | 1597 | | |
| |||
1626 | 1647 | | |
1627 | 1648 | | |
1628 | 1649 | | |
1629 | | - | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
1630 | 1655 | | |
1631 | 1656 | | |
1632 | 1657 | | |
| |||
0 commit comments