What Is SIMT Branch Divergence? CUDA Warps and AMD Wavefronts
SIMT branch divergence occurs when threads in one GPU execution group choose different conditional paths based on their data. If only some lanes can work on a particular path, the other lanes may be idle while that path runs, reducing useful throughput. This does not by itself mean the result is incorrect: the actual cost and execution method depend on the GPU architecture and compiler.
What Is SIMT Branch Divergence? CUDA Warps and AMD Wavefronts
SIMT branch divergence occurs when threads in one GPU execution group choose different conditional paths based on their data. If only some lanes can work on a particular path, the other lanes may be idle while that path runs, reducing useful throughput. This does not by itself mean the result is incorrect: the actual cost and execution method depend on the GPU architecture and compiler.
What happens inside one execution group?
GPU kernels are commonly written so that each thread performs the same kind of operation on its own data. This model is called SIMT (Single Instruction, Multiple Threads). Unlike a CPU vector instruction, where software may operate on an explicitly sized vector, the programmer writes thread-level code and the GPU schedules threads in groups such as warps or wavefronts.
If every thread in a group has the same condition, only one path is needed. If input values split the condition, more than one path may be needed. NVIDIA's CUDA guide describes a divergent warp as executing the paths that are taken while threads not on the current path are inactive. AMD's HIP hardware documentation says that predication handles execution-mask updates for thread divergence. It is therefore inaccurate to claim that every GPU serializes branch paths in the same order using the same machine instructions. The shared performance question is how many lanes do useful work on each path and what the compiled code actually does.
The diagram below is a conceptual example: four of eight lanes choose path A and the other four choose path B. It is not a hardware measurement, a real lane width, or a trace of instruction order.
Condition lane 0 1 2 3 4 5 6 7
Choice A A A A B B B B
Work on path A ● ● ● ● · · · ·
Work on path B · · · · ● ● ● ●
● = works on this path · = inactive on this pathIf both paths perform substantial computation, useful lane utilization may be low relative to the work required. Even one lane choosing a path can make that path's instructions and memory accesses necessary. On the other hand, divergence may have little impact when the branch body is short, when the compiler turns the choice into predicated instructions, or when the data does not split an execution group into several paths. The mere presence of an if statement is not proof that a kernel is slow.
Execution groups also run independently. If every thread in one group chooses A and every thread in the next chooses B, there is no split within either group; the difference between groups alone is not branch divergence. Analyze the distribution of conditions within each group, not just the overall percentage of true and false inputs.
Do CUDA warps and AMD wavefronts have the same width?
The concepts are related, but do not carry one vendor's group width or synchronization details over to another GPU. The NVIDIA CUDA Programming Guide defines a warp as 32 threads. AMD HIP commonly calls its group a wavefront, and warpSize can vary with the target device. The current HIP language extensions documentation says NVIDIA devices return 32, AMD gfx9 returns 64, and gfx10 or later returns 32. It recommends checking with hipDeviceGetAttribute() or hipDeviceGetProperties() on the host. Check the actual product, target architecture, and compiler settings you use.
| Aspect | NVIDIA CUDA | AMD HIP | Portability check |
|---|---|---|---|
| Common group name | warp | wavefront (also called warp in some docs) | Shared terminology does not mean identical hardware |
| Group width | CUDA warp has 32 threads | May vary by architecture | Do not hardcode 32 or 64 as a universal rule |
| Branch explanation | Threads not taking the current path may be inactive | Official hardware docs connect divergence-mask handling with predication | Do not infer identical instructions or cost across implementations |
| Direct lane cooperation | Execution and synchronization assumptions vary by generation | Check cross-lane operations, width, and mask constraints | Follow the target API contract and active-thread requirements |
NVIDIA compute capability 7.0 and later supports Independent Thread Scheduling. Older code that assumes every thread in a warp always executes in lockstep at every instruction must therefore be reviewed. For code that exchanges data within a warp or performs a reduction without synchronization, follow CUDA's explicit synchronization guidance. HIP code must likewise respect the width, mask format, and participation rules of shuffle, vote, and other lane-cooperation operations. An ordinary per-thread if and a hand-written lane synchronization protocol are different correctness concerns.
Compare branch behavior and reordering cost with a pixel example
Illustrative assumption: Assume consecutive lanes process neighboring pixels. Suppose a kernel applies a simple correction A or a more complex correction B depending on pixel brightness. If neighboring pixels have similar brightness, lanes in a group may tend to choose the same path. If brightness varies randomly, A and B may be mixed within a group, so work for both paths may be needed. This is an explanatory scenario, not a measurement on a particular GPU.
Sorting or grouping pixels by path could make conditions more uniform within groups, but classification, data movement, extra memory reads and writes, and restoring output order all cost time. Reusing the reordered data in several later stages may amortize that cost; a small kernel that runs once may become slower. Compare path work, output-order restoration, memory locality, and end-to-end application time together.
A practical order for checking portability and performance
**Fix the target.** Record the GPU model, compilation target, runtime, and relevant settings. For HIP, check the actual device's `warpSize`; for CUDA, use the 32-thread warp model and separately review generation-specific synchronization rules.
**Inspect condition distribution by group.** Do not stop at the overall true/false ratio. Check whether neighboring threads' data choose the same path, and account for block boundaries and valid lanes in the final partial group.
**Confirm there is a performance problem.** Use compiler output and a profiler appropriate to the target to see whether the branch matters to application runtime and how the compiler translated it. Metrics with similar names from different tools or GPUs need not mean the same thing.
**Compare one change at a time.** Try path-based partitioning, a data-layout change, or a simpler path separately. Include the time and memory cost of reordering or temporary buffers.
**Recheck correctness and total runtime.** Validate results on the same inputs and repeat application-level timing without profiler overhead. For lane-cooperation code, recheck active masks and synchronization conditions too.
The goal is not to assume that eliminating divergence always makes a program faster. Determine how much paths are mixed within each execution group and whether those paths are actually a bottleneck. For cross-vendor code, make width, mask, and synchronization assumptions explicit and follow the contracts for the target device.
Sources
[NVIDIA, CUDA C++ Programming Guide — SIMT Execution Model and Independent Thread Scheduling](https://docs.nvidia.com/cuda/cuda-programming-guide/03-advanced/advanced-kernel-programming.html)
[AMD, HIP C++ language extensions — `warpSize`](https://rocm.docs.amd.com/projects/HIP/en/latest/how-to/hip_cpp_language_extensions.html)
[AMD, HIP hardware implementation — Branch unit and predication](https://rocm.docs.amd.com/projects/HIP/en/latest/understand/hardware_implementation.html)
[AMD, HIP hardware features — Architecture-specific execution features](https://rocm.docs.amd.com/projects/HIP/en/latest/reference/hardware_features.html)
[NVIDIA, CUDA C++ Best Practices Guide — Control Flow and Branch Predication](https://docs.nvidia.com/cuda/cuda-c-best-practices-guide/)
References
- NVIDIA CUDA C++ Programming Guide — SIMT Execution Model and Independent Thread Scheduling
- NVIDIA CUDA C++ Best Practices Guide — Control Flow and Branch Predication
- AMD HIP C++ language extensions — warpSize
- AMD HIP hardware implementation — Branch unit and predication
- AMD HIP hardware features — Architecture-specific execution features