简体   繁体   中英

Can I install Tensorflow 1.15 with GPU support on Ubuntu 20.04.1 LTS?

I am building a Deep Learning rig with a GeForce RTX 2060.

I am wanting to use baselines-stable which isn't tensorflow 2.0 compatible yet.

According to here and here , tensorflow-gpu-1.15 is only listed as compatible with CUDA 10.0, not CUDA 10.1.

Attempting to download CUDA from Nvidia, the option for Ubuntu 20.04 is not available for CUDA 10.0.

Searching the apt-cache does not result in CUDA 10.0 either.

$ sudo apt-cache policy nvidia-cuda-toolkit
[sudo] password for lansford: 
nvidia-cuda-toolkit:
  Installed: (none)
  Candidate: 10.1.243-3
  Version table:
     10.1.243-3 500
        500 http://us.archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages

I would highly prefer not to have to reinstall the OS with an older version of Ubuntu. However experimenting with reinforcement learning was the motive for purchasing this PC.

I see some possible clues that it might be possible to build tensorflow-gpu-1.15 from source with cuda 10.1 support. I also saw a random comment that tensorflow-gpu-1.15 will just-work with tf 1.15, but I am not wanting to make a miss-step installing things until I have a signal that is the direction to go. Uninstalling things isn't always straightforward.

  • Should I install CUDA 10.1 and cross my fingers 1.15 will like it.
  • Should I download the install for CUDA 10.0 for a the older Ubuntu version and see if it will install anyway
  • Should I attempt to compile tensorflow from source against CUDA 10.1 (heh heh heh)
  • Should I install and older version of Ubuntu and hope I don't go obsolete too quickly.

Given the situation is there a way to run tensorflow 1.15 with gpu support on Ubuntu 20.04.1?

As this also bothered me I found a working solution that I think is more versatile than using docker containers.

The main idea is from here (not to claim credit from others).

To make a working solution for Ubuntu 20.04 and TensorFlow 1.15 one needs:

  1. Cuda 10.0 (to work with tf 1.15). I have some trouble finding this version because it's not officially available for Ubuntu 20.04. I resolved to the Ubuntu 18.04 version though which works fine.
    Archive toolkits here .
    Final toolkit for Ubuntu here (as it's obvious not 20.04 version is available).

I chose runfile as method which resulted into 1 main runfile and 1 patch runfile being available:

cuda_10.0.130_410.48_linux.run
cuda_10.0.130.1_linux.run

The toolkit can be safely installed using the instructions provided with no risk since each version allocates a different folder in the system (typically this would be /usr/local/cuda-10.0/ ).

  1. The corresponding cudnn for cuda 10.0 I had this one from a previous installation but its shouldn't be hard to download it also. The version I used is cudnn-10.0-linux-x64-v7.6.5.32.tgz .
    Cudnn basically just copies files in the right places (do not actually install anything that is). So, an extraction of the compressed file and copy to the folder would suffice:
    $ sudo cp cuda/include/cudnn.h /usr/local/cuda-10.0/include  
    $ sudo cp cuda/lib64/libcudnn* /usr/local/cuda-10.0/lib64  
    $ sudo chmod a+r /usr/local/cuda-10.0/include/cudnn.h /usr/local/cuda-10.0/lib64/libcudnn*
  1. Upto this point although installed the system is unaware of the presence of cuda 10.0. So, all call to it will fail as if non existent. We should update the relevant system environment for cuda 10.0. One way (there are others) system-wide is to create (in not existent) a /etc/profile.d/cuda.sh which will contain the update to the LD_LIBRARY_PATH variable. It should contain something like:
    export LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/cuda-11.3/lib64:/usr/local/cuda-10.0/lib64:$LD_LIBRARY_PATH

This command would normally do the work:

$ sudo sh -c ‘echo export LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/cuda-11.3/lib64:/usr/local/cuda-10.0/lib64:\$LD_LIBRARY_PATH > /etc/profile.d/cuda.sh’

This requires a restart though to be evaluated I think. Anyway, this way the system will search for the relevant so files in:
a) /usr/local/cuda/lib64 (the default symbolic link) and it will fail
b) to the virtually same as the latter /usr/local/cuda-11.3/lib64 and also fail BUT it will search also
c) /usr/local/cuda-10.0/lib64 which will be successful.

  1. The supported versions of python for cuda 10.0 ends with 3.7 so an older version should be installed. This means obligatory a virtual environment (since messing with system python is never not a good idea).
    One can install python 3.7 for example using this repository which contains old (and new versions of python):
    sudo add-apt-repository ppa:deadsnakes/ppa  
    sudo apt-get install python3.7

This just installs python3.7 to the system it does not make it default. The default is the previous one.

  1. Create a virtual environment and add the desired python as the default interpreter. For me this works:
    virtualenv -p python3.7 ~/tensorflow_1-15

which creates a new venv with Python 3.7 in it.

Now populate with all required modules and you are set to go.

I went ahead and went with the docker approach . The Tensorflow documentation seems to be pushing in that direction anyway. Using docker only the Nvidia driver needs to be installed. You do need to have nvidia support installed in docker for it to work.

  • This contains the CUDA environment with the Tensorflow version so I can work with 1.15 and with the latest 2.x versions of Tensorflow on the same computer which require different CUDA versions.
  • It doesn't install anything besides docker stuff to get messy on the computer and difficult to pull back out.
  • I can still install Tensorflow natively on the computer at some point in the future when the libraries become availabe without compiling from source.

Here is the command which launches jupyter and mounts the current directory from my computer to /tf/bob which shows up in jupyter.

docker run -it --mount type=bind,source="$(pwd)",target=/tf/bob -u $(id -u):$(id -g) -p 8888:8888 tensorflow/tensorflow:1.15.2-gpu-py3-jupyter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM