Skip to content

Commit 555569b

Browse files
samremescursoragent
andcommitted
Optimize FlyDSL TopK row barrier
Co-authored-by: Cursor <[email protected]>
1 parent 48f0a93 commit 555569b

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

‎aiter/ops/flydsl/kernels/topk_per_row_decode_aiter_persistent.py‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,22 @@ def global_atomic_xchg_i32(elem_i32, value, ordering):
306306
).result
307307

308308
def global_atomic_load_i32_acquire(elem_i32):
309-
return global_atomic_add_i32(elem_i32, c_zero, llvm.AtomicOrdering.acquire)
309+
# True acquire load of the slot rather than an atomicAdd(slot, 0)
310+
# read-modify-write. The RMW form carried wave-reduce scaffolding
311+
# (mbcnt / readfirstlane / exec-mask toggling) on every spin
312+
# iteration; a plain acquire load (matching the AITER HIP
313+
# __atomic_load_n(..., __ATOMIC_ACQUIRE) spin) reads the L2-coherent
314+
# value without it. Kept volatile + agent-scoped acquire so it is not
315+
# hoisted/cached and still establishes the cross-CTA happens-before
316+
# with the release publish below.
317+
return llvm.LoadOp(
318+
T.i32,
319+
global_i32_ptr(elem_i32),
320+
alignment=4,
321+
volatile_=True,
322+
ordering=llvm.AtomicOrdering.acquire,
323+
syncscope="agent",
324+
).result
310325

311326
def lds_atomic_add_i32(base, elem_i32, value):
312327
return llvm.AtomicRMWOp(
@@ -337,7 +352,6 @@ def spin_until_slot_ge(elem_i32, target):
337352
def row_barrier(token: int):
338353
token_value = fx.Int32(token)
339354
target_arrivals = ArithValue(token_value) * ArithValue(active_parts)
340-
rocdl.s_waitcnt(0)
341355
gpu.barrier()
342356
if tid == ArithValue(c_zero):
343357
prev = global_atomic_add_i32(

0 commit comments

Comments
 (0)