美文网首页
Ubuntu安装GPU版本tensorflow,Ubuntu i

Ubuntu安装GPU版本tensorflow,Ubuntu i

作者: 寽虎非虫003 | 来源:发表于2020-04-19 06:24 被阅读0次

    摘要

    基本按照官网来就行,但是也可以一看。

    前情提要

    Ubuntu下Python3.8.2安装虚拟环境virtualenv的出错与处理。Python3.8.2 install virtualenv wrong and solve.

    一、安装CUDA 10.1

    我的配置是GTX 1060MQ,仔细对比过,应该是属于1060吧。

    1.1 源命令

    按照官网GPU 支持的 “ 使用 apt 安装 CUDA” 一节的源命令:
    Ubuntu 18.04 (CUDA 10.1):

        # Add NVIDIA package repositories
        wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-repo-ubuntu1804_10.1.243-1_amd64.deb
        sudo dpkg -i cuda-repo-ubuntu1804_10.1.243-1_amd64.deb
        sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
        sudo apt-get update
        wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
        sudo apt install ./nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
        sudo apt-get update
    
        # Install NVIDIA driver
        sudo apt-get install --no-install-recommends nvidia-driver-418
        # Reboot. Check that GPUs are visible using the command: nvidia-smi
    
        # Install development and runtime libraries (~4GB)
        sudo apt-get install --no-install-recommends \
            cuda-10-1 \
            libcudnn7=7.6.4.38-1+cuda10.1  \
            libcudnn7-dev=7.6.4.38-1+cuda10.1
        
    
        # Install TensorRT. Requires that libcudnn7 is installed above.
        sudo apt-get install -y --no-install-recommends libnvinfer6=6.0.1-1+cuda10.1 \
            libnvinfer-dev=6.0.1-1+cuda10.1 \
            libnvinfer-plugin6=6.0.1-1+cuda10.1
    

    Ubuntu 16.04 (CUDA 10.1):

        # Add NVIDIA package repositories
        # Add HTTPS support for apt-key
        sudo apt-get install gnupg-curl
        wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_10.1.243-1_amd64.deb
        sudo dpkg -i cuda-repo-ubuntu1604_10.1.243-1_amd64.deb
        sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
        sudo apt-get update
        wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64/nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb
        sudo apt install ./nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb
        sudo apt-get update
    
        # Install NVIDIA driver
        # Issue with driver install requires creating /usr/lib/nvidia
        sudo mkdir /usr/lib/nvidia
        sudo apt-get install --no-install-recommends nvidia-418
        # Reboot. Check that GPUs are visible using the command: nvidia-smi
    
        # Install development and runtime libraries (~4GB)
        sudo apt-get install --no-install-recommends \
            cuda-10-1 \
            libcudnn7=7.6.4.38-1+cuda10.1  \
            libcudnn7-dev=7.6.4.38-1+cuda10.1
        
    
        # Install TensorRT. Requires that libcudnn7 is installed above.
        sudo apt-get install -y --no-install-recommends \
            libnvinfer6=6.0.1-1+cuda10.1 \
            libnvinfer-dev=6.0.1-1+cuda10.1 \
            libnvinfer-plugin6=6.0.1-1+cuda10.1
    
    

    Ubuntu 16.04(CUDA 9.0,TensorFlow 1.13.0 以下版本):

        # Add NVIDIA package repository
        sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
        wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.1.85-1_amd64.deb
        sudo apt install ./cuda-repo-ubuntu1604_9.1.85-1_amd64.deb
        wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64/nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb
        sudo apt install ./nvidia-machine-learning-repo-ubuntu1604_1.0.0-1_amd64.deb
        sudo apt update
    
        # Install the NVIDIA driver
        # Issue with driver install requires creating /usr/lib/nvidia
        sudo mkdir /usr/lib/nvidia
        sudo apt-get install --no-install-recommends nvidia-410
        # Reboot. Check that GPUs are visible using the command: nvidia-smi
    
        # Install CUDA and tools. Include optional NCCL 2.x
        sudo apt install cuda9.0 cuda-cublas-9-0 cuda-cufft-9-0 cuda-curand-9-0 \
            cuda-cusolver-9-0 cuda-cusparse-9-0 libcudnn7=7.2.1.38-1+cuda9.0 \
            libnccl2=2.2.13-1+cuda9.0 cuda-command-line-tools-9-0
    
        # Optional: Install the TensorRT runtime (must be after CUDA install)
        sudo apt update
        sudo apt install libnvinfer4=4.1.2-1+cuda9.0
    
    

    1.2 安装

    直接根据自己的系统和需要安装的源代码建立一个.sh文件进行安装,我是在虚拟环境当中进行安装的:

    #激活虚拟环境,不是完全必要
    source ./virPy/bin/activate 
    
    #新建一个文件夹及文件存放上面选择的命令,以及方便管理下载的包
    mkdir cuda_install
    subl install.sh     #建立sh文件,并将1.1中复制的命令粘贴进去
    
    #安装
    sudo sh intall.sh
    

    然后等待执行完以后reboot,使用nvidia-smi检查安装情况:
    输入:

    nvidia-smi
    

    输出如下则安装成功:

    Sun Apr 19 05:50:40 2020       
    +-----------------------------------------------------------------------------+
    | NVIDIA-SMI 418.87.01    Driver Version: 418.87.01    CUDA Version: N/A      |
    |-------------------------------+----------------------+----------------------+
    | GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
    | Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
    |===============================+======================+======================|
    |   0  GeForce GTX 106...  Off  | 00000000:01:00.0 Off |                  N/A |
    | N/A   60C    P0    25W /  N/A |    206MiB /  6078MiB |      0%      Default |
    +-------------------------------+----------------------+----------------------+
                                                                                   
    +-----------------------------------------------------------------------------+
    | Processes:                                                       GPU Memory |
    |  GPU       PID   Type   Process name                             Usage      |
    |=============================================================================|
    |    0      1185      G   /usr/lib/xorg/Xorg                           162MiB |
    |    0      2060      G   compiz                                        42MiB |
    +-----------------------------------------------------------------------------+
    
    

    二、安装tensorflow

    直接执行:

    pip install tensorflow
    

    全文完

    相关文章

      网友评论

          本文标题:Ubuntu安装GPU版本tensorflow,Ubuntu i

          本文链接:https://www.haomeiwen.com/subject/qxtrbhtx.html