@@ -84,6 +84,7 @@ template <bool UsePDL>
8484__device__ __forceinline__ void pdl_wait_primary () {
8585#if defined(__CUDA_ARCH__) && __CUDA_ARCH__ >= 900
8686 if constexpr (UsePDL) {
87+ // PDL may start this grid early, so this must precede its first global load.
8788 asm volatile (" griddepcontrol.wait;" ::: " memory" );
8889 }
8990#endif
@@ -176,6 +177,8 @@ __global__ __launch_bounds__(kFusedQBlockSize, 16) void fused_q_norm_rope_kernel
176177 const uint32_t total_works = params.batch_size * params.num_q_heads ;
177178 if (work_id >= total_works) return ;
178179
180+ pdl_wait_primary<UsePDL>();
181+
179182 const uint32_t batch_id = work_id / params.num_q_heads ;
180183 const uint32_t head_id = work_id % params.num_q_heads ;
181184 const auto * input_ptr =
@@ -186,8 +189,6 @@ __global__ __launch_bounds__(kFusedQBlockSize, 16) void fused_q_norm_rope_kernel
186189
187190 __shared__ Storage rope_storage[kFusedQNumWarps ][kRopeVecs ];
188191
189- pdl_wait_primary<UsePDL>();
190-
191192 Storage input_vec[kLocalSize ];
192193#pragma unroll
193194 for (int i = 0 ; i < kLocalSize ; ++i) {
@@ -260,13 +261,13 @@ __global__ __launch_bounds__(kFusedKBlockSize, 8) void fused_k_norm_rope_flashml
260261 const uint32_t work_id = blockIdx .x ;
261262 if (work_id >= params.batch_size ) return ;
262263
264+ pdl_wait_primary<UsePDL>();
265+
263266 const auto * input_ptr = params.kv + work_id * params.kv_stride_batch ;
264267 const int32_t position = static_cast <int32_t >(static_cast <const PosT*>(params.positions )[work_id]);
265268 const int32_t out_loc = params.out_loc [work_id];
266269 const float * freqs_cis = params.freqs_cis + position * kMainRopeDim ;
267270
268- pdl_wait_primary<UsePDL>();
269-
270271 const Storage input_vec = reinterpret_cast <const Storage*>(input_ptr)[tx];
271272 const Storage weight_vec = reinterpret_cast <const Storage*>(params.kv_weight )[tx];
272273 float2 data;
@@ -341,14 +342,14 @@ __global__ __launch_bounds__(kFusedQBlockSize, 16) void fused_q_indexer_rope_had
341342 const uint32_t total_works = params.batch_size * params.num_heads ;
342343 if (work_id >= total_works) return ;
343344
345+ pdl_wait_primary<UsePDL>();
346+
344347 const uint32_t batch_id = work_id / params.num_heads ;
345348 const int32_t position = static_cast <int32_t >(static_cast <const PosT*>(params.positions )[batch_id]);
346349 const auto * input_ptr = params.q_input + static_cast <int64_t >(work_id) * kIndexerHeadDim ;
347350 const float * freqs_cis = params.freqs_cis + position * kIndexerRopeDim ;
348351 const bool is_rope_lane = lane_id >= kWarpThreads - kRopeVecs ;
349352
350- pdl_wait_primary<UsePDL>();
351-
352353 const float weight_value = __bfloat162float (params.weight [work_id]);
353354 const Storage input_vec = reinterpret_cast <const Storage*>(input_ptr)[lane_id];
354355 Float4 data;
0 commit comments