CUDA Compiler (nvcc)
Need to first understand how a normal compiler works…
NVIDIA cares a lot about CUDA, and so CUDA uses Clang and uses LLVM for graphics and GPU.
Resources: https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html
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.
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
nvccis the command line command for using thenvcccompiler.some-CUDA.cuis passed as the file to compile.- The
oflag is used to specify the output file for the compiled program. -stdspecifies the C++ version- The
archflag indicates for which architecture the files must be compiled. But for those interested in a deeper dive, please refer to the docs about thearchflag, virtual architecture features and GPU features. - As a matter of convenience, providing the
runflag will execute the successfully compiled binary.
The .cu file extension just specifies that it is a CUDA file.
If you want to include CUDA code in regular .cpp file, just write a header file for the .cu file, and then include it.