Installing CUDA 10.2 or 11.0 on Ubuntu 18.04 or 20.04
Installing CUDA correctly can be a headache, which is why I’ve written this tutorial. I will be using a V100 GPU instance from datacrunch.io.
The latest version of this document can be found on datacrunch.io/docs.
Step 1a. (easy mode) Installing driver & CUDA with our script
If your goal is to get up and running as fast as you can, this installer script does everything you will need.
It works for Ubuntu 18.04 and 20.04 and installs either CUDA 10.2 or CUDA 11.0. Pick CUDA 10.2 if you are not sure what to take.
sudo git clone https://github.com/DataCrunch-Scripts/Install-CUDA.git ~/Install-CUDAsudo chmod +x ~/Install-CUDA/installer.shsudo ~/Install-CUDA/installer.sh
Follow the instructions of the installer and your server will be running CUDA in mere minutes!
Step 1b. Alternative (slightly-more-work): Installing NVidia driver & CUDA manually
If you would like to learn how to install the NVidia driver and CUDA manually; these are the steps the installer takes.
First we will need the CUDA installer which we can find on NVidia’s website. The installer includes an appropriate driver as well.
Note that we do not actually need to install CUDA, the NVidia driver is actually enough since we will be using conda environments which include CUDA. However, if you want to run CUDA accelerated programs outside of conda, it is convenient to have it installed.
Here we will be installing CUDA 10.2 for Ubuntu 18.04;
wget http://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda_10.2.89_440.33.01_linux.run
Before installing, we will need to install some dependencies:
sudo apt updatesudo apt-get install build-essential gcc-multilib dkms
The installer will ask what to install, you should select the driver and CUDA toolkit.
Next, we make the file executable:
sudo chmod +x cuda_10.2.89_440.33.01_linux.run
Followed by executing the installer:
sudo ./cuda_10.2.89_440.33.01_linux.run
Follow the instructions given by the installer. Choose to install the driver and CUDA toolkit. The samples are optional.
Next we will want to configure the runtime library:
sudo bash -c "echo /usr/local/cuda/lib64/ > /etc/ld.so.conf.d/cuda.conf"sudo ldconfig
We add our path variable by adding “/usr/local/cuda/bin” to our PATH variable:
sudo nano /etc/environment
We want our file to look like this:
After adding, press ctrl+x to exit, save the file when prompted.
At this point, you can check the output of “nvidia-smi”, you should see your GPU’s, driver version and CUDA version. If all is looking good, we will modify our startup script;
sudo nano /etc/rc.local
“#!/bin/bash”: required to let the shell know to use bash. (this is not a normal comment, not a optional line)
“nvidia-smi -pm 1”: This will enable persistence mode to keep the driver loaded (which will increase the speed of some actions).
“nvidia-smi -e 0”: This will disable error correcting on the memory of the GPU. This is safe to do for most applications and will allow using more GPU memory.
“exit 0”: Close the script.
#!/bin/bash
nvidia-smi -pm 1
nvidia-smi -e 0
exit 0
Let’s make the file executable:
sudo chmod +x /etc/rc.local
Reboot your server:
sudo reboot -h now
And that’s it, you are ready to use your GPU’s!