CUDA

CUDA Compiler (nvcc)

Before you even understand how CUDA compilers work, you need to understand how a basic compiler works in the first place mate. Like you don’t know ANYTHING.

How have you neglected this understanding for so long? Because you never needed it I guess.

Resources

From Accelerated Computing Course: The CUDA platform ships with the NVIDIA CUDA Compiler nvcc, which can compile CUDA accelerated applications, both the host, and the device code they contain. For the purposes of this lab, nvcc discussion will be pragmatically scoped to suit our immediate needs. After completing the lab anyone interested in a deeper dive into nvcc can start with the documentation.

nvcc will be very familiar to experienced gcc users. Compiling, for example, a some-CUDA.cu file, is simply:

nvcc -std=c++11 arch=sm_70 -o out some-CUDA.cu -run
  • nvcc is the command line command for using the nvcc compiler.
  • some-CUDA.cu is passed as the file to compile.
  • The o flag is used to specify the output file for the compiled program.
  • -std specifies the C++ version
  • The arch flag indicates for which architecture the files must be compiled. For the present case sm_70 will serve to compile specifically for the GPU this lab is running on, but for those interested in a deeper dive, please refer to the docs about the arch flag, virtual architecture features and GPU features.
  • As a matter of convenience, providing the run flag will execute the successfully compiled binary.