CUDA PTX is analogous to assembly, and as such reveals the source code. I have read Section 3.1 of the CUDA Programming Guide and Section 3.2.7 from the online CUDA compiler documentation. I have a basic understanding of the -arch versus -code compiler options.
If I understand correctly, specifying -arch compute_XX makes PTX. Whereas -code sm_XX makes both PTX and cubin.
I desire only cubin, such that no PTX is in the resulting image. How can I achieve this?
Preferably via Visual Studio settings, although I only find the -gencode option within Visual Studio Project Settings.
PTX is not quite analogous to assembly. PTX is an intermediate representation of the program that can be compiled to the different, incompatible instruction set architectures (ISA) that Nvidia GPUs have been using over time. Usually, a new ISA for Nvidia GPUs comes with an updated version of PTX that can represent the new features of the ISA.
-arch
and -code
options to nvcc
work slightly differently to what you describe. They are not (mutual exclusive) alternatives, rather they determine different aspects.-arch
controls which PTX version is used as the intermediate representation. As such it is combined with a compute_XX
PTX version.-code
controls what code is embedded into the resulting binary - either machine code for the specified ISA if used in the -code sm_XX
form, or PTX to be just-in-time compiled by the GPU driver if -code compute_XX
is specified.-arch sm_XX
will embed both the compiled code for the specified ISA and PTX code into the binary - this probably is the situation that you are referring to that you want to avoid.-gencode
option allows you to specify multiple -arch
/-code
pairs, with the resulting binary containing separate code for each of the pairs.nvprune
to remove all but the desired ISA code from a binary. cuobjdump
to check what is in a specific binary.So the way to prevent any PTX code from being present in your resulting binary is to call nvcc as nvcc -arch compute_XX -code sm_XX
(or use multiple such pairs together with -gencode
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With