Using the __syncthreads() device function

In our prior example of Conway's Game of Life, our kernel only updated the lattice once for every time it was launched by the host. There are no issues with synchronizing all of the threads among the launched kernel in this case, since we only had to work with the lattice's previous iteration that was readily available.

Now let's suppose that we want to do something slightly differentwe want to re-write our kernel so that it performs a certain number of iterations on a given cell lattice without being re-launched over and over by the host. This may initially seem triviala naive solution would be to just put an integer parameter to indicate the number of iterations and a for loop in the inline ...

Get Hands-On GPU Programming with Python and CUDA now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.