[QST] Question about different number of N in warpgroup_wait<N> in existing code
Hello,
I am fixing code for my own functionality and have some questions about wargroup_wait called in mma function of sm90_mma_tma_gmma_x_warpspecialized_x.hpp files. Why do below files use different amount of N for warpgroup_wait
- sm90_mma_tma_gmma_rs_warpspecialized_mixed_input.hpp : warpgroup_wait<K_BLOCK_MAX - 1>();
- sm90_mma_tma_gmma_ss_warpspecialized.hpp : warpgroup_wait<K_PIPE_MMAS>();
- sm90_mma_tma_gmma_rs_warpspecialized.hpp : warpgroup_wait<2>();
Another question is why is a single thread in a warp elected to process load functions? Are all other 31 threads idle? For example, below is the code for load function in "sm90_mma_tma_gmma_rs_warpspecialized.hpp".
load(...) { int lane_predicate = cute::elect_one_sync(); if (lane_predicate) { ... } }
Thank you!
Why do below files use different amount of N for warpgroup_wait?
This is related to the nature of pipelining in each mainloop.
- In
ss_warpspecialized, the granularity of wgmma batching is one K-tile, andK_PIPE_MMAScontrols how many K-tiles worth of MMA instructions can be in-flight when we advance to the next tile. Usually it is set to 1, meaning we start queuing MMAs for next K-tile while the previous one is being computed. - In
rs_warpspecializedandrs_warpspecialized_mixed_inputwe do more fine-grained pipelining in order to overlap additional work (smem->RF loading, transposition, conversion/scaling) with MMA, so the granularity of a commit group is one K-block (which is the K-shape of one MMA instruction, usually there are 4 K-blocks per K-tile). The exact wait numbers are determined by how many K-blocks worth of registers are being modified by overlapped work. For example, inrs_warpspecialized2 K-blocks are being modified (one by loading, one by transpose), so the remaining 2 register buffers can be consumed by outstanding MMA instructions. Inrs_warpspecialized_mixed_inputonly one K-block register buffer is being used in loading and conversion, while the remainingK_BLOCK_MAX - 1are safe to be consumed by MMA.
Another question is why is a single thread in a warp elected to process load functions? Are all other 31 threads idle?
Yes, TMA loads only need to be issued by a single thread
Thanks for you answer!
Can I ask a few more questions? I really appreciate your help.
- For example in below code for
sm90_mma_tma_gmma_rs_warpspecialized.hpp,
CUTLASS_PRAGMA_UNROLL for (int k_block = 0; k_block < size<2>(tCrA) - 1; ++k_block) { copy(smem_tiled_copy_A, tCsA_copy_view(_,_,k_block + 1,read_stage), tCrA_copy_view(_,_,k_block + 1)); transpose.synchronize(k_block); transpose(sB, gmma_sB, read_stage, k_block + 1); warpgroup_arrive(); // (V,M) x (V,N) => (V,M,N) cute::gemm(tiled_mma, tCrA(_,_,k_block), tCrB(_,_,k_block,read_stage), accum); if(k_block == 0) { tiled_mma.accumulate_ = GMMA::ScaleOut::One; } warpgroup_commit_batch(); } warpgroup_wait<2>();
After cute::gemm operation, transpose for k_block should have been already done. So isn't only k_block + 1 being modified? So can't there be K_BLOCK_MAX - 1 ongoing MMAs? Why are 2 blocks are being modified?
And in CUTLASS 3.6, for sm90_mma_tma_gmma_rs_warpspecialized_mixed_input.hpp, aren't they modifying k_block + 1 and k_block + 2 like code below so there only can be K_BLOCK_MAX - 2 ongoing MMAs? But they still use warpgroup_wait<K_BLOCK_MAX - 1>();.
// Unroll the K mode manually to set scale D to 1 CUTLASS_PRAGMA_UNROLL for (int k_block = 0; k_block < K_BLOCK_MAX; ++k_block) { if (k_block < K_BLOCK_MAX - 2) { // prefetch next block copy_A_and_extra_info(smem_tiled_copy_A, tCsA, tCrA_copy_view, partitioned_extra_info, copy_partitions_extra_info, k_block + 2, read_stage); } if (k_block < K_BLOCK_MAX - 1) { transform_A_kblock(tCrA_load, tCrA_mma, partitioned_extra_info, k_block + 1); } warpgroup_arrive(); // (V,M) x (V,N) => (V,M,N) cute::gemm(tiled_mma, tCrA_mma(_,_,k_block), tCrB(_,_,k_block,read_stage), accum); tiled_mma.accumulate_ = GMMA::ScaleOut::One; warpgroup_commit_batch(); }
- Also, I cannot understand how can there be multiple outstanding MMAs. For example for
sm90_mma_tma_gmma_rs_warpspecialized_mixed_input.hpp, how can there be K_BLOCK_MAX - 1 (for example 3) outstanding MMAs anyway? We are using CUDA core for conversion operation and as far as I know CUDA core and tensor core operations cannot be launched together in terms of single warp. So in terms of warp group perspective, shouldn't there be always 1 outstanding MMA? Also, can multiple MMAs be inflight in terms of HW?
I find in my own modification of inserting bitwise operation before MMA in sm90_mma_tma_gmma_rs_warpspecialized.hpp (prefetching k_block + 1 only) to be breaking pipeline even if ALU utilization is lower than the tensor core utilization. My tensor core utilization drops 60~70% and so as my throughput. I presumed this to be due to the inability of tensor core and cuda core operations to be working at the same time at the same warp. I would find question 2 helpful to be answered to resolve my issues.
After cute::gemm operation, transpose for k_block should have been already done. So isn't only k_block + 1 being modified? So can't there be K_BLOCK_MAX - 1 ongoing MMAs? Why are 2 blocks are being modified?
Yes, perhaps my explanation above is not entirely accurate. Summoning @depaulmillz who has probably looked at it a lot closer than I have.
Also, I cannot understand how can there be multiple outstanding MMAs. For example for sm90_mma_tma_gmma_rs_warpspecialized_mixed_input.hpp, how can there be K_BLOCK_MAX - 1 (for example 3) outstanding MMAs anyway? We are using CUDA core for conversion operation and as far as I know CUDA core and tensor core operations cannot be launched together in terms of single warp. So in terms of warp group perspective, shouldn't there be always 1 outstanding MMA? Also, can multiple MMAs be inflight in terms of HW?
wgmma.mma_async is an asynchronous instruction for which the tensor core has its own internal execution pipeline. Therefore we can issue multiple MMA instructions that will be queued and executed in order, and to achieve peak throughput the pipeline must always be non-empty. That is why the programming model has warpgoup_commit_batch, warpgroup_wait etc. CUDA cores can run conversion and other math simultaneously with tensor core executing MMAs.
I find in my own modification of inserting bitwise operation before MMA in sm90_mma_tma_gmma_rs_warpspecialized.hpp (prefetching k_block + 1 only) to be breaking pipeline even if ALU utilization is lower than the tensor core utilization. My tensor core utilization drops 60~70% and so as my throughput. I presumed this to be due to the inability of tensor core and cuda core operations to be working at the same time at the same warp. I would find question 2 helpful to be answered to resolve my issues.
Depending on the number of bitwise instructions added, you could be bound by ALU throughput, in which case it is expected that the tensor core utilization would drop - CUDA cores simply cannot provide input data for MMAs fast enough. Optimizing the number of instructions used for conversion/scaling of inputs is an active area of research.
Thank you for your answer!
To clarify my understanding, can cuda and tensor core operations be scheduled simulatenously within same warp? Is it better if it is scheduled between different warps? Why can warp specialization be any better than multi stage pipeline if those operations could be scheduled together within same warp?
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.
Why do below files use different amount of N for warpgroup_wait?
This is related to the nature of pipelining in each mainloop.
- In
ss_warpspecialized, the granularity of wgmma batching is one K-tile, andK_PIPE_MMAScontrols how many K-tiles worth of MMA instructions can be in-flight when we advance to the next tile. Usually it is set to 1, meaning we start queuing MMAs for next K-tile while the previous one is being computed.- In
rs_warpspecializedandrs_warpspecialized_mixed_inputwe do more fine-grained pipelining in order to overlap additional work (smem->RF loading, transposition, conversion/scaling) with MMA, so the granularity of a commit group is one K-block (which is the K-shape of one MMA instruction, usually there are 4 K-blocks per K-tile). The exact wait numbers are determined by how many K-blocks worth of registers are being modified by overlapped work. For example, inrs_warpspecialized2 K-blocks are being modified (one by loading, one by transpose), so the remaining 2 register buffers can be consumed by outstanding MMA instructions. Inrs_warpspecialized_mixed_inputonly one K-block register buffer is being used in loading and conversion, while the remainingK_BLOCK_MAX - 1are safe to be consumed by MMA.Another question is why is a single thread in a warp elected to process load functions? Are all other 31 threads idle?
Yes, TMA loads only need to be issued by a single thread
Thank you for your answer, but I still don't understand why RS must use wait<2>. I have drawn the following timing diagram and I'm not sure if it's correct.
Why do below files use different amount of N for warpgroup_wait?
This is related to the nature of pipelining in each mainloop.
- In
ss_warpspecialized, the granularity of wgmma batching is one K-tile, andK_PIPE_MMAScontrols how many K-tiles worth of MMA instructions can be in-flight when we advance to the next tile. Usually it is set to 1, meaning we start queuing MMAs for next K-tile while the previous one is being computed.- In
rs_warpspecializedandrs_warpspecialized_mixed_inputwe do more fine-grained pipelining in order to overlap additional work (smem->RF loading, transposition, conversion/scaling) with MMA, so the granularity of a commit group is one K-block (which is the K-shape of one MMA instruction, usually there are 4 K-blocks per K-tile). The exact wait numbers are determined by how many K-blocks worth of registers are being modified by overlapped work. For example, inrs_warpspecialized2 K-blocks are being modified (one by loading, one by transpose), so the remaining 2 register buffers can be consumed by outstanding MMA instructions. Inrs_warpspecialized_mixed_inputonly one K-block register buffer is being used in loading and conversion, while the remainingK_BLOCK_MAX - 1are safe to be consumed by MMA.Another question is why is a single thread in a warp elected to process load functions? Are all other 31 threads idle?
Yes, TMA loads only need to be issued by a single thread
Or maybe, timing diagram should be like this? I have tested, that wg_wait =1 2 3 are all correct, just =2 is the fastest, but not fast that much, just 10 TFLOPS faster....But the parameters are so much, can we be confident that 2 is the best for RS case? I guess we still need to try on each MNK case?
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.