Using Nsight with Eclipse in Linux

We will now see how to use Nsight in Linux. You can open Nsight from either your desktop by selecting it or you can run it from a command line with the nsight command. The Nsight IDE will open. From the top of the IDE, click on File, then choose New... from the drop-down menu, and from there choose New CUDA C/C++ Project. A new window will appear, and from here choose CUDA Runtime Project. Give the project some appropriate name, and then click Next. You'll be prompted to give further settings options, but the defaults will work fine for our purposes for now. (Be sure to note where the source folder and project paths will be located in the third and fourth screens here.) You'll get to a final screen, where you can press Finish to create the project:

Finally, you'll end up at a project view with your new project and some placeholder code open; as of CUDA 9.2, this will consist of a reciprocal kernel example.

We can now import our code. Either you can just use the editor in Nsight to delete all of the code in the default source file and cut and paste it in, or you can manually delete the file from the project's source directory, manually copy the matrix_ker.cu file into the source directory, and then choose to refresh the source directory view in Nsight by selecting it and then pressing F5. You can now build the project with Ctrl + B, and run it with F11. The output of our program should appear within the IDE itself within the Console subwindow, as follows:

We can now set a breakpoint within our CUDA code; let's set it at the entry point of our kernel where the row value is set. We set the cursor onto that row in the Eclipse editor, and then press Ctrl + Shift + B to set it. 

We can now begin debugging by pressing F11 (or clicking the bug icon). The program should be paused at the very beginning of the main function, so press F8 to resume to the first breakpoint. You should see the first line in our CUDA kernel highlighted with an arrow pointing to it in the IDE; let's step over the current line by pressing F6, which will ensure that the row has been set.

Now, we can easily switch between different threads and blocks in our CUDA grid to check the current values that they hold as follows: from the top of the IDE, click on the Window drop-down menu, then click Show view, and then choose CUDA. A window with the currently running kernel should open, and from here you can see a list of all of the blocks that this kernel is running over.

Click on the first one and from here you will be able to see all of the individual threads that are running within the block:

Now, we can look at the variable corresponding to the very first thread in the very first block by clicking on the Variables tab—here, row should be 0, as expected:

Now, we can check the values for a different thread by again going to the CUDA tab, choosing the appropriate thread, and switching back. Let's stay in the same block, but choose thread (1, 0, 0) this time, and check the value of row again:

We see that the value of row is now 1, as we expect. 

We now have the basics of how to debug a CUDA program from Nsight/Eclipse in Linux, and we can use all of the regular conventions as you would for debugging a regular Linux program as with any other IDE (setting breakpoints, starting the debugger, continue/resume, step over, step in, and step out). Namely, the main difference here is we have to know how to switch between CUDA threads and blocks to check variables, otherwise, it's pretty much the same.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.82.4