cuda infinite kernel

前端 未结 2 1320
广开言路
广开言路 2020-12-21 06:58

I am working on an application for which it is necessary to run a CUDA kernel indefinitely. I have one CPU thread that writes stg on a list and gpu reads that list and reset

相关标签:
2条回答
  • 2020-12-21 07:32

    As already pointed out by @Greg Smith, CUDA compiler does not generate proper assembly for infinite loops. And of course there are certain situations when it's a perfect solution, e.g. running a background service kernel, which receives updates from host, pushed over host-mapped memory.

    One workaround, which works as of CUDA 9.2:

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

    Doing infinite loop inside a divergent branch is obviously not a good idea. Other than that, improper handling of while (1) construct IMO is definitely a bug.

    0 讨论(0)
  • 2020-12-21 07:48

    The CUDA programming language and the CUDA architecture do not currently support infinite kernels. I suggest you consider Roger's suggestion.

    If you want to pursue this I suggest you add the following debug code to your kernel:

    1. Increment a variable in pinned memory every N clocks (may want a different location for each SM) and,
    2. Periodically read a memory location that can be updated by CPU to tell the kernel to exit.

    This is a software watchdog.

    You can use clock() or clock64() to control how often you do (1) and (2).

    You can use cuda-gdb to debug your problem.

    Infinite loops are not supported in the language. The compiler may be stripping code. You may want to review the PTX and SASS. If the compiler is generating bad code you can fake it out by making the compiler think there is a valid exit condition.

    0 讨论(0)
提交回复
热议问题