Skip to content

Commit c56ba0f

Browse files
authored
Pass tmem scalar fields as .ptr to TmemAllocator on SM100 (#2679)
The DSL now warns when a struct scalar is used directly as a pointer ("Use explicit struct.scalar.ptr for pointer instead"), so these fire on every tmem_holding_buf / dealloc mbar access. Just pass .ptr like the other SM100 kernels already do.
1 parent 82d6441 commit c56ba0f

8 files changed

Lines changed: 27 additions & 27 deletions

flash_attn/cute/flash_bwd_mla_dq_dqv_sm100.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ class SharedStorage:
354354
mbar_ptr_KV_cpasync: cute.struct.MemRange[cutlass.Int64, self.num_stages_KV * 2]
355355
mbar_ptr_load_kv_epi: cute.struct.MemRange[cutlass.Int64, 2]
356356
# Tmem holding buffer
357-
mbar_ptr_tmem_dealloc: cutlass.Int64
357+
tmem_dealloc_mbar: cutlass.Int64
358358
tmem_holding_buf: cutlass.Int32
359359
# Clc pointers
360360
clc_ptr: cute.struct.Align[
@@ -569,11 +569,11 @@ def kernel(
569569
)
570570
# ---- Tensor memory dealloc barrier init ----
571571
tmem = utils.TmemAllocator(
572-
storage.tmem_holding_buf,
572+
storage.tmem_holding_buf.ptr,
573573
barrier_for_retrieve=tmem_alloc_barrier,
574574
allocator_warp_id=self.epilogue_warp_ids[0],
575575
is_two_cta=False,
576-
two_cta_tmem_dealloc_mbar_ptr=storage.mbar_ptr_tmem_dealloc,
576+
two_cta_tmem_dealloc_mbar_ptr=storage.tmem_dealloc_mbar.ptr,
577577
)
578578

579579
# ---- Cluster arrive after barrier init ----

flash_attn/cute/flash_bwd_mla_sm100.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def mbar_struct(num_stages):
293293
self.num_stages_dPsum,
294294
]
295295
)
296-
mbar_ptr_tmem_dealloc_struct = Int64
296+
tmem_dealloc_mbar_struct = Int64
297297
tmem_holding_buf_struct = Int32
298298

299299
self.sched_stages = 1
@@ -314,7 +314,7 @@ class SharedStorage:
314314
mbar_ptr_dV_epi: mbar_ptr_dV_struct
315315
mbar_ptr_scaleP: mbar_ptr_scaleP_struct
316316
mbar_ptr_dPsum: mbar_ptr_dPsum_struct
317-
mbar_ptr_tmem_dealloc: mbar_ptr_tmem_dealloc_struct
317+
tmem_dealloc_mbar: tmem_dealloc_mbar_struct
318318
tmem_holding_buf: tmem_holding_buf_struct
319319
clc_mbar_ptr: cute.struct.MemRange[cutlass.Int64, clc_mbar_size]
320320
clc_response: cute.struct.MemRange[Int32, clc_response_size]
@@ -711,11 +711,11 @@ def kernel(
711711
num_threads=self.num_mma_threads + self.num_softmax_threads + self.num_epilogue_threads,
712712
)
713713
tmem = cutlass.utils.TmemAllocator(
714-
storage.tmem_holding_buf,
714+
storage.tmem_holding_buf.ptr,
715715
barrier_for_retrieve=tmem_alloc_barrier,
716716
allocator_warp_id=self.mma_warp_id,
717717
is_two_cta=self.use_2cta_instrs,
718-
two_cta_tmem_dealloc_mbar_ptr=storage.mbar_ptr_tmem_dealloc,
718+
two_cta_tmem_dealloc_mbar_ptr=storage.tmem_dealloc_mbar.ptr,
719719
)
720720

721721
# ==== Prefetch TMA descriptors ====

flash_attn/cute/flash_bwd_sm100.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ class SharedStorage:
782782
cutlass.Int64, self.dQaccum_reduce_stage // 2
783783
]
784784
tmem_holding_buf: Int32
785-
tmem_dealloc_mbar_ptr: cutlass.Int64
785+
tmem_dealloc_mbar: cutlass.Int64
786786

