ubuntu16.04下nvidia-415.27 cuda-9.2 cudnn7.3.1 tensorflow-gpu 1.12安装

python 3.7版本目前和tensorflow兼容性不是很好,推荐使用:python 3.6
本人是之前装的anconda3装的python3.7,为了配置tensorflow又创建了py36环境安装python3.6

安装NVIDIA

用最简单的方法安装成功的:
最开始用指令安装失败了,重启进入不了图形界面,进入ubuntu之后黑屏有光标在闪
解决办法:ssh远程进入我的主机IP,卸载英伟达驱动,用ubuntu的software&update安装
software&update安装:打开software&update->Additional Driver->(这里可能需要禁用nouveau,但是我没 弄也装上了)——>选了一个号最大的415.27apply一下——>重启——>终端输入:nvidia-smi检查是否安装成功

安装cuda

安装之前查好对应版本,CUDA及其驱动兼容情况具体可参见:https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html
去官网https://developer.nvidia.com/cuda-92-download-archive?target_os=Linux&target_arch=x86_64下载自己想要的版本的文件
根据官网的提示进行安装,下图是我的版本信息:
在这里插入图片描述执行完以上四条语句:

    sudo dpkg -i cuda-repo-ubuntu1604-9-2-local_9.2.148-1_amd64.deb
    sudo apt-key add /var/cuda-repo-<version>/7fa2af80.pub
   	sudo apt-get update
    sudo apt-get install cuda

之后,参考链接https://blog.csdn.net/EliminatedAcmer/article/details/80528980
进行环境变量配置
配置环境变量,运行如下命令打开个人资料文件

sudo gedit  /etc/profile

打开文件后在文件末尾添加路径,也就是安装目录,命令如下:

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

保存,然后重启电脑,进入终端

cd  /usr/local/cuda-9.2/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery

如果result = PASS,则安装成功,否则失败,可能原因是环境未配置好,或者是cuda与驱动版本不兼容。

如果需要卸载重装,运行下列命令卸载 cuda

$ cd /usr/local/cuda/bin
$ sudo ./uninstall_cuda_9.2.pl

安装cudnn7.3.1

参考博客:https://blog.csdn.net/wgllovemother/article/details/82997320
官网https://developer.nvidia.com/rdp/cudnn-archive
下载三个包
在这里插入图片描述
注意:这三个文件都要下载。

使用如下命令安装:

$ cd ~/Downloads/    
$ ls    
$ sudo dpkg -i libcudnn7_7.3.1.20-1+cuda9.0_amd64.deb    
$ sudo dpkg -i libcudnn7-dev_7.3.1.20-1+cuda9.0_amd64.deb    
$ sudo dpkg -i libcudnn7-doc_7.3.1.20-1+cuda9.0_amd64.deb

安装完成

在我们验证cuDNN之前,我们必须首先安装freeimage lilbray作为ministCUDNN示例代码的依赖关系。否则,会有提示要求我们正确设置Freeimage

$ sudo apt-get install libfreeimage3 libfreeimage-dev

使用如下命令验证;

$ cp -r /usr/src/cudnn_samples_v7/ $HOME    
$ cd $HOME/cudnn_samples_v7/mnistCUDNN    
$ make clean && make    
$ ./mnistCUDNN

如果输出如下信息就表示安装cuDNN成功,并且还可以看到你机器上有几个支持cuda的设备。在这里插入图片描述

tensorflow-gpu 1.12安装

通过anaconda安装:

conda install tensorflow-gpu=1.12.0

检测是否安装成功
参考:https://blog.csdn.net/qq_36909753/article/details/87886263

"""
测试GPU的计算能力,测试tensorflow-GPU版是否安装正确
"""
import tensorflow as tf
import numpy as np
import time
 
value = np.random.randn(5000, 1000)
a = tf.constant(value)
 
b = a * a
 
c =0
tic = time.time()
with tf.Session() as sess:
        for i in range(1000):
            sess.run(b)
 
            c+=1
            if c%100 == 0:
 
                d = c / 10
                # print(d)
                print("计算进行%s%%" % d)
 
toc = time.time()
t_cost = toc - tic
 
print("测试所用时间%s"%t_cost)
print("Ubuntu上GPU为1050ti测试时间为7.99727988243103")

运行效果

2019-02-22 21:55:18.595152: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2019-02-22 21:55:18.673060: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:964] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-02-22 21:55:18.673437: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1411] Found device 0 with properties: 
name: GeForce GTX 1050 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.62
pciBusID: 0000:01:00.0
totalMemory: 3.95GiB freeMemory: 3.53GiB
2019-02-22 21:55:18.673448: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1490] Adding visible gpu devices: 0
2019-02-22 21:55:18.881182: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-02-22 21:55:18.881208: I tensorflow/core/common_runtime/gpu/gpu_device.cc:977]      0 
2019-02-22 21:55:18.881213: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990] 0:   N 
2019-02-22 21:55:18.881315: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1103] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 3247 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1050 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1)
计算进行10.0%
计算进行20.0%
计算进行30.0%
计算进行40.0%
计算进行50.0%
计算进行60.0%
计算进行70.0%
计算进行80.0%
计算进行90.0%
计算进行100.0%
测试所用时间8.04111933708191
Ubuntu上GPU为1050ti测试时间为7.99727988243103

Process finished with exit code 0

完。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
自编译tensorflow: 1.python3.5,tensorflow1.12; 2.支持cuda10.0,cudnn7.3.1,TensorRT-5.0.2.6-cuda10.0-cudnn7.3; 3.无mkl支持; 软硬件硬件环境:Ubuntu16.04,GeForce GTX 1080 TI 配置信息: hp@dla:~/work/ts_compile/tensorflow$ ./configure WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown". You have bazel 0.19.1 installed. Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3 Found possible Python library paths: /usr/local/lib/python3.5/dist-packages /usr/lib/python3/dist-packages Please input the desired Python library path to use. Default is [/usr/local/lib/python3.5/dist-packages] Do you wish to build TensorFlow with XLA JIT support? [Y/n]: XLA JIT support will be enabled for TensorFlow. Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: No OpenCL SYCL support will be enabled for TensorFlow. Do you wish to build TensorFlow with ROCm support? [y/N]: No ROCm support will be enabled for TensorFlow. Do you wish to build TensorFlow with CUDA support? [y/N]: y CUDA support will be enabled for TensorFlow. Please specify the CUDA SDK version you want to use. [Leave empty to default to CUDA 10.0]: Please specify the location where CUDA 10.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /usr/local/cuda-10.0 Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7]: 7.3.1 Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda-10.0]: Do you wish to build TensorFlow with TensorRT support? [y/N]: y TensorRT support will be enabled for TensorFlow. Please specify the location where TensorRT is installed. [Default is /usr/lib/x86_64-linux-gnu]://home/hp/bin/TensorRT-5.0.2.6-cuda10.0-cudnn7.3/targets/x86_64-linux-gnu Please specify the locally installed NCCL version you want to use. [Default is to use https://github.com/nvidia/nccl]: Please specify a list of comma-separated Cuda compute capabilities you want to build with. You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus. Please note that each additional compute capability significantly increases your build time and binary size. [Default is: 6.1,6.1,6.1]: Do you want to use clang as CUDA compiler? [y/N]: nvcc will be used as CUDA compiler. Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: Do you wish to build TensorFlow with MPI support? [y/N]: No MPI support will be enabled for TensorFlow. Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native -Wno-sign-compare]: Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: Not configuring the WORKSPACE for Android builds. Preconfigured Bazel build configs. You can use any of the below by adding "--config=" to your build command. See .bazelrc for more details. --config=mkl # Build with MKL support. --config=monolithic # Config for mostly static monolithic build. --config=gdr # Build with GDR support. --config=verbs # Build with libverbs support. --config=ngraph # Build with Intel nGraph support. --config=dynamic_kernels # (Experimental) Build kernels into separate shared objects. Preconfigured Bazel build configs to DISABLE default on features: --config=noaws # Disable AWS S3 filesystem support. --config=nogcp # Disable GCP support. --config=nohdfs # Disable HDFS support. --config=noignite # Disable Apacha Ignite support. --config=nokafka # Disable Apache Kafka support. --config=nonccl # Disable NVIDIA NCCL support. Configuration finished 编译: bazel build --config=opt --verbose_failures //tensorflow/tools/pip_package:build_pip_package 卸载已有tensorflow: hp@dla:~/temp$ sudo pip3 uninstall tensorflow 安装自己编译的成果: hp@dla:~/temp$ sudo pip3 install tensorflow-1.12.0-cp35-cp35m-linux_x86_64.whl
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值