CUDA: How to use -arch and -code and SM vs COMPUTE
<p>I am still not sure how to properly specify the architectures for code generation when building with nvcc. I am aware that there is machine code as well as PTX code embedded in my binary and that this can be controlled via the controller switches <code>-code</code> and <code>-arch</code> (or a combination of both using <code>-gencode</code>).</p>

<p>Now, according to <a href="http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/#axzz41HxCsBLc" rel="noreferrer">this</a> apart from the two compiler flags there are also two ways of specifying architectures: <code>sm_XX</code> and <code>compute_XX</code>, where <code>compute_XX</code> refers to a virtual and <code>sm_XX</code> to a real architecture. The flag <code>-arch</code> only takes identifiers for virtual architectures (such as <code>compute_XX</code>) whereas the <code>-code</code> flag takes both, identifiers for real and for virtual architectures.</p>

<p>The documentation states that <code>-arch</code> specifies the virtual architectures for which the input files are compiled. However, this PTX code is not automatically compiled to machine code, but this is rather a "preprocessing step".</p>

<p>Now, <code>-code</code> is supposed to specify which architectures the PTX code is assembled and optimised for.</p>

<p>However, it is not clear which PTX or binary code will be embedded in the binary. If I specify for example <code>-arch=compute_30 -code=sm_52</code>, does that mean my code will first be compiled to feature level 3.0 PTX from which afterwards machine code for feature level 5.2 will be created? And what will be embedded?</p>

<p>If I just specify <code>-code=sm_52</code> what will happen then? Only machine code for V5.2 will be embedded that has been created out of V5.2 PTX code? And what would be the difference to <code>-code=compute_52</code>?</p>