ubuntu18.04安装tensorRT和重装cuda

1. 环境

查看cuda版本:

$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Thu_Jun_11_22:26:38_PDT_2020
Cuda compilation tools, release 11.0, V11.0.194
Build cuda_11.0_bu.TC445_37.28540450_0

查看cudnn版本:

$ find / -name cudnn_version.h 2>&1 | grep -v "Permission denied"
/home/zxq/Downloads/cudnn-11.0-linux-x64-v8.0.5/cuda/include/cudnn_version.h

# 由路径可知,我的是v8.0.5,与cuda11.0是匹配的就行。

cuda11.0+ cudnn8.0.5

2.安装TensorRT

严格按照官网操作,我下载的是nv-tensorrt-repo-ubuntu1804-cuda11.0-trt7.2.3.4-ga-20210226_1-1_amd64.deb,这需要注意,我选择的安装是deb安装方式,这里的前提是cuda必须也是deb安装的,不然就会报一堆的依赖错误,我的问题已经解决了,贴个示例。cuda卸载重装请看第3步。

The following packages have unmet dependencies.
 tensorrt : Depends: libnvinfer6 (= 6.0.1-1+cuda10.1) but it is not going to be installed
            Depends: libnvinfer-plugin6 (= 6.0.1-1+cuda10.1) but it is not going to be installed
            Depends: libnvparsers6 (= 6.0.1-1+cuda10.1) but it is not going to be installed
            Depends: libnvonnxparsers6 (= 6.0.1-1+cuda10.1) but it is not going to be installed
            Depends: libnvinfer-bin (= 6.0.1-1+cuda10.1) but it is not going to be installed
            Depends: libnvinfer-dev (= 6.0.1-1+cuda10.1) but it is not going to be installed
            Depends: libnvinfer-plugin-dev (= 6.0.1-1+cuda10.1) but it is not going to be installed
            Depends: libnvparsers-dev (= 6.0.1-1+cuda10.1) but it is not going to be installed
            Depends: libnvonnxparsers-dev (= 6.0.1-1+cuda10.1) but it is not going to be installed
            Depends: libnvinfer-samples (= 6.0.1-1+cuda10.1) but it is not going to be installed
            Depends: libnvinfer-doc (= 6.0.1-1+cuda10.1) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

是这个人提醒的我:

ubuntu18.04安装tensorRT和重装cuda_第1张图片

C++接口安装:

os="ubuntu1x04"
tag="cudax.x-trt7.x.x.x-ga-yyyymmdd"
sudo dpkg -i nv-tensorrt-repo-${os}-${tag}_1-1_amd64.deb
sudo apt-key add /var/nv-tensorrt-repo-${tag}/7fa2af80.pub

sudo apt-get update
sudo apt-get install tensorrt

验证C++接口安装成功:

dpkg -l | grep TensorRT

ubuntu18.04安装tensorRT和重装cuda_第2张图片

如果要安装python接口:

If using Python 2.7:
sudo apt-get install python-libnvinfer-dev
The following additional packages will be installed:
python-libnvinfer
If using Python 3.x:
sudo apt-get install python3-libnvinfer-dev
The following additional packages will be installed:
python3-libnvinfer

如果想要卸载tensorRT,可参考官方

3 cuda卸载重装。

各个版本的卸载方式可能不同,卸载官方文档的位置:/usr/local/cuda-10.0/doc/pdf/CUDA_Installation_Guide_Linux.pdf

sudo /usr/local/cuda-11.0/bin/cuda-uninstaller  # 卸载cuda

# 卸载显卡驱动,后面还要再做一边
# (1)卸载现有的显卡驱动
sudo apt-get purge nvidia*

# (2)如果是离线安装的
卸载驱动和安装一样,首先ctrl+Alt+F2进入命令行状态,然后停止lightdm
sudo service lightdm stop
或者
sudo /etc/init.d/lightdm stop

# 卸载
sudo /usr/bin/nvidia-uninstall

也可以
sudo apt-get install autoremove --purge nvidia*

deb方式按照cuda,按照官网来即可。

Installation Instructions:
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget http://developer.download.nvidia.com/compute/cuda/11.0.2/local_installers/cuda-repo-ubuntu1804-11-0-local_11.0.2-450.51.05-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1804-11-0-local_11.0.2-450.51.05-1_amd64.deb
sudo apt-key add /var/cuda-repo-ubuntu1804-11-0-local/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda

但是官网默认会再次安装显卡驱动,官网的安装的显卡驱动有问题,所以需要重新卸载显卡驱动,重新安装显卡驱动。

sudo apt --purge remove nvidia*

# 安装
$ ubuntu-drivers devices
== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
modalias : pci:v000010DEd00002204sv00007377sd0000140Abc03sc00i00
vendor   : NVIDIA Corporation
driver   : nvidia-driver-460 - third-party free
driver   : nvidia-driver-460-server - distro non-free recommended
driver   : xserver-xorg-video-nouveau - distro free builtin

$ sudo apt-get install nvidia-driver-460  # 推荐是server,都可以。

离线安装驱动,重启会黑屏。建议采用上面的方式安装驱动。

cudnn去官网下载和cuda匹配的版本。然后将里面解压的文件复制到cuda目录中,命令如下。

sudo cp cuda/include/* /usr/local/cuda/include

sudo cp cuda/lib64/* /usr/local/cuda/lib64

sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

环境配置。

sudo gedit ~/.bashrc

打开的文档末尾输入(cuda版本对应修改下):

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

验证显卡驱动是否安装成功。

$ nvidia-smi
Fri Apr  9 14:01:10 2021       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.67       Driver Version: 460.67       CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce RTX 3090    Off  | 00000000:01:00.0  On |                  N/A |
|  0%   42C    P8    31W / 350W |    206MiB / 24265MiB |     18%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1233      G   /usr/lib/xorg/Xorg                 78MiB |
|    0   N/A  N/A      1787      G   /usr/bin/gnome-shell               42MiB |
|    0   N/A  N/A      2172      G   ...AAAAAAAAA= --shared-files       82MiB |
+-----------------------------------------------------------------------------+

验证cuda是否安装成功。

$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Thu_Jun_11_22:26:38_PDT_2020
Cuda compilation tools, release 11.0, V11.0.194
Build cuda_11.0_bu.TC445_37.28540450_0

 

你可能感兴趣的:(环境搭建)