Install Nvidia graphics card driver on Ubuntu along with cuda libraries
From Notes_Wiki
Home > Ubuntu > Server or Desktop administration > Install Nvidia graphics card driver on Ubuntu along with cuda libraries
- First determine the version of Ubuntu using:
- cat /etc/*release
- Then determine the Nvidia card installed on machine using one of the below methods:
- Using lspci
- sudo lspci | grep -i --color 'vga\|3d\|2d'
- To to System > Preferences > Hardware information and check card information
- Install and use hardinfo to get information about card
- sudo apt-get install hardinfo
- hardinfo
- Using lspci
- Download drivers from nvidia site ( http://www.nvidia.com/download/driverResults.aspx/118962/en-us )
- Example driver download link http://us.download.nvidia.com/tesla/375.66/nvidia-diag-driver-local-repo-ubuntu1604_375.66-1_amd64.deb
- Install the downloaded driver, update and upgrade OS, Install cuda drivers using:
- dpkg -i <driver>.deb
- apt-get update
- apt-get upgrade
- apt-get install cuda-drivers
- In some cases before installing cuda drivers we may have to setup cuda-keyring using:
- Install required kernel headers:
- sudo apt-get install linux-headers-$(uname -r)
- Download required keyring deb file and install using:
- distribution=$(. /etc/os-release;echo $ID$VERSION_ID | sed -e 's/\.//g')
- wget https://developer.download.nvidia.com/compute/cuda/repos/$distribution/x86_64/cuda-keyring_1.0-1_all.deb
- sudo dpkg -i cuda-keyring_1.0-1_all.deb
- Install required kernel headers:
- Reboot the machine and test
- After reboot if screen is blank edit /etc/default/grub and append nomodeset option to GRUB_CMDLINE_LINUX_DEFAULT. Do not remove existing options append with space bar.
- GRUB_CMDLINE_LINUX_DEFAULT="nomodeset"
- Run below and verify that output contains information about installed graphics card.
- /usr/local/cuda/bin/nvcc --version
- nvidia-smi
- Refer https://stackoverflow.com/questions/9727688/how-to-get-the-cuda-version
- If setup is not working then as per https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html there is combination of OS, GCC, nvidia drivers, etc. that is tested for particular OS. We can validate those via
- uname -a
- gcc --version
- ldd --version
- nvidia-smi
- /usr/local/cuda/bin/nvcc --version
- If required perform following additional steps
- sudo apt-get install nvidia-gds
- sudo apt-get install cuda-drivers-515
- conda install cuda -c nvidia
- cat /proc/driver/nvidia/version
- Execute below in current shell to set PATH and LD_LIBRARY_PATH properly for current shell
- export PATH=/usr/local/cuda-11.7/bin${PATH:+:${PATH}}
- export LD_LIBRARY_PATH=/usr/local/cuda-11.7/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
- Ideally we should use "module load", "module available" etc. to set appropriate environment for required cuda version based on the programs being compiled / executed.
- Edit /etc/ld.so.conf and append a new line:
- /usr/local/cuda-11.7/lib64
- Update ldconfig using
- sudo ldconfig
- We can further test the installation with cuda samples from https://github.com/nvidia/cuda-samples. For that use
- sudo apt-get -y install git
- git clone https://github.com/NVIDIA/cuda-samples.git
- cd cuda-samples
- make
- All tests and compilations succeed except for 0_Introduction/simpleMPI perhaps due to missing MPI libaries. We did 'rm -rf 0_Introduction/simpleMPI' to delete that sample and compile all others using make
- Especially, we ran Samples/1_Utilities/deviceQuery from below path
- ./bin/x86_64/linux/release/deviceQuery
- Note after this we tried to run python based code from https://www.geeksforgeeks.org/running-python-script-on-gpu/ It did not work. Perhaps we have not installed python-cuda libraries to make the code work
Home > Ubuntu > Server or Desktop administration > Install Nvidia graphics card driver on Ubuntu along with cuda libraries