主要是根据工程环境需要,参考trt文档安装trt
下载完安装包后如下:
root@iZbp120zfnu5353tdx5hq7Z:/data/workspace/docker/trtfile/test# ls
cudnn-10.0-linux-x64-v7.6.3.30.tgz
解压后如下:
root@iZbp120zfnu5353tdx5hq7Z:/data/workspace/docker/trtfile/test# tar xvf cudnn-10.0-linux-x64-v7.6.3.30.tgz
cudnn-10.0-linux-x64-v7.6.3.30.tgz cudnn
复制cudnn中相关文件到系统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*
查看cudnn版本是否安装好(显示如下则成功):
root@3792e2c3dbce:/dacker/data/workspace/docker/torch2trt# cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
#define CUDNN_MAJOR 7
#define CUDNN_MINOR 6
#define CUDNN_PATCHLEVEL 3
--
#define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)
#include "driver_types.h"
下载完安装包并解压后如下:
root@iZbp120zfnu5353tdx5hq7Z:/data/workspace/docker/trtfile# ls
cuda cudnn-10.0-linux-x64-v7.6.3.30.tgz TensorRT-5.1.5.0 TensorRT-5.1.5.0.Ubuntu-16.04.5.x86_64-gnu.cuda-10.0.cudnn7.5.tar.gz
进入到解压目录中安装(根据你系统的版本安装相应的版本)
root@iZbp120zfnu5353tdx5hq7Z:/data/workspace/docker/trtfile/TensorRT-5.1.5.0/python# ls
tensorrt-5.1.5.0-cp27-none-linux_x86_64.whl tensorrt-5.1.5.0-cp35-none-linux_x86_64.whl tensorrt-5.1.5.0-cp37-none-linux_x86_64.whl
tensorrt-5.1.5.0-cp34-none-linux_x86_64.whl tensorrt-5.1.5.0-cp36-none-linux_x86_64.whl
root@iZbp120zfnu5353tdx5hq7Z:/data/workspace/docker/trtfile/TensorRT-5.1.5.0/python# pip install tensorrt-5.1.5.0-cp36-none-linux_x86_64.whl
配置环境变量:
$ vim ~/.bashrc # 打开环境变量文件
# 将下面环境变量写入环境变量文件并保存
export LD_LIBRARY_PATH=TensorRT解压路径/lib:$LD_LIBRARY_PATH
# 使刚刚修改的环境变量文件生效
$ source ~/.bashrc
#当cuda环境没有指定时,也需要指定
export CUDA_INSTALL_DIR=/usr/local/cuda-9.0
export CUDNN_INSTALL_DIR=/usr/local/cuda-9.0
测试TensorRT 是否安装成功,进入python编辑器加载tensorrt:
>>>import tensorrt
Traceback (most recent call last):
File "test.py", line 3, in
import torch2trt
File "/dacker/data/workspace/docker/torch2trt/torch2trt/__init__.py", line 1, in
from . import core, handlers
File "/dacker/data/workspace/docker/torch2trt/torch2trt/core.py", line 12, in
import tensorrt as trt
File "/dacker/data/workspace/docker/evenv_docker/lib/python3.6/site-packages/tensorrt/__init__.py", line 1, in
from .tensorrt import *
ImportError: libcudnn.so.7: cannot open shared object file: No such file or directory
这个问题根据报错情况和cudnn有关,首先排查cudnn是否安装正确(排查方法安装中有)如果有问题,重装一遍,如果没有问题,检查环境变量配置,将安装过程中的环境变量配置完整,即可。(以为cuda安装环境的问题,有时也会报此类错,如果以上两点没问题,需要添加库及打布丁)
#打开bashrc (打不开请用sudo,有些环境需要sudo才能打开)
vim ~/.bashrc
#在里面添加路径(也可指定cuda版本)
export PATH="/usr/local/cuda/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda/lib64:$LD_LIBRARY_PATH"
#使改变生效
source .bashrc #此时终端在用户名目录下 ~
#检查是否添加成功(下面两条语句会打印出刚才添加的内容)
echo $PATH
echo $LD_LIBRARY_PATH
英伟达官网:https://developer.nvidia.com/跳转