cutlass icon indicating copy to clipboard operation
cutlass copied to clipboard

[QST]How to Handle Synchronization with Different Thread Counts for Producer and Consumer in CUTLASS?

Open ziyuhuang123 opened this issue 1 year ago • 2 comments

In scenarios where both producer and consumer threads exist, how can we achieve synchronization using CUTLASS's barrier.sync/arrive? I understand that in barrier.arrive(a, b), a represents the number of threads required to arrive, and b is the barrier_ID. However, the number of producer and consumer threads is often different.

In FlashAttention3, I saw this example: https://github.com/Dao-AILab/flash-attention/blob/0dfb28174333d9eefb7c1dd4292690a8458d1e89/hopper/mainloop_fwd_sm90_tma_gmma_ws.hpp#L651

Here, the a parameter includes the consumer thread count (256) plus the active threads in the producer (32). However, I don't understand why it is written this way.

ziyuhuang123 avatar Dec 18 '24 11:12 ziyuhuang123

This issue has been labeled inactive-30d due to no recent activity in the past 30 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed. This issue will be labeled inactive-90d if there is no activity in the next 60 days.

github-actions[bot] avatar Jan 17 '25 11:01 github-actions[bot]

@Junkai-Wu

hwu36 avatar Mar 04 '25 03:03 hwu36

The example you showed is a hopper warp specialized kernel where mma warp groups execute mma operations + epilogue operations. Therefore, when executing next mma operation, it has to make sure the last epilogue operation is finished and also the data from producer threads are ready. That's why the thread count it needs to wait is NumMmaThreads + NumProducerThreads.

Junkai-Wu avatar Mar 14 '25 07:03 Junkai-Wu

This issue has been labeled inactive-30d due to no recent activity in the past 30 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed. This issue will be labeled inactive-90d if there is no activity in the next 60 days.

github-actions[bot] avatar Apr 13 '25 08:04 github-actions[bot]

This issue has been labeled inactive-90d due to no recent activity in the past 90 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed.

github-actions[bot] avatar Jul 12 '25 08:07 github-actions[bot]