Over 60 trainings all over Europe for universities and industryOn-site trainings on the whole range of GPU computing technologiesEach lecture accompanied with a practical session on remote GPU clusterBest recipes of GPU code optimization, based on our 5-year development experienceWe have multiple training programs and even books! Check out our catalogue here.

How to get infinite loops to work in CUDA

Category: CUDA Published: Tuesday, 12 June 2018

Surprisingly, the CUDA compiler does not handle infinite loops properly:

while(1)
{
  ...
}

For instance, the loop above will be completely eliminated from the resulting assembly, along with its contents. This situation seems to be known at least since 2012.

There are certain situations where infinite loop on GPU is required, such as running a background service with configuration updates periodically sent from host over host-mapped memory.

One solution to enforce infinite loop is:

volatile int infinity = 1;
while (infinity)
{
  ...
}
Hits: 363