Adam
Adam

Reputation: 4164

How can I read the PTX?

I am working with Capabilities 3.5, CUDA 5 and VS 2010 (and obviously Windows).

I am interested in reading the compiled code to understand better the implication of my C code changes.

Upvotes: 4

Views: 3834

Answers (1)

Robert Crovella
Robert Crovella

Reputation: 151849

In general, to create a ptx version of a particular .cu file, the command is:

nvcc -ptx mycode.cu

which will generate a mycode.ptx file containing the ptx code corresponding to the file you used. It's probably instructive to use the -src-in-ptx option as well:

nvcc -ptx -src-in-ptx mycode.cu

Which will intersperse the lines of source code with the lines of ptx they correspond to.

To comprehend ptx, start with the documentation

Note that the compiler may generate ptx code that doesn't correspond to the source code very well, or is otherwise confusing, due to optimizations. You may wish (perhaps to gain insight) to compile some test cases using the -G switch as well, to see how the non-optimized version compares.

Since the windows environment may vary from machine to machine, I think it's easier if you just look at the path your particular version of msvc++ is using to invoke nvcc (look at the console output from one of your projects when you compile it) and prepend the commands I give above with that path. I'm not sure there's much utility in trying to build this directly into Visual Studio, unless you have a specific need to compile from ptx to an executable. There are also a few sample codes that have to do with ptx in some fashion.

Also note for completeness that ptx is not actually what's executed by the device (but generally pretty close). It is an intermediate code that can be re-targetted to devices within a family by nvcc or a portion of the compiler that also lives in the GPU driver. To see the actual code executed by the device, we use the executable instead of the source code, and the tool to extract the machine assembly code is:

cuobjdump -sass mycode.exe

Similar caveats about prepending an appropriate path, if needed. I would start with the ptx. I think for what you want to do, it's enough.

Upvotes: 10

Related Questions