warp.tile_stack_pop#
- warp.tile_stack_pop(s: Any) tuple[Any, int]#
Kernel
Pop a value from a tile stack (cooperative).
All threads in the block must call this function. Each calling thread races for a slot.
- Parameters:
s – The tile stack
- Returns:
A tuple
(value, slot)wherevalueis the popped element (or the default value if the stack was empty) andslotis the index of the popped element (the slot it previously occupied), or-1if the stack was empty. When non-negative,slotlies in[0, capacity-1]. Consistent withtile_stack_push()which also uses-1to indicate failure.
Example
CAP = wp.constant(8) @wp.kernel def pop_kernel(out: wp.array[int]): _i, j = wp.tid() s = wp.tile_stack(capacity=CAP, dtype=int) wp.tile_stack_push(s, j * 10, j < 4) val, slot = wp.tile_stack_pop(s) if slot != -1: out[slot] = val out = wp.full(8, -1, dtype=int) wp.launch_tiled(pop_kernel, dim=[1], inputs=[out], block_dim=8) vals = out.numpy() print(sorted(vals[vals >= 0].tolist()))
[0, 10, 20, 30]