ubuntu 16.04 笔记本双显卡安装tensorflow-

作者: 谢昆明 | 来源:发表于2018-11-21 19:59 被阅读0次

    环境
    联想笔记本 Y430P
    ubuntu 16.04
    GeForce GTX 850M
    python3
    tensorflow-gpu

    前言

    ubuntu默认使用集显,不支持CUDA,因此需要切换成独显GeForce GTX 850M。

    CUDA必须是3.5以上的,GeForce GTX 850M是5.0
    NVIDIA® GPU card with CUDA® Compute Capability 3.5 or higher

    1. 安装显卡切换软件

    sudo add-apt-repository ppa:nilarimogard/webupd8    #添加PPA更新源
    sudo apt-get update                                 #刷新更新源列表
    sudo apt-get install prime-indicator                #安装双显卡切换指示器
    

    重启,右上角会有NVIDIA的图标


    image.png

    2. 禁用系统默认驱动

    sudo chmod 666 /etc/modprobe.d/blacklist.conf       #修改blacklist.conf权限为可写可运行
    sudo vim /etc/modprobe.d/blacklist.conf           #打开blacklist.conf
    

    文件末尾添加这一行

    blacklist nouveau
    

    3. 查看GTX850M官方驱动的版本

    最新的驱动是410

    image.png

    4. Ctrl+Alt+F1进入命令行模式

    sudo service lightdm stop           #关闭图形系统
    sudo apt-get install nvidia-410     #也就是刚才看的410
    sudo reboot            #重启
    

    5. 安装CUDA

    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 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
    

    6. 安装tensorflow-gpu

    pip3 install tensorflow-gpu
    

    7. 测试代码,第一次运行时间很长

    python3 1_tf_reduce_mean.py

    # 1_tf_reduce_mean.py
    
    import tensorflow as tf
    import numpy as np
    
    #  Computes the mean of elements across dimensions of a tensor. (deprecated arguments)
    
    #  tf.reduce_mean(
    #      input_tensor,
    #      axis=None,
    #      keepdims=None,
    #      name=None,
    #      reduction_indices=None,
    #      keep_dims=None
    #      )
    
    c = np.array([[3.,4], [5.,6], [6.,7]])
    
    step = tf.reduce_mean(c, 1)
    with tf.Session() as sess:
        print(sess.run(step))
    

    相关文章

      网友评论

        本文标题:ubuntu 16.04 笔记本双显卡安装tensorflow-

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