Ubuntu18.04安装CUDA10.1+CUDNN7.6.5.32+TensorRT-6.0.1.5(GTX1070)

       因为学习CUDA编程,需要搭建CUDA编程环境,需要用到TensorRT,所以连TensorRT一块安装了,安装之前最重要的一步就是确认自己的显卡是不是支持CUDA编程,支持cuda的显卡只有NVidia的显卡,NVidia的显卡有GTX Geforce, Quadra 和 Tesla三个大系列,根据自己的显卡型号去以下网站查询对应的CUDA版本:

https://developer.nvidia.com/cuda-gpus

如下图所示,发现我的显卡GTX1070是支持的。

确认自己的显卡是支持CUDA编程后,开始刺激惊险的安装之旅了,前方有坑,不要怕。

一.安装Ubuntu18.04

1.去下载网站:http://releases.ubuntu.com/bionic/ 下载ubuntu-18.04.5-desktop-amd64.iso安装包

2.找个U盘制作安装盘(假设你已会,用UltraISO软件制作)

3.插上U盘,BIOS设置成U盘启动,开始系统安装之旅,一路默认下去,很快就会安装好。

坑:安装过程不要选择安装后自动下载更新,否则会是漫长的等待。

二.安装NVIDIA驱动

打开软件和更新,如下图:

 

点击后打开下图所示窗口:

单击“附加驱动”,进入下图所示界面:
 

 

选中要安装的版本,开始下载安装,完成后点击“应用修改”。

坑:好多文章指导自己下载驱动文件,用命令行的方式进行安装,看似高大上,命令一大堆,实际有许多坑,一步不小心,就会掉坑里,什么循环登录、界面太大,鼠标指针不动之类的问题。这种图形界面安装的方式也许是最省心的安装方式。

三.安装CUDA10.1

1.cuda安装包下载网址:https://developer.nvidia.com/cuda-10.1-download-archive-update2?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1804&target_type=runfilelocal

如下图所示,选择正确的版本,开始安装,不推荐选择deb类型,可能会安装失败。

按照网页上的安装指导指令,开始下载,如下图所示:

 

文件很大,2.6G,下载速度一般不会很快,以下就是漫长的等待,先喝杯咖啡消消火。

下载完成后开始安装,执行命令:

sudo sh cuda_10.1.243_418.87.00_linux.run

结果如下图所示:

选择Continue,进入下一界面:

最下面输入文本内容accpet,然后回车,进入下一界面:

把Driver项勾选掉,不安装驱动,只安装其他项,

[]内没有X就是没选中,这个X迷惑人,还以为带X的是不安装,其实正好相反,是安装的意思,估计没法把对号显示,才用X来表示的吧。

选中Install,回车,开始安装。

接下来开始添加环境变量

执行命令:

sudo gedit ~/.bashrc

打开文件后,将下面内容添加到文件的最后面,保存后退出

export PATH=/usr/local/cuda-10.1/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-10.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

然后设置环境变量和动态链接库,执行命令:

sudo gedit /etc/profile

在打开的文件末尾加入:

export PATH=/usr/local/cuda/bin:$PATH

保存后退出,然后创建链接文件,执行命令:

sudo gedit /etc/ld.so.conf.d/cuda.conf

在打开的文件中添加如下语句:

/usr/local/cuda/lib64

保存后退出,执行命令,使链接立即生效:

sudo ldconfig

输入命令,验证是否安装成功:

nvcc --version

若是安装成功,出现如下图所示信息:

cuda安装成功了!

四.安装CUDNN7.6.5.32

1.下载地址:https://developer.nvidia.com/rdp/cudnn-archive

打开下载网页之后,如下图所示,选择和cuda版本对应的版本,之所以选择7.6.5版本是因为要和TensorRT对应,如果选择了8.0.2,结果会找不到对应的tensorRT的版本。

使用命令解压文件cudnn-10.1-linux-x64-v7.6.5.32.tgz,并且复制到cuda路径中,命令如下图所示:

tar -zxvf cudnn-10.1-linux-x64-v7.6.5.32.tgz
cd cuda    
sudo cp lib64/lib* /usr/local/cuda/lib64/    
sudo cp include/cudnn.h /usr/local/cuda/include/ 

然后更新链接:

cd /usr/local/cuda/lib64/  
sudo chmod +r libcudnn.so.7.6.5  
sudo ln -sf libcudnn.so.7.6.5 libcudnn.so.7  
sudo ln -sf libcudnn.so.7 libcudnn.so  
sudo ldconfig 

查看cudnn版本是否安装好

cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2

如果出现下列显示,则安装成功

五、安装TensorRT

1.下载地址:https://developer.nvidia.com/nvidia-tensorrt-6x-download

要根据系统版本和cuda的版本来选择对应的TensorRT版本,一定要对应,否则会有问题,啥问题?就是版本不对的问题,如下图所示:

点击下载链接,等待下载完成,可以去喝杯咖啡了,下载完成后,文件如下图所示:

执行以下命令,解压tar包:

tar -xzvf TensorRT-6.0.1.5.Ubuntu-18.04.x86_64-gnu.cuda-10.1.cudnn7.6.tar.gz

得到TensorRT-6.0.1.5文件夹,把文件夹拷贝到指定目录下,目录自己指定,我是拷贝到了/usr/local/目录下,命令如下:

 sudo cp -r TensorRT-6.0.1.5 /usr/local/

添加环境变量:

export LD_LIBRARY_PATH=/usr/local/TensorRT-6.0.1.5/lib:$LD_LIBRARY_PATH
export CUDA_INSTALL_DIR=/usr/local/cuda-10.1
export CUDNN_INSTALL_DIR=/usr/local/cuda-10.1

执行source命令:

 source ~/.bashrc

安装是否成功,我还没有验证。

自编译tensorflow: 1.python3.5,tensorflow1.12; 2.支持cuda10.0,cudnn7.3.1,TensorRT-5.0.2.6-cuda10.0-cudnn7.3; 3.支持mkl,无MPI; 软硬件硬件环境:Ubuntu16.04,GeForce GTX 1080 配置信息: 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 编译: hp@dla:~/work/ts_compile/tensorflow$ bazel build --config=opt --config=mkl --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
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值