CUDA Application Running and Debugging
The Compiler and Debugger allows you to debug CUDA programs. It leverages CUDA-GDB to debug GPU applications on a unified interface.
Prerequisites
- You have logged in to the Kunpeng DevKit.
- The program has been compiled before debugging.
- In the Resource Manager of VS Code, the folder of the local source program has been opened.
Debugging a Program Module That Has Source Code
- Click
in the navigation pane on the left, or click Development and then click Debug under Compiler and Debugger to display the debugging page. - Select CUDA application and set CUDA application debugging parameters, as shown in Figure 1 and Figure 2. After the configuration is complete, click Start.
Table 1 CUDA application debugging parameters Parameter
Description
Configured Remote Server
IP address of the node server to be debugged.
Use an existing server or add a target server. Click Add Target Server to go to the target server management page. .
NOTE:The root user account has the highest permission. To avoid unnecessary risks to the system, we strongly recommend you use a non-root account for the debugging.
Linux User Password
Password of the user of the node to be debugged.
Remember password
If this option is selected, the Linux user password of the current remote server will be remembered.
Debug Mode
- Launch Application
- Attach to Process
NOTE:If you select Attach to Process, you need to enter the ID of the process to be debugged.
PID
ID of the process to be debugged.
Program
Enter the absolute path of the program.
Program Source Code Path
Enter the working directory of the program source code.
NOTE:- If the source file is a
soft link , the file (privacy content) corresponding to the soft link is read during debugging. Before debugging, check whether the source file is a soft link. If yes, check whether debugging is required. It is recommended that the source file to be debugged is a common text file. - During debugging, all files in the source code path are copied to the debugging server. Ensure that the source code path contains only source files related to debugging.
(Optional) Program Arguments
Enter the arguments passed to the CUDA program to run.
- The progress is displayed in the lower right corner. Then the system checks whether the entered information is correct. If it is incorrect, rectify the fault according to the prompted information.
- The system automatically checks whether cuda-gdbserver is installed on the node to be debugged and whether CUDA-GDB is installed on the debugging server. If they are not installed, follow instructions in Installing the CUDA Toolkit. CUDA-GDB and cuda-gdbserver are included in
CUDA Toolkit . When installing the CUDA Toolkit, the CUDA-GDB and cuda-gdbserver are also installed. - If GDB, instead of CUDA-GDB, is installed on the debugging server, some CUDA debugging functions will be unavailable. You are advised to install CUDA-GDB. For details, see Installing the CUDA Toolkit.
- It is recommended that the architecture of the debugged server is the same as that of the debugging server.
- Currently, the CUDA supports the debugging formats of DWARF 2, 3, 4, and 5.
- During debugging, the cuda-gdbserver program is started. Ensure that the cuda-gdbserver program is normal and not tampered with in advance.
- If CUDA application debugging fails to be started, rectify the fault by following instructions in Failed to Start a CUDA Application Debugging Task.
- The system automatically checks whether cuda-gdbserver is installed on the node to be debugged and whether CUDA-GDB is installed on the debugging server. If they are not installed, follow instructions in Installing the CUDA Toolkit. CUDA-GDB and cuda-gdbserver are included in
- If the target server is detected to have multiple GPUs, the Select GPU Device dialog box is displayed. Select the required GPU from the GPU drop-down list and click OK. If the target server is detected to have only one GPU, no dialog box is displayed. The debugging window for the CUDA node is directly displayed.Figure 3 Selecting a GPU device
A GPU device can be selected only when Debug Mode is set to Launch Application.
- After the necessary information is checked, open the debugging window of the CUDA application to obtain the RUN AND DEBUG area, source code area, and debug-buttons area. The RUN AND DEBUG area displays CUDA debugging information. The KERNEL THREADS and INFO CUDA tab pages are displayed on the VS Code panel. You can click the corresponding pages to view the information, as shown in Figure 4.
- When debugging in the source code area, the line of code that is being debugged is highlighted. You can click a line of code to set a breakpoint for it. See Figure 5.
Try other debug buttons on the debugging bar as required. See Table 2. You can move the mouse pointer to the left part in the debugging button area and click to drag debugging buttons to another place.
Table 2 Description of debugging buttons Icon
Button
Description

Resume
Runs the code until the next breakpoint.

Suspend
Suspends the program that is being executed.

Skip a single step
Executes the next line of code.

Step in
Steps in to the function.

Step out
Steps out of the function.

Restart
Restarts debugging.

Stop
Stops debugging.
- Click
on the debugging bar to restart CUDA application debugging.Figure 6 Restarting a debugging task
- Click the RUN AND DEBUG window on the left to view the variables (Locals and Registers), WATCH, BREAKPOINTS, and HOST THREADS information. You can perform the following operations during debugging: Viewing the HOST THREADS information and switching threads, modifying the values of Locals and Registers, adding or modifying a WATCH expression, deleting a single or all WATCH expressions, viewing BREAKPOINTS and CALL STACK information. See Figure 7 for all debugging information.
Debugging a Program Module That Has No Source Code
- Click Debug, after the configuration information is checked, open the debugging window of the CUDA application to obtain the RUN AND DEBUG area, source code area, and debug-buttons area. The RUN AND DEBUG area displays CUDA debugging information, as shown in Figure 8.
- In the source code area, click
on the debugging bar to perform compilation and debugging. After the execution is complete, the corresponding source code line is highlighted. If there is no source code, the corresponding assembly instruction is displayed in the source code area. See Figure 9. - Continue debugging the assembly instruction and set breakpoints for the line of the assembly instruction. If any assembly instruction has a source file, the corresponding source code is used for debugging. If still no source file is found, assembly instructions are used for debugging.






