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

  1. First determine the version of Ubuntu using:
    cat /etc/*release
  2. Then determine the Nvidia card installed on machine using one of the below methods:
    1. Using lspci
      sudo lspci | grep -i --color 'vga\|3d\|2d'
    2. To to System > Preferences > Hardware information and check card information
    3. Install and use hardinfo to get information about card
      sudo apt-get install hardinfo
      hardinfo
    Refer https://www.cyberciti.biz/faq/linux-tell-which-graphics-vga-card-installed/
  3. 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
  4. 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
  5. In some cases before installing cuda drivers we may have to setup cuda-keyring using:
    1. Install required kernel headers:
      sudo apt-get install linux-headers-$(uname -r)
    2. 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
    Refer https://docs.nvidia.com/datacenter/tesla/tesla-installation-notes/index.html.
  6. Reboot the machine and test
  7. 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"
  8. 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
  9. 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
  10. 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
  11. 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.
  12. Edit /etc/ld.so.conf and append a new line:
    /usr/local/cuda-11.7/lib64
  13. Update ldconfig using
    sudo ldconfig
  14. 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
  15. Especially, we ran Samples/1_Utilities/deviceQuery from below path
    ./bin/x86_64/linux/release/deviceQuery
  16. 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