A decode step is schedule(N) -> forward(N) -> sample(N) -> post_process(N). Scheduling and post-processing run on the CPU, and the naive loop leaves the GPU idle during both. The asynchronous loop runs the CPU one step ahead and one step behind: while the GPU runs step N, the CPU schedules and launches step N + 1 and post-processes step N - 1. Simulate both loops.
simulate_decode_loop(n_steps, t_sched, t_fwd, t_sample, t_post, t_launch, mode)
mode is "serial" or "async".N takes t_sched + t_fwd + t_sample + t_post and its tokens are emitted when its post-processing ends.0 (t_sched + t_launch); the GPU runs a step for t_fwd + t_sample starting when both it is free and the step has been launched. Then for each step N in order: if N + 1 exists, the CPU spends t_sched + t_launch scheduling and launching it (the GPU may start it as soon as it is free and launched); if N - 1 exists, the CPU post-processes it, which can start only when both the CPU is free and the GPU has finished step N - 1, and takes t_post; emission of step N - 1 is when that ends. After the loop the CPU post-processes the last step the same way.{"emit_times": [...], "makespan": ..., "gpu_idle_frac": ..., "mean_step": ...}: emission time per step, total time, 1 - gpu_busy / makespan with gpu_busy = n_steps * (t_fwd + t_sample), and the mean gap between consecutive emissions (None for a single step). Round every number to 4 decimals.cpu and gpu_free, and a list of GPU completion times; every event is a max of the clocks it depends on plus a duration.