Before we discuss some fundamental GPU programming concepts, it is essential that we revisit the CUDA installation and testing procedure that we covered earlier in Chapter 2, Designing a GPU Computing Strategy, while concluding the DIY section. Step-by-step screenshots of a fresh Ubuntu 18.04 Linux installation were illustrated. There were only two basic steps involved, as we discussed previously.
It requires performing the following sequential tasks:
- Driver installation: The driver installation can be done by installing the most recent version of the NVIDIA graphics driver from the available Ubuntu repository via Additional Drivers.
- CUDA toolkit installation: The toolkit package goes by the name of nvidia-cuda-toolkit, which will also set the path to the NVIDIA CUDA Compiler (NVCC) driver after installation. A reboot is recommended post installation, after which you will be able to compile a CUDA program source code files with the nvcc command from any Terminal. You can verify your new CUDA installation with the following code:
nvidia-smi
This is followed by checking the NVCC version:
nvcc -version
The syntax for nvcc compilation in simple form goes like this:
nvcc Your-CUDA-GPU-program.cu
As we can see here, the extension for CUDA source files is .cu. What we require next for hands-on computing is an IDE, which will be covered later in this book.
It's always good practice to choose the CUDA toolkit available on the Linux repository by default, as it makes it convenient while upgrading your Linux system. Manual installation of separately downloaded versions may lead to system instability if not properly configured. But should you choose to have more than one CUDA version in accordance to a specific application requirement, you can install and configure them from the following archive link. It also shows relevant documentation after selecting your CUDA version and operating system.
Follow this link to download the CUDA toolkit: https://developer.nvidia.com/cuda-toolkit-archive.
To retain system stability, after updating your repository based on the previous link, install only your specific toolkit version using the following format:
sudo apt install cuda-toolkit-x-x
x-x refers to the version number of your CUDA Toolkit. For example, cuda-toolkit-9-0 would install CUDA 9.0.
Do not install the package cuda or cuda-x-x as either would also try to install a new NVIDIA driver along with CUDA, and thus could disrupt your existing NVIDIA graphics that were installed earlier from the default settings (Additional Proprietary Drivers).