The variable window allows you to edit the types of variables. This is useful for viewing an address as a different type. For example,
Figure 253 shows the result of casting a float in global storage to a 2x2 array of floats in global storage.
You can determine the storage kind of a variable by diving on the variable to open a variable window in the graphical user interface (GUI), or by using the
dwhat command in the command line interface (CLI).
Here are some examples of using the CLI to determine variable types and to perform type casts.
Use Tools > Command Line from the process window menu to open a CLI window from the GUI.
The following examples use the CLI for ease of illustration, but you can instead use the GUI by entering the cast expression (
dprint argument) in the Expression field of the variable window.
When you are using the CLI and want to operate on a CUDA thread, you must first focus on the CUDA thread. The GPU focus thread in the CLI is the same as in the GUI:
The dwhat command prints the type and address offset or PTX register name of a variable. The
dwhat command prints additional lines that have been omitted here for clarity:
You can use dprint in the CLI to cast and print an address offset as a particular type. Note that the CLI is a Tcl interpreter, so we wrap the expression argument to
dprint in curly braces {} for Tcl to treat it as a literal string to pass into the debugger. For example, below we take the address of "A", which is at 0x10 in parameter storage. Then, we can cast 0x10 to a "pointer to a Matrix in parameter storage", as follows:
The above "@parameter" type qualifier is an important part of the cast, because without it the debugger cannot determine the storage kind of the address offset. Casting without the proper type storage qualifier usually results in "Bad address" being displayed, as follows:
You can perform similar casts for global storage addresses. We know that "A.elements" is a pointer to a 2x2 array in global storage. The value of the pointer is 0x110000 in global storage. You can use C/C++ cast syntax:
Or you can use TotalView cast syntax, which is an extension to C/C++ cast syntax that allows you to simply read the type from right to left to understand what it is:
If you know the address of a pointer and you want to print out the target of the pointer, you must specify a storage qualifier on both the pointer itself and the target type of the pointer. For example, if we take the address of "A.elements", we see that it is at address offset 0x20 in parameter storage, and we know that the pointer points into global storage. Consider this example:
Above, using the TotalView cast syntax and reading right to left, we cast 0x20 to a pointer in parameter storage to a pointer to a 2x2 array of floats in global storage. Dereferencing it once gives the value of the pointer to global storage. Dereferencing it twice gives the array in global storage. The following is the same as above, but this time in C/C++ cast syntax: