The code from the book CUDA For Engineers is freely available online. All the projects include make files which call nvcc. I was a bit confused about how nvcc knows which hardware to target. How does the compiler know what the target platform is? I’m trying to use the examples from the book as a way to learn how to code CUDA and figured the Jetson Nano was an affordable hardware platform to use.
Hi shossain, the NVCC compiler should be provided with -gencode flags for the GPU architectures you wish to target, so that it compiles the CUDA kernels for those architectures. Here are the -gencode flags for Jetson Nano and TX1:
FYI, these are the -gencode flags for TX2 and Xavier:
-gencode arch=compute_62,code=sm_62 -gencode arch=compute_72,code=sm_72
You can invoke NVCC with multiple -gencode flags, and it will compile CUDA code for each of the specified architectures.
The correct binaries, which get embedded inside your library or executable, are selected at runtime by the CUDA drivers.