@@ -106,9 +106,21 @@ def _nearest_kernel(
106106 best_idx = tl .zeros ((BLOCK_N ,), dtype = tl .int32 ) # Best y index.
107107
108108 if USE_BATCH :
109- batch_id = tl .load (batch_x_ptr + offs_n , mask = mask_x , other = 0 ) # Batch id per x.
110- left = tl .load (ptr_y_ptr + batch_id , mask = mask_x , other = 0 ) # y range start.
111- right = tl .load (ptr_y_ptr + batch_id + 1 , mask = mask_x , other = 0 ) # y range end.
109+ batch_id = tl .load (
110+ batch_x_ptr + offs_n ,
111+ mask = mask_x ,
112+ other = 0 ,
113+ ) # Batch id per x.
114+ left = tl .load (
115+ ptr_y_ptr + batch_id ,
116+ mask = mask_x ,
117+ other = 0 ,
118+ ) # y range start.
119+ right = tl .load (
120+ ptr_y_ptr + batch_id + 1 ,
121+ mask = mask_x ,
122+ other = 0 ,
123+ ) # y range end.
112124 else :
113125 left = 0 # Full y range.
114126 right = M
@@ -194,7 +206,11 @@ def _nearest_kernel(
194206 inv_y = tl .rsqrt (y_sq + EPS ) # 1/||y||.
195207 dist = 1.0 - acc * (inv_y [:, None ] * inv_x [None , :])
196208 else :
197- dist = tl .fma (- 2.0 , acc , y_sq [:, None ] + x_sq [None , :]) # L2^2 distance.
209+ dist = tl .fma (
210+ - 2.0 ,
211+ acc ,
212+ y_sq [:, None ] + x_sq [None , :],
213+ ) # L2^2 distance.
198214
199215 if full_y :
200216 valid = tl .broadcast_to (mask_x [None , :], (BLOCK_M , BLOCK_N ))
@@ -218,7 +234,11 @@ def _nearest_kernel(
218234 best_dist = tl .where (better , block_min , best_dist )
219235 best_idx = tl .where (better , block_idx , best_idx )
220236
221- tl .store (out_ptr + offs_n , best_idx .to (tl .int64 ), mask = mask_x ) # Write output.
237+ tl .store (
238+ out_ptr + offs_n ,
239+ best_idx .to (tl .int64 ),
240+ mask = mask_x ,
241+ ) # Write output.
222242
223243
224244@triton .autotune (
0 commit comments