Skip to content

Instantly share code, notes, and snippets.

@colllin
Last active May 28, 2019 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colllin/d5c016fb0c7d482aca9d4b5204e01abb to your computer and use it in GitHub Desktop.
Save colllin/d5c016fb0c7d482aca9d4b5204e01abb to your computer and use it in GitHub Desktop.
Install NVIDIA drivers & CUDA
  1. Install NVIDIA drivers

    1. Find NVIDIA driver download link for your system at http://www.nvidia.com/Download/index.aspx?lang=en-us

    2. wget -P ~/Downloads/ http://us.download.nvidia.com/tesla/390.46/NVIDIA-Linux-x86_64-390.46.run

    3. sudo rm /etc/X11/xorg.conf # It's ok if this doesn't exist

    4. NVIDIA will clash with the nouveau driver so deactivate it:

      $ sudo vim /etc/modprobe.d/blacklist-nouveau.conf
      

      Type i to insert the following lines and save by doing Esc then :wq

      blacklist nouveau
      blacklist lbm-nouveau
      options nouveau modeset=0
      alias nouveau off
      alias lbm-nouveau off
      

      After saving the file, run

      $ sudo update-initramfs -u
      $ sudo reboot # reboot will take a few minutes. After that, you can ssh back in
      
    5. Install NVIDIA drivers. Note: The no-opengl-files option is important.

      $ chmod +x ~/Downloads/NVIDIA-Linux-x86_64-390.46.run
      $ sudo sh ~/Downloads/NVIDIA-Linux-x86_64-390.46.run --no-opengl-files 
      $ sudo reboot # reboot will take a few minutes
      $ sudo modprobe nvidia  
      
  2. Install CUDA

    1. Find CUDA download link from https://developer.nvidia.com/cuda-downloads

    2. Download & Install CUDA (and, optionally, any patches)

      $ wget -P ~/Downloads/ https://developer.nvidia.com/compute/cuda/9.1/Prod/local_installers/cuda_9.1.85_387.26_linux
      $ chmod +X ~/Downloads/cuda_9.1.85_387.26_linux
      $ sudo sh ~/Downloads/cuda_9.1.85_387.26_linux --override --no-opengl-libs
      
      • For recent versions of cuda (>10?):

        [X] Driver
        [X] Toolkit
        [X] Samples
        [ ] Everything else
        

        Yes to question about updating symbolic link at /usr/local/bin/cuda.

      • For older versions of cuda (9?):

        1. Hit q to go the bottom of the agreement.
        2. Type accept to accept the EULA
        3. Type n to NOT Install NVIDIA Accelerated Graphics Driver for Linux-x86_64
        4. Type y to Install the CUDA 8.0 Toolkit
        5. Enter toolkit location to be (default): /usr/local/cuda-8.0
        6. Yes to install a symbolic link at /usr/local/cuda
        7. Yes to install the CUDA 8.0 Samples
        8. Default location for CUDA Samples location: ~/Downloads
    3. As recommended by the CUDA installer, update PATH and LD_LIBRARY_PATH in your ~/.bashrc

      Note: Doesn't seem like .bashrc or .bash_profile are loaded by screen.... is there a workaround? Otherwise you need to remember to run source ~/.bashrc whenever you open a screen.

      $ vim ~/.bashrc
      

      Add the following environment variables and save:

      export PATH=/usr/local/cuda-8.0/bin:$PATH
      export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH
      export CUDA_HOME=/usr/local/cuda
      

      Now save the file and run:

      $ source ~/.bashrc
      
  3. Install cuDNN

    1. Find Download link at https://developer.nvidia.com/cudnn

    2. Download locally, then upload to your EC2 instance (using scp...)

    3. Then on your EC2 instance:

      $ cd ~/Downloads
      $ tar -xzvf cudnn-8.0-linux-x64-v5.1.tgz
      $ sudo cp cuda/lib64/* /usr/local/cuda/lib64/
      $ sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
      
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment