Commit ed0db4c
mt_pagedattn: fix RDNA4 WMMA operand order in decode + tile prefill
Per RDNA4 ISA §7.12.2, the wmma_f32_16x16x16_f16_w32_gfx12 instruction
places the A operand with K-dim in lane (lane%16) and M-dim in slot, but
the C/D output with M-dim in lane and N-dim in slot — those orientations
are different. The kernel's I-major load + (Q,K) call order computes the
correct product at the HW level, but reads the result as if D were also
I-major, producing scores and acc that are effectively transposed.
This manifested as garbage decode output after 1-2 tokens (the wrong-axis
mask and softmax become dominant as K-token count grows) and as
subtly-wrong prefill attention that PPL did not detect — the LM head
still sampled plausible tokens from systematically-perturbed activations.
Fix: swap the operand order at each mma site. With the swap, HW computes
the transposed product, which the kernel's existing I-major read decodes
as correctly-oriented scores_true and acc_true. No changes required to
the load helpers, mask logic, softmax, or shfl_xor reductions.
mt_pagedattn_decode.cu:
mma(scores, Q_tile, K_tile) → mma(scores, K_tile, Q_tile)
mma(acc, scores_h, V_tile) → mma(acc, V_tile, scores_h)
mt_pagedattn_tile.cu (basic + prefetch variants, 4 sites total).
Validation:
- WMMA decode bit-identical to non-WMMA flash-decode (4 prompts, 4B).
- WMMA tile prefill bit-identical to --no-kv-tier-paged-blocks mainline
attention (4 prompts, 4B).
- 35B coherent on simple prompts.
- NIAH @ 6854 tokens on Qwen3.6-35B retrieves the secret passphrase.
Also adds tests/wmma_rdna4_probe_v3.cu — a standalone HIP probe that
encodes A/B/D positions per ISA §7.12.2 and confirms 256/256 element
agreement on gfx1201. Useful as a regression check if future kernel work
revisits the per-element layout.
Debug lane-0 dumps in mt_pagedattn_decode.cu are gated by a constexpr
MT_WMMA_DEBUG_DUMP=false so they cost nothing at runtime, but stay
available for future investigation.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 8b3fd55 commit ed0db4c
3 files changed
Lines changed: 176 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
773 | 773 | | |
774 | 774 | | |
775 | 775 | | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
776 | 791 | | |
777 | 792 | | |
778 | 793 | | |
| |||
882 | 897 | | |
883 | 898 | | |
884 | 899 | | |
885 | | - | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
886 | 906 | | |
887 | 907 | | |
888 | 908 | | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
889 | 926 | | |
890 | 927 | | |
891 | 928 | | |
| |||
946 | 983 | | |
947 | 984 | | |
948 | 985 | | |
949 | | - | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
950 | 1013 | | |
951 | 1014 | | |
952 | 1015 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
450 | 450 | | |
451 | 451 | | |
452 | 452 | | |
453 | | - | |
| 453 | + | |
| 454 | + | |
454 | 455 | | |
455 | 456 | | |
456 | 457 | | |
| |||
544 | 545 | | |
545 | 546 | | |
546 | 547 | | |
547 | | - | |
| 548 | + | |
| 549 | + | |
548 | 550 | | |
549 | 551 | | |
550 | 552 | | |
| |||
823 | 825 | | |
824 | 826 | | |
825 | 827 | | |
826 | | - | |
| 828 | + | |
| 829 | + | |
827 | 830 | | |
828 | 831 | | |
829 | 832 | | |
| |||
935 | 938 | | |
936 | 939 | | |
937 | 940 | | |
938 | | - | |
| 941 | + | |
| 942 | + | |
939 | 943 | | |
940 | 944 | | |
941 | 945 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
0 commit comments