Forked from kmhofmann/installing_nvidia_driver_cuda_cudnn_linux.md
Created
December 2, 2020 01:16
-
-
Save dryqin/6cc031e9b4ccfd85db94443cb013ea32 to your computer and use it in GitHub Desktop.
Revisions
-
kmhofmann revised this gist
Aug 6, 2020 . 1 changed file with 42 additions and 23 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,54 +1,73 @@ # Installing the NVIDIA driver, CUDA and cuDNN on Linux (Ubuntu 20.04) This is a companion piece to my instructions on building [TensorFlow from source](https://gist.github.com/kmhofmann/e368a2ebba05f807fa1a90b3bf9a1e03). In particular, the aim is to install the following pieces of software - [NVIDIA graphics card driver](https://www.nvidia.com/en-us/drivers/unix/) (v450.57) - [CUDA](https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=2004&target_type=runfilelocal) (v11.0.2) - [cuDNN](https://developer.nvidia.com/cudnn) (v8.0.2.39) on an Ubuntu Linux system, in particular Ubuntu 20.04. At the time of writing (**2020-08-06**), these were the latest available versions. As a disclaimer, please note that I am **not** interested in running an outdated Ubuntu version or installing a CUDA/cuDNN version that is not the latest. Therefore, **the below instructions may or may not be useful to you**. Please also note that the instructions **are likely outdated**, since I only update them occasionally. **Don't just copy these instructions, but check what the respective latest versions are and use these instead!** ### Installing the NVIDIA driver Download and install the latest NVIDIA graphics driver from here: https://www.nvidia.com/en-us/drivers/unix/. Note that every CUDA version requires a minimum version of the driver; check this beforehand. Ubuntu 20.04 currently offers installation of the NVIDIA driver version 440.100 through its built-in 'Additional Drivers' mechanism, which should be sufficient for CUDA 10.2. CUDA 11.0 appears to require a newer version of the NVIDIA driver, so we're going to install this manually. Download and install the latest NVIDIA graphics driver from here: https://www.nvidia.com/en-us/drivers/unix/. sudo sh NVIDIA-Linux-x86_64-450.57.run The CUDA runfile also includes a version of the NVIDIA graphics driver, but I like to separate installing either, as the version supplied with CUDA Is not necessarily the latest version of the driver. ### Installing CUDA Download the latest CUDA version [here](https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=2004&target_type=runfilelocal). For example, I downloaded: $ wget http://developer.download.nvidia.com/compute/cuda/11.0.2/local_installers/cuda_11.0.2_450.51.05_linux.run Thankfully, CUDA 11 currently supports the up-to-date Ubuntu version, 20.04, so we don't need to jump through hoops to deal with an `unsupported GNU version` error as in [previous versions](https://gist.github.com/kmhofmann/cee7c0053da8cc09d62d74a6a4c1c5e4) of this document. Simply install as per the official instructions: $ sudo sh cuda_11.0.2_450.51.05_linux.run You may need to confirm that the display driver is already installed, and de-select installation of the display driver. Once finished, you should see a summary like this: =========== = Summary = =========== Driver: Not Selected Toolkit: Installed in /usr/local/cuda-11.0/ Samples: Installed in /home/michael/, but missing recommended libraries Please make sure that - PATH includes /usr/local/cuda-11.0/bin - LD_LIBRARY_PATH includes /usr/local/cuda-11.0/lib64, or, add /usr/local/cuda-11.0/lib64 to /etc/ld.so.conf and run ldconfig as root To uninstall the CUDA Toolkit, run cuda-uninstaller in /usr/local/cuda-11.0/bin Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-11.0/doc/pdf for detailed information on setting up CUDA. ***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least .00 is required for CUDA 11.0 functionality to work. To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file: sudo <CudaInstaller>.run --silent --driver Do what the instructions given in the summary say and add the given directories to your `PATH` and `LD_LIBRARY_PATH`. For example by adding the following lines to your `.bashrc`, `.zshrc`, or whatever shell you are using: export PATH=/usr/local/cuda-11.0/bin:$PATH export LD_LIBRARY_PATH=/usr/local/cuda-11.0/lib64:$LD_LIBRARY_PATH ### Installing cuDNN Just go [here](https://developer.nvidia.com/cudnn) and follow the [instructions](https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html). You'll have to log in, so downloading of the right cuDNN binary packages cannot be easily automated. Meh. Once downloaded, un-tar the file and copy the contents to their respective locations: $ tar -xzvf cudnn-11.0-linux-x64-v8.0.2.39.tgz $ sudo cp cuda/include/cudnn*.h /usr/local/cuda/include $ sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64 $ sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn* -
kmhofmann created this gist
May 23, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ # Installing the NVIDIA driver, CUDA and cuDNN on Linux (Ubuntu 20.04) This is a companion piece to my instructions on building [TensorFlow from source](https://gist.github.com/kmhofmann/e368a2ebba05f807fa1a90b3bf9a1e03). In particular, the aim is to install the following pieces of software - [NVIDIA graphics card driver](https://www.nvidia.com/en-us/drivers/unix/) (v440.82) - [CUDA](https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1804&target_type=runfilelocal) (v10.2) - [cuDNN](https://developer.nvidia.com/cudnn) (v7.6.5) on an Ubuntu Linux system, in particular Ubuntu 20.04. At the time of writing (**2020-05-23**), these were the latest available versions. As a disclaimer, please note that I am **not** interested in running an outdated Ubuntu version or installing a CUDA/cuDNN version that is not the latest. Therefore, **the below instructions may or may not be useful to you**. Please also note that the instructions **are likely outdated**, since I only update them occasionally. **Don't just copy these instructions, but check what the respective latest versions are and use these instead!** ### Installing the NVIDIA driver Download and install the latest NVIDIA graphics driver from here: https://www.nvidia.com/en-us/drivers/unix/. Note that every CUDA version requires a minimum version of the driver; check this beforehand. Ubuntu 20.04 currently offers installation of the NVIDIA driver version 440.82 through its built-in 'Additional Drivers' mechanism, which should be sufficient for CUDA 10.2. Otherwise, download and install the latest NVIDIA graphics driver from here: https://www.nvidia.com/en-us/drivers/unix/. The CUDA runfile also includes a version of the NVIDIA graphics driver, but I like to separate installing either, as installing them in combination can be more brittle on "unsupported" distributions for CUDA. ### Installing CUDA Download the latest CUDA version [here](https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1804&target_type=runfilelocal). For example, I downloaded: $ wget http://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda_10.2.89_440.33.01_linux.run Here's the first roadblock: Ubuntu 20.04 ships with GCC 9.3.0 by default, but CUDA 10.2 pretends to only support Ubuntu 18.04 and GCC versions *up to* version 8. When trying to install CUDA on an up-to-date system, it will fail. Uhm... this is insane. I understand when code needs to be built with a certain *minimum* version of a compiler, but no well written piece of software ever should specify a *maximum* version. You would now think that you can simply install GCC 8 (something along the lines of `sudo apt install gcc-8` and running `CC=$(which gcc-8) CXX=$(which g++-8) ./cuda_10.2.89_440.33.01_linux.run` as root) and be happy, but alas, no. The CUDA installer conveniently disregards any such set environment variables. And changing the system default compiler [as suggested](https://linuxconfig.org/how-to-install-cuda-on-ubuntu-20-04-focal-fossa-linux) out on the internet using the inadequate `update-alternatives` mechanism should clearly not be an option for anyone! Time for more desperate measures. Go ahead and install CUDA like this: $ sudo sh cuda_10.2.89_440.33.01_linux.run --override The `--override` flag overrides the compiler check, and you can now go on. Deselect the driver if it was installed earlier, but install the rest. Try to build the samples. You will notice that this fails, again with a message such as unsupported GNU version! gcc versions later than 8 are not supported! Thanks for nothing, NVIDIA. Thankfully we can disable this error by commenting out the `#error` pragma in `/usr/local/cuda/include/crt/host_config.h`. Do so. This is what it looks like for me: #if defined(__GNUC__) #if __GNUC__ > 8 //#error -- unsupported GNU version! gcc versions later than 8 are not supported! #endif /* __GNUC__ > 8 */ I have no idea what the implications are, but so far I haven't found any. There's a similar section on Clang just below, in case you decide to compile TensorFlow with Clang. (I have not tried yet, but it should be a good adventure.) ### Installing cuDNN Just go [here](https://developer.nvidia.com/cudnn) and follow the [instructions](https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html). You'll have to log in, so downloading of the right cuDNN binary packages cannot be easily automated. Meh.