Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove all PTX from compiled CUDA to prevent Intellectual Property leaks

Tags:

cuda

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.

like image 752
Tyson Hilmer Avatar asked Jan 26 '17 13:01

Tyson Hilmer


1 Answers

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.

  • The -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.
    As a special shortcut, specifying only -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.
    Finally the -gencode option allows you to specify multiple -arch/-code pairs, with the resulting binary containing separate code for each of the pairs.
  • You can use nvprune to remove all but the desired ISA code from a binary.
  • If unsure, you can always use 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).

like image 102
tera Avatar answered Nov 03 '22 10:11

tera