787787
# 2-CTA
788788
Qt_mbar_ptr: cute.struct.MemRange[cutlass.Int64, 2 * self.Q_stage]
@@ -861,7 +861,7 @@ class SharedStorage:
861861
cutlass.Int64, self.dQaccum_reduce_stage // 2
862862
]
863863
tmem_holding_buf: Int32
864-
tmem_dealloc_mbar_ptr: Int64
864+
tmem_dealloc_mbar: Int64
865865

866866
sQ: cute.struct.Align[
867867
cute.struct.MemRange[cute.Uint8, sQ_alloc_bytes],
@@ -1152,11 +1152,11 @@ def kernel(
11521152
* len((self.mma_warp_id, *self.compute_warp_ids, *self.reduce_warp_ids)),
11531153
)
11541154
tmem = cutlass.utils.TmemAllocator(
1155-
storage.tmem_holding_buf,
1155+
storage.tmem_holding_buf.ptr,
11561156
barrier_for_retrieve=tmem_alloc_barrier,
11571157
allocator_warp_id=self.mma_warp_id,
11581158
is_two_cta=self.use_2cta_instrs,
1159-
two_cta_tmem_dealloc_mbar_ptr=storage.tmem_dealloc_mbar_ptr,
1159+
two_cta_tmem_dealloc_mbar_ptr=storage.tmem_dealloc_mbar.ptr,
11601160
)
11611161

11621162
# UMMA producers and AsyncThread consumers

flash_attn/cute/flash_fwd_mla_sm100.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def mbar_struct(num_stages):
304304
self.num_stages_bitmask,
305305
]
306306
)
307-
mbar_ptr_tmem_dealloc_struct = Int64
307+
tmem_dealloc_mbar_struct = Int64
308308
tmem_holding_buf_struct = Int32
309309

310310
self.sched_stages = 1
@@ -325,7 +325,7 @@ class SharedStorage:
325325
mbar_ptr_V_cpasync: mbar_ptr_V_struct
326326
mbar_ptr_sm_stats: mbar_sm_stats_struct
327327
mbar_ptr_bitmask: mbar_bitmask_struct
328-
mbar_ptr_tmem_dealloc: mbar_ptr_tmem_dealloc_struct
328+
tmem_dealloc_mbar: tmem_dealloc_mbar_struct
329329
tmem_holding_buf: tmem_holding_buf_struct
330330
clc_mbar_ptr: cute.struct.MemRange[cutlass.Int64, clc_mbar_size]
331331
clc_response: cute.struct.MemRange[Int32, clc_response_size]
@@ -820,11 +820,11 @@ def kernel(
820820
num_threads=self.num_mma_threads + self.num_softmax_threads + self.num_epilogue_threads,
821821
)
822822
tmem = cutlass.utils.TmemAllocator(
823-
storage.tmem_holding_buf,
823+
storage.tmem_holding_buf.ptr,
824824
barrier_for_retrieve=tmem_alloc_barrier,
825825
allocator_warp_id=self.mma_warp_id,
826826
is_two_cta=self.use_2cta_instrs,
827-
two_cta_tmem_dealloc_mbar_ptr=storage.mbar_ptr_tmem_dealloc,
827+
two_cta_tmem_dealloc_mbar_ptr=storage.tmem_dealloc_mbar.ptr,
828828
)
829829

830830
# ==== Prefetch TMA descriptors ====

flash_attn/cute/flash_fwd_sm100.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ class SharedStorage:
694694
mbar_O_epi: cute.struct.MemRange[Int64, self.q_stage * 2]
695695
mbar_s0_s1_sequence: cute.struct.MemRange[Int64, 2 * 2]
696696
# Tmem dealloc cluster barrier
697-
tmem_dealloc_mbar_ptr: Int64
697+
tmem_dealloc_mbar: Int64
698698
# Tmem holding buffer
699699
tmem_holding_buf: Int32
700700
# Smem tensors
@@ -883,11 +883,11 @@ def kernel(
883883
)
884884
# Tensor memory dealloc barrier init
885885
tmem = cutlass.utils.TmemAllocator(
886-
storage.tmem_holding_buf,
886+
storage.tmem_holding_buf.ptr,
887887
barrier_for_retrieve=tmem_alloc_barrier,
888888
allocator_warp_id=self.mma_warp_id,
889889
is_two_cta=self.use_2cta_instrs,
890-
two_cta_tmem_dealloc_mbar_ptr=storage.tmem_dealloc_mbar_ptr,
890+
two_cta_tmem_dealloc_mbar_ptr=storage.tmem_dealloc_mbar.ptr,
891891
)
892892

