# Thread Divergence

**URL:** <https://forums.developer.nvidia.com/t/thread-divergence/5679>\
**Category:** CUDA Programming and Performance\
**Created:** [September 27, 2008, 1:47pm UTC](https://forums.developer.nvidia.com/t/thread-divergence/5679 "2008-09-27T13:47:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pdavis68](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@pdavis68](https://forums.developer.nvidia.com/u/pdavis68)\
**Post date:** [September 27, 2008, 1:47pm UTC](https://forums.developer.nvidia.com/t/thread-divergence/5679/1 "2008-09-27T13:47:53Z")

</div>

I have a question regarding thread divergence: According to the documentation, every time a thread diverges, it has to be run separately from other threads. I get that and it makes sense. My question is, let’s say half of my threads diverge together down the same execution path.

Does that mean that the threads will now run as two groups or will it be what’s left of the individual group, plus a bunch of individual threads, each executed separately, that diverged?

The latter makes no sense to me, but the documentation is unclear and I’m just curious.

I guess my question is, do divergent threads get grouped to run together if they diverge together.

Thanks.

Pete

---

<div class="post-metadata">

**Author:** ![E.D\_Riedijk](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@E.D\_Riedijk](https://forums.developer.nvidia.com/u/E.D_Riedijk)\
**Post date:** [September 27, 2008, 7:44pm UTC](https://forums.developer.nvidia.com/t/thread-divergence/5679/2 "2008-09-27T19:44:41Z")

</div>

> [@](#):
>
> I have a question regarding thread divergence: According to the documentation, every time a thread diverges, it has to be run separately from other threads. I get that and it makes sense. My question is, let’s say half of my threads diverge together down the same execution path.
> 
> Does that mean that the threads will now run as two groups or will it be what’s left of the individual group, plus a bunch of individual threads, each executed separately, that diverged?
> 
> The latter makes no sense to me, but the documentation is unclear and I’m just curious.
> 
> I guess my question is, do divergent threads get grouped to run together if they diverge together.
> 
> Thanks.
> 
> Pete
> 
> [snapback]444885[/snapback]

Don’t think threads, think warps. If your first 32 threads take one code path, and the next 32 threads another, you have no divergence.

Thread (0 - 31)+N\*32 are always in the same warp.

If you have divergence within a warp, that warp runs both code paths, with the appropriate threads set inactive.

---

<div class="post-metadata">

**Author:** ![pdavis68](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@pdavis68](https://forums.developer.nvidia.com/u/pdavis68)\
**Post date:** [September 27, 2008, 10:02pm UTC](https://forums.developer.nvidia.com/t/thread-divergence/5679/3 "2008-09-27T22:02:21Z")

</div>

Ok, I get it. Thanks.
