Commit Graph

761 Commits

Author SHA1 Message Date
ca51af99dd D1: N-tile support for HEAD_DIM>256
- pv_n_tile = min(head_dim, 256) — MMA instruction N limit
- n_pv_tiles = head_dim // pv_n_tile — outer loop count
- V FMHA layout uses pv_n_tile (not head_dim) for N-tile slicing
- Test loops over N-tiles at Python level, kernel processes (128, pv_n_tile)
- For hd=512: 2 kernel launches with V[:,0:256] and V[:,256:512]
2026-05-23 03:22:23 +00:00
af51455db1 d1: add hd=512 test 2026-05-23 03:20:46 +00:00
af2f133347 d1: add quick regression test (hd=64 only) 2026-05-23 03:20:12 +00:00
ea9264a469 D1: Parameterize HEAD_DIM in FmhaKernel (64→512)
- Promote HEAD_DIM from module constant to constructor parameter
- FmhaKernel(head_dim=64, s_k=128, ...) — default 64 for regression
- All references to HEAD_DIM replaced with self.head_dim
- PV MMA tiler, V layout, softmax corr_tiles all parameterized
- TMEM budget warning when num_tmem_alloc_cols > 512
- New test: test_fmha_v3_stage_d1.py tests hd=64 (regression) and hd=512
- Stage C test preserved as-is for reference
2026-05-23 03:19:52 +00:00
3be9d6ed8c docs: revised Stage D/E plan — indexer removes paged TMA, one kernel for CSA/HCA/SWA, sink merge 2026-05-23 03:10:41 +00:00
bf0bb8241c cleanup: remove archive/ (240 stale files), stale example9/10, fix test table, add Stage D plan 2026-05-23 03:05:08 +00:00
dbf76fbc87 docs: update README with Stage C TMEM layout mismatch findings and status 2026-05-23 03:01:04 +00:00
f1ec406434 fix: revert to composition layout for hand-constructed atoms (matching CUTLASS) 2026-05-23 02:54:54 +00:00
68d1d547e0 fix: use logical_divide (not composition) for O rescale/normalize atoms to match get_tmem_load_op layout 2026-05-23 02:53:59 +00:00
3d058bcc77 fix: add NO-OP TMEM round-trip to re-map O from MMA to epilog layout 2026-05-23 02:50:53 +00:00
b140a9cecf fix: use TMEM round-trip normalize + epilogue_tma_store (known ~3% error) 2026-05-23 02:49:46 +00:00
de8221ea58 fix: correct bSG_gC indexing (6 modes) 2026-05-23 02:45:30 +00:00
00e2922d6d diag: print bSG shapes for TMA store indexing 2026-05-23 02:44:47 +00:00
2e8820fbe2 fix: typo from_dlcap -> from_dlpack 2026-05-23 02:44:00 +00:00
78a336e3ca fix: correction_epilog with paired atoms + pre-partitioned TMA store outside if block 2026-05-23 02:41:07 +00:00
2bdeb0f649 test: NO-OP round-trip + normalize at n=128 and n=256 2026-05-23 02:37:50 +00:00
5286aa985b fix: correction_epilog with paired atoms + pre-partitioned TMA store 2026-05-23 02:34:33 +00:00
830cb8c394 diag: NO-OP round-trip before normalize on 2D pattern 2026-05-23 02:32:40 +00:00
33ff5578d6 fix: O rescale uses 2D register tensor pattern, remove fence_view_async_tmem_load 2026-05-23 02:31:28 +00:00
93be84cdda fix: use paired atoms for correction_epilog + cute.copy TMA store 2026-05-23 02:26:57 +00:00
9916c14e56 diag: add CUDA_LAUNCH_BLOCKING for crash debug 2026-05-23 02:25:46 +00:00
ef44a12498 fix: inline epilogue_tma_store with inv_row_sum multiply using paired atoms 2026-05-23 02:24:36 +00:00
3195e805d6 fix: use cute.copy instead of cpasync.copy for TMA store 2026-05-23 02:23:16 +00:00
a49b6109b5 fix: correction_epilog with get_tmem_load_op paired atoms + direct TMA store 2026-05-23 02:19:41 +00:00
ed3f110866 diag: NO-OP TMEM round-trip test — load+store back unchanged 2026-05-23 02:15:28 +00:00
d4ccb20938 fix: inline epilogue with paired atoms + inv_row_sum normalize, no TMEM round-trip 2026-05-23 02:13:52 +00:00
a90b814221 fix: all epilogue warps do TMA store, no dynamic if inside method 2026-05-23 01:41:36 +00:00
e1e6f6fcb7 fix: correction_epilog with get_tmem_load_op paired atoms, no TMEM round-trip 2026-05-23 01:40:13 +00:00
6d4b406a70 fix: use attn_raw (not softmax'd) for unnorm computation 2026-05-23 01:36:27 +00:00
1d397c8b67 diag: skip kernel normalize, do Python-side normalize to isolate TMEM round-trip issue 2026-05-23 01:35:18 +00:00
1698f01308 diag: print expected unnorm P@V for comparison with raw kernel output 2026-05-23 01:28:32 +00:00
4248589c61 diag: skip final normalize, test raw PV output via epilogue_tma_store 2026-05-23 01:27:03 +00:00
13ed779aee fix: O rescale uses 2D register tensor pattern (matching CUTLASS correction_rescale) 2026-05-23 01:25:53 +00:00
34b9c39388 fix: pre-compute tmem_load_epi_atom in __call__, pass to kernel 2026-05-23 01:24:33 +00:00
4bb57ffc97 fix: index into TMA partitioned tensors for copy 2026-05-23 01:23:04 +00:00
21c12870f7 fix: use flat_divide+group_modes(0,2) for TMA store, matching CUTLASS 2026-05-23 01:22:22 +00:00
f4c474ced9 fix: use gC not tCgC for TMA partition, group modes 0-3 2026-05-23 01:20:52 +00:00
420ed0c5d8 fix: use tma_partition for TMA store in correction_epilog 2026-05-23 01:20:09 +00:00
2b41ebcec4 fix: replace TMEM round-trip normalize with CUTLASS correction_epilog pattern 2026-05-23 01:18:56 +00:00
81edcf0a4b diag: inv_row_sum=1.0 to test raw PV, n=128 only 2026-05-23 01:17:14 +00:00
84b728efb4 diag: test original code n=128+256 to confirm baseline 2026-05-23 01:13:29 +00:00
d04e847ac0 diag: disable O rescale properly, test n=128+256 baseline 2026-05-23 01:12:50 +00:00
405636f49a diag: test n=128 and n=256 both with rescale disabled 2026-05-23 01:12:00 +00:00
e5827d867c fix: indentation error in diag disable 2026-05-23 01:11:25 +00:00
c08564954b diag: disable O rescale to isolate the issue (n=256 only) 2026-05-23 01:11:00 +00:00
4cf6981c65 debug: add wide-search diagnostics for n=256 O rescale 2026-05-23 01:02:33 +00:00
18f88c395a 🚀 MULTI-TILE SOFTMAX + O RESCALE WORKING: n=128 cos 0.999998, n=256 cos 0.80
Fixed ALL loops to use self.n_kv_tiles (Python int) instead of
cute.size(gK, mode=[3]) which returned 1 for all n values.

Results:
  n=128: cos 0.999998  PASS (single tile, full softmax + normalize)
  n=256: cos 0.801156 (2 tiles, O rescale partially working)
  n=512: CUDA launch failure (pipeline can't cycle past kv_stage=2)

The n=256 improvement (0.71 → 0.80) confirms:
  1. TMA fix (None,0,None,0) loads both KV tiles correctly
  2. Softmax processes both tiles with online row_max/row_sum tracking
  3. O rescale (O *= acc_scale for kt > 0) is partially working
  4. Final normalize (O *= 1/row_sum) works correctly

Remaining:
  - n=256 cos 0.80 → 0.9999: O rescale precision issue
  - n≥384: pipeline cycling (kv_stage=2 can only hold 2 tiles)
  - Need to increase kv_stage or fix pipeline state cycling
2026-05-23 00:35:42 +00:00
77ac14e788 Debug: add row_sum/inv_row_sum printf at final normalize 2026-05-23 00:34:38 +00:00
94c29dc9df Fix ALL loops: use self.n_kv_tiles everywhere
The MMA loop (cutlass.range) and MMA consumer loop (range) also used
cute.size(gK, mode=[3]) which returns 1 for all n. Fixed all 3 loops:
1. TMA load loop (cutlass.range, line 215)
2. MMA consumer loop (range, line 231)
3. Softmax loop (range, line 324)

This was causing the deadlock — MMA only produced S[0] while softmax
waited for S[1].
2026-05-23 00:33:38 +00:00
5b3cb38281 Fix softmax loop: use self.n_kv_tiles not cute.size(gK, mode=[3])
cute.size(gK, mode=[3]) returns 1 for ALL n values — mode 3 is batch,
not KV tiles. self.n_kv_tiles = s_k // 128 is the correct Python int.
This is why softmax only processed kt=0 for all n.
2026-05-23 00:30:49 +00:00