893893
ThreadCooperativeGroup = partial(pipeline.CooperativeGroup, pipeline.Agent.Thread)

flash_attn/cute/sm100_hd256_2cta_fmha_backward_dkdvkernel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ class SharedStorage:
660660
cutlass.Int64, self.mma_compute_dKdV_stage * 2
661661
]
662662
tmem_holding_buf: cutlass.Int32
663-
tmem_dealloc_mbar_ptr: cutlass.Int64
663+
tmem_dealloc_mbar: cutlass.Int64
664664
clc_mbar_ptr: cute.struct.MemRange[cutlass.Int64, 2]
665665
clc_response: cute.struct.MemRange[Int32, 4]
666666
# Smem tensors
@@ -1029,11 +1029,11 @@ def dkdv_bwd(
10291029
)
10301030

10311031
tmem = utils.TmemAllocator(
1032-
storage.tmem_holding_buf,
1032+
storage.tmem_holding_buf.ptr,
10331033
barrier_for_retrieve=tmem_alloc_barrier,
10341034
allocator_warp_id=self.load_warp_id,
10351035
is_two_cta=True,
1036-
two_cta_tmem_dealloc_mbar_ptr=storage.tmem_dealloc_mbar_ptr,
1036+
two_cta_tmem_dealloc_mbar_ptr=storage.tmem_dealloc_mbar.ptr,
10371037
)
10381038

10391039
tmem.allocate(self.tmem_alloc_cols)

flash_attn/cute/sm100_hd256_2cta_fmha_backward_dqkernel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ class SharedStorage:
520520
cutlass.Int64, self.load_compute_sum_OdO_stage * 2
521521
]
522522
# A CTA-wide "TMEM lifetime" barrier used to safely deallocate TMEM after all users finish.
523-
tmem_dealloc_mbar_ptr: Int64
523+
tmem_dealloc_mbar: Int64
524524
# Tmem holding buffer
525525
tmem_holding_buf: Int32
526526
# CLC pipeline barriers and response buffer
@@ -751,11 +751,11 @@ def kernel(
751751

752752
# Tensor memory dealloc barrier init
753753
tmem = utils.TmemAllocator(
754-
storage.tmem_holding_buf,
754+
storage.tmem_holding_buf.ptr,
755755
barrier_for_retrieve=self.tmem_alloc_barrier,
756756
allocator_warp_id=self.epilogue_warp_ids[0],
757757
is_two_cta=True,
758-
two_cta_tmem_dealloc_mbar_ptr=storage.tmem_dealloc_mbar_ptr,
758+
two_cta_tmem_dealloc_mbar_ptr=storage.tmem_dealloc_mbar.ptr,
759759
)
760760
tmem.allocate(self.tmem_alloc_cols)
761761
tmem.wait_for_alloc()

flash_attn/cute/sm100_hd256_2cta_fmha_forward.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ class SharedStorage:
510510
Int64, self.mma_corr_stage * 2
511511
] # mma_corr_{producer,consumer}
512512
# A CTA-wide "TMEM lifetime" barrier used to safely deallocate TMEM after all users finish.
513-
tmem_dealloc_mbar_ptr: Int64
513+
tmem_dealloc_mbar: Int64
514514
# Tmem holding buffer
515515
tmem_holding_buf: Int32
516516
# CLC pipeline barriers and response buffer
@@ -676,11 +676,11 @@ def kernel(
676676
).make_participants()
677677
# Tensor memory dealloc barrier init
678678
tmem = utils.TmemAllocator(
679-
storage.tmem_holding_buf,
679+
storage.tmem_holding_buf.ptr,
680680
barrier_for_retrieve=self.tmem_alloc_barrier,
681681
allocator_warp_id=self.correction_warp_ids[0],
682682
is_two_cta=True,
683-
two_cta_tmem_dealloc_mbar_ptr=storage.tmem_dealloc_mbar_ptr,
683+
two_cta_tmem_dealloc_mbar_ptr=storage.tmem_dealloc_mbar.ptr,
684684
)
685685
tmem.allocate(self.tmem_alloc_cols)
686686
tmem.wait_for_alloc()

0 commit comments

Comments
 (0)