CUDA Debugging Tutorial | Cuda Education

A brief outline of how to go about debugging you CUDA program.

  • Probably the best way in my opinion is to use printf functionality to print out variable and system state to the console.
    • printf can be used in host code and device code, assuming a compute capability of 3.0 (i think) or higher.
    • Make sure that you are not printing too much to the printf buffer that you start overwriting old information with newer information and therefore reading misleading information.
    • The code below prints out the size of the printf buffer, so you can have an idea of what you are up against.


  • You can also use the assert function to test if specific values are true in your code.
    • The assert function is also able to evaluate built-in CUDA variables in host and device code, so that is helpful when tackling very detailed processes.
    • In my experience, it will throw an assertion for each and every thread that it comes across and display it in the output.
    • Please note that assertions abort processing immediately.
    • Make sure to include <assert.h> before using the assert function.
    • See the video for an example of assertions.
    • See the code below to learn how to implement it