I'd like to know what is the best debugger for a JCuda project (if exists).
I know that for normal CUDA applications there are tools like cuda-gdb and cuda-memcheck and I wonder if I can use any of them or similar ones for a JCuda project.
Thank you!

- 190
- 2
- 7
2 Answers
You should be able to use regular CUDA debugger (e.g. Nsight or cuda-gdb) to debug the GPU code in your JCuda application. You can use Java debuggers (e.g. Eclipse) to debug Java code. There is no debugger that can seamlessly debug Java and CUDA code though.

- 9,242
- 2
- 30
- 29
-
Thanks for the answer, but what I need is a debugger that could help during the execution of the device code. I launch a CUDA kernel from Java with JCuda. I know that native CUDA code can be debugged in a way that shows, for examples, memory leaks or other useful informations for optimizations, things that I can't use in this situation, though. If you can provide an example or a tutorial that I could follow that would be great! :) – Rorrim Aug 02 '13 at 07:50
-
2You can try attaching to Java process to debug CUDA code. That's how you debug any JNI code. – Eugene Aug 02 '13 at 15:57
-
Thanks for the advice. Unfortunately on linux I can't debug with a single GPU, so I'll try it on my Windows PC and hopefully it works. – Rorrim Aug 05 '13 at 10:54
-
1It worked! This is for anyone interested: [http://http.developer.nvidia.com/NsightVisualStudio/2.2/Documentation/UserGuide/HTML/Content/Attach_CUDA_to_Process.htm](http://http.developer.nvidia.com/NsightVisualStudio/2.2/Documentation/UserGuide/HTML/Content/Attach_CUDA_to_Process.htm) – Rorrim Aug 08 '13 at 22:25
-
1@Rorrim The latest version of the documentation is: http://http.developer.nvidia.com/NsightVisualStudio/3.2/Documentation/UserGuide/HTML/Content/Attach_CUDA_to_Process.htm – Aleksandr Dubinsky Oct 27 '13 at 14:49
-
Something that caught me: if you start your application before setting NSIGHT_CUDA_DEBUGGER=1, you have to restart the entire command window or IDE (ie, the spawning process) before trying again (at least on Windows w/ Nsight 3.1). – Aleksandr Dubinsky Oct 30 '13 at 20:09
On Linux, you can use Nvidia Nsight (cuda-gdb).
To set up a debugging session that launches your executable:
- launch Nsight as root (surprising, but necessary for me)
- go to Run menu > Debug Configurations...
- Right-click "C/C++ Application", choose New
- Under Main tab
- Set the executable (field C/C++ Application) to
/usr/bin/java
or whatever the correct path
- Set the executable (field C/C++ Application) to
- Under Arguments tab
- set the startup arguments, eg
-jar target/MyApp.jar
- set the working directory
- set the startup arguments, eg
- Under Debugger tab
- set the "CUDA GDB init file" path (see below)
- set additional options, like enabling CUDA memcheck
Because Java uses segmentation faults internally for some too-clever purposes, you will need to create a file with the following GDB option and point to it as the "CUDA GDB init file". Note that by setting this option you won't be able to catch segmentation fault bugs inside your own JNI code. This shouldn't be a problem.
handle SIGSEGV nostop noprint pass
If you compile your kernels with debug symbols, you'll be able to debug them.

- 22,436
- 15
- 82
- 99