Inspect State

In this section, learn more about how to use various state inspection features of the CUDA debugger, such as specifying the debugger context, viewing variables, and more.

1. Inspect State

In this section, learn more about how to use various state inspection features of the CUDA debugger, such as specifying the debugger context, viewing variables, and more.

2. Specify Debugger Context

Program execution in CUDA takes place over hundreds or thousands of threads simultaneously. The CUDA Debugger features the CUDA: Change CUDA debug focus command, which lets you choose the blocks and threads of interest in the currently debugged application.

The Locals and Watch views, as well as the Step Into function use the block and thread of interest as context for their functionality.

2.1. Choose a Block and Thread of Interest

  1. From the Visual Studio Code Command Palette run the CUDA: Change CUDA debug focus command to show the CUDA Debug Focus input box.

    Alternatively, the Visual Studio Code status bar display block and thread indexes, and launches the CUDA Debug Focus input box.

  2. Enter the desired block index and thread index in the input box provided.

  3. Press Enter.

    The Locals and Watch tool windows show variables and expressions evaluated in the context of the newly chosen thread.

  Note:  

Changing the CUDA debug focus affects the behavior of breakpoints. Breakpoints are initially unconditional. When the debugger encounters the first breakpoint, the location of the breakpoint becomes the focus for all debugging. Stepping and breakpoints are set on the focus thread. This resets on the next kernel launch, going back to unconditional breakpoints.

For example, if the current focus is block(0,0,0) thread(5,2,0), then breakpoints will only hit when block and thread indices match the current focus indices.

2.2. Which Thread Has Focus?

Consider how threads grab focus in the CUDA Debugger. For example, the debugger can change focus to another thread without notifying you. If the focus thread is not at a breakpoint, and a different thread hits a data breakpoint, conditional breakpoint, or an unconditional breakpoint, the CUDA Debugger changes the current focus thread.

For example, if stopped in block (0,0,0) and thread (0,0,0) and a breakpoint hits in block (1,0,0) thread (0,0,0), the debugger will switch to the new thread. The debugger does not switch the focus thread when stepping, since the other threads are frozen.

3. How To: View Variables

NVIDIA Nsight™ VSCE supports the standard Visual Studio Locals view for examining the value of local variables in CUDA source code, and the Watch view for interactively evaluating expressions.

The information in the Locals view and Watch view are available in the CUDA Debugger only when:

  • A CUDA-based application is running, and

  • Application execution is halted while executing CUDA source code.

3.1. View the Value of a Local Variable

  1. Start a debugging session.

    1. In Visual Studio Code, open a folder with a CUDA project.

    2. Define at least one breakpoint.

    3. Press F5 to start debugging.

    4. Pause execution or allow the application to run to a breakpoint, or set a breakpoint if none enabled.

  2. From the Run and Debug tab select Locals.

The Locals view shows the list of variables, their assigned values, and type in the current lexical scope.

3.2. Evaluate the Value of an Expression

  1. From the Run and Debug tab choose Watch.

  2. Click the + to Add Expression.

  3. Type any valid expression recognized by the debugger. The expression can contain any variable valid at the current execution location.

  4. Press the Enter key.

    The CUDA Debugger evaluates the expression and displays the result.

    If the expression refers to a variable that is not valid in the current execution location, the expression value displays <Not available>.

    If the expression is a variable, you can edit the value in this column to change the contents of the variable. You cannot edit the value of const variables.

Notices

Notice

NVIDIA® Nsight™ Application Development Environment for Heterogeneous Platforms, Visual Studio Code Edition 2023.1.0 User GuideSend Feedback

THE INFORMATION IN THIS GUIDE AND ALL OTHER INFORMATION CONTAINED IN NVIDIA DOCUMENTATION REFERENCED IN THIS GUIDE IS PROVIDED “AS IS.” NVIDIA MAKES NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO THE INFORMATION FOR THE PRODUCT, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. Notwithstanding any damages that customer might incur for any reason whatsoever, NVIDIA’s aggregate and cumulative liability towards customer for the product described in this guide shall be limited in accordance with the NVIDIA terms and conditions of sale for the product.

THE NVIDIA PRODUCT DESCRIBED IN THIS GUIDE IS NOT FAULT TOLERANT AND IS NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE IN CONNECTION WITH THE DESIGN, CONSTRUCTION, MAINTENANCE, AND/OR OPERATION OF ANY SYSTEM WHERE THE USE OR A FAILURE OF SUCH SYSTEM COULD RESULT IN A SITUATION THAT THREATENS THE SAFETY OF HUMAN LIFE OR SEVERE PHYSICAL HARM OR PROPERTY DAMAGE (INCLUDING, FOR EXAMPLE, USE IN CONNECTION WITH ANY NUCLEAR, AVIONICS, LIFE SUPPORT OR OTHER LIFE CRITICAL APPLICATION). NVIDIA EXPRESSLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR SUCH HIGH RISK USES. NVIDIA SHALL NOT BE LIABLE TO CUSTOMER OR ANY THIRD PARTY, IN WHOLE OR IN PART, FOR ANY CLAIMS OR DAMAGES ARISING FROM SUCH HIGH RISK USES.

NVIDIA makes no representation or warranty that the product described in this guide will be suitable for any specified use without further testing or modification. Testing of all parameters of each product is not necessarily performed by NVIDIA. It is customer’s sole responsibility to ensure the product is suitable and fit for the application planned by customer and to do the necessary testing for the application in order to avoid a default of the application or the product. Weaknesses in customer’s product designs may affect the quality and reliability of the NVIDIA product and may result in additional or different conditions and/or requirements beyond those contained in this guide. NVIDIA does not accept any liability related to any default, damage, costs or problem which may be based on or attributable to: (i) the use of the NVIDIA product in any manner that is contrary to this guide, or (ii) customer product designs.

Other than the right for customer to use the information in this guide with the product, no other license, either expressed or implied, is hereby granted by NVIDIA under this guide. Reproduction of information in this guide is permissible only if reproduction is approved by NVIDIA in writing, is reproduced without alteration, and is accompanied by all associated conditions, limitations, and notices.

Trademarks

NVIDIA, the NVIDIA logo, and cuBLAS, CUDA, CUDA-GDB, CUDA-MEMCHECK, cuDNN, cuFFT, cuSPARSE, DIGITS, DGX, DGX-1, DGX Station, NVIDIA DRIVE, NVIDIA DRIVE AGX, NVIDIA DRIVE Software, NVIDIA DRIVE OS, NVIDIA Developer Zone (aka "DevZone"), GRID, Jetson, NVIDIA Jetson Nano, NVIDIA Jetson AGX Xavier, NVIDIA Jetson TX2, NVIDIA Jetson TX2i, NVIDIA Jetson TX1, NVIDIA Jetson TK1, Kepler, NGX, NVIDIA GPU Cloud, Maxwell, Multimedia API, NCCL, NVIDIA Nsight Compute, NVIDIA Nsight Eclipse Edition, NVIDIA Nsight Graphics, NVIDIA Nsight Integration, NVIDIA Nsight Systems, NVIDIA Nsight Visual Studio Edition, NVIDIA Nsight Visual Studio Code Edition, NVLink, nvprof, Pascal, NVIDIA SDK Manager, Tegra, TensorRT, Tesla, Visual Profiler, VisionWorks and Volta are trademarks and/or registered trademarks of NVIDIA Corporation in the United States and other countries. Other company and product names may be trademarks of the respective companies with which they are associated.