【ubuntu】安装tensorRT

发布于 2019-09-26 作者 风铃 54次 浏览 版块 前端

**tensorRT官方安装文档TensorRT3-Installation-Guide-RC.pdf位于tensorRT下载页面**

1,tensorRT下载,将tensorRT下载到想要安装的目录

https://developer.nvidia.com/rdp/form/tensorrt3RC-download-survey

注:tensorRT官方提供两种安装版本tar和deb安装,但用deb安装多次均未成功,以下只列出了tar安装教程

2,需要预先安装CUDA Toolkit8.0 or9.0 cuDNN7.0 python2/3

CUDA安装教程:http://blog.csdn.net/xll_bit/article/details/78304722

cudnn安装教程:http://blog.csdn.net/xll_bit/article/details/78373576

3,解压tar文件,解压完会出现TensorRT.-3.0.0,这个目录下面会包含lib,bin等文件

tar -xzvf TensorRT-3.0.0.Ubuntu-16.04.3.cuda-9.0.tar.gz(此命令根据下载位置不同有可能需要sudo权限)

4,添加环境变量

vim ~/.bashrc 

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<eg:TensorRT-3.0.0/lib>

source ~/.bashrc

5,安装python tensorRT包

$ cd TensorRT-3.0.0/python #转到解压后的python目录

对于python2.7

$ sudo pip2 install tensorrt-3.0.0-cp27-cp27mu-linux_x86_64.whl

对于python3.5

$ sudo pip3 install tensorrt-3.0.0-cp35-cp35m-linux_x86_64.whl

测试 tensorRT是否安装成功

$ which tensorrt
/usr/local/bin/tensorrt

**此步骤我在一台服务器上能运行通过,在另一台服务器上运行报错**

错误记录:

In file included from src/cpp/cuda.cpp:1:0:
    src/cpp/cuda.hpp:14:18: fatal error: cuda.h: No such file or directory
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

显示是找不到cuda.h,根据网上分析是因为用了sudo之后环境变量用的是root的环境变量

具体可参考https://codeyarns.com/2015/07/31/pip-install-error-with-pycuda/

主要原因是安装pycuda时依赖cuda库,sudo之后找不到所以出错

解决方法:

vim /etc/profile.d/cuda.sh

添加:export PATH=/usr/local/cuda-8.0/bin:$PATH

$ sudo su -

$ pip2 install tensorrt-3.0.0-cp27-cp27mu-linux_x86_64.whl --trusted-host pypi.douban.com

$ exit

6,安装UFF包

转到uff目录下

sudo pip2 install uff-0.1.0rc0-py2.py3-none-any.whl

或 sudo pip3 install uff-0.1.0rc0-py2.py3-none-any.whl

测试:

$ which convert-to-uff
/usr/local/bin/convert-to-uff

7,复制lenet5.uff文件到相应目录

sudo cp TensorRT-3.0.0/data/mnist/lenet5.uff TensorRT-3.0.0/python/data/mnist/lenet5.uff

8,验证

cd TensorRT-3.0.0/samples/sampleMNIST

sudo make clean

sudo make

cd /TensorRT-3.0.0/bin(转到bin目录下面,make后的可执行文件在此目录下)

sudo ./sample_mnist

tensorrt2安装:

解压tar文件到指定目录

tar -jxvf TensorRT-2.1.2.x86_64.cuda-8.0-14-04.tar.bz2 -C /opt

添加环境变量:(~/.bashrc  or  /etc/profile)

export CUDA_INSTALL_DIR=/usr/local/cuda-8.0
export CUDNN_INSTALL_DIR=/usr/local/cuda-8.0
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/TensorRT-2.1.2/lib

验证同tensorrt3




收藏
暂无回复