Remove host syncs from compute_dacs_segsum_triton_varlen - #969
Conversation
Remove host syncs from `compute_dacs_segsum_triton_varlen`
|
removing host syncs is great for throughput. any leftover .item()/.cpu() calls in the varlen path worth grepping for? |
|
Good call, I grepped the varlen path on this branch. The inference/forward path is now sync-free: |
Problem
The chunk-mapping construction loops over packed sequences reading scalars
from GPU tensors element by element:
That is
2*num_sequences + 1GPU→CPU synchronizations plus2*num_sequencestiny slice-fill kernels per call. Each.item()stallsthe CPU on the GPU stream. Under packed-varlen inference serving this runs
once per layer per prefill batch: with 29 mamba3 layers and 64 packed prompts
that is ~3,700 pipeline stalls (~100–200 ms) per prefill wave, dominating
time-to-first-token. Varlen training forwards pay the same pattern once per
layer per micro-batch.
Fix — fully vectorized on device, zero syncs
Sequence
iowns the contiguous global chunk slots[cu[i]//C + i, cu[i]//C + i + len_i//C + 1). The starts are strictlyincreasing (
floor(a+b) >= floor(a) + floor(b)), so the owner of slotgissearchsorted(range_starts, g, right=True) - 1, slots at/after the owner'srange end are inactive padding, and the local chunk index is
g - range_starts[owner]:The inactive-slot sentinel (
ceil(len_0 / C), same as before) stays adevice-side scalar. ~7 small kernels replace the loop; no
.item()/.tolist()anywhere, so the call no longer serializes the CPU against the GPU stream —
which also matters under async scheduling, where any sync blocks pipelining
of the next step's host work.
The old per-sequence overflow assert is dropped: by the same floor
inequality the last range end is always
<= nchunks, so it could never fire.Validation / measurements
lengths exactly multiple of C, single-token sequences, mixed lengths, and
32 packed sequences.
our integration layer, prefill syncs dropped ~520 → ~7 per 8-prompt batch
and TTFT at 256 concurrent requests dropped 1.31 s → 0.85 s.