Ubuntu1804+CUDA10.0安装TensorRT7

本文详细介绍了在Ubuntu环境下使用两种不同方式安装TensorRT的方法,包括deb安装与local安装,并提供了依赖包安装步骤及测试样例,帮助读者顺利完成TensorRT的配置与验证。

1 下载

官网下载系统对应版本,一般分为deb和local 2种安装方式
在这里插入图片描述

2 安装

2.1 deb安装

deb是ubuntu下常用的一种安装包格式;安装前确保CUDA及CUDNN等已经安装好

  1. 首先安装tensorRT:

    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
    
  2. 安装其他依赖包:libnvinfer-doc

    #python2
    sudo apt-get install python-libnvinfer-dev
    
    #pyhon3
    sudo apt-get install python3-libnvinfer-dev
    
  3. 安装其他依赖包:uff-converter-tf

     sudo apt-get install uff-converter-tf
    
  4. 验证

    dpkg -l | grep TensorRT
    
  5. 问题
    这种deb安装方式要求CUDA也是deb格式安装的,否则容易出错(很多安装CUDA采用的是runfile格式)

2.2 local安装(推荐)

  1. 解压下载的安装文件,它是已经编译好的库

     version=”7.x.x.x”
     os=”<os>”
     arch=$(uname -m)
     cuda=”cuda-x.x”
     cudnn=”cudnn7.x”
     tar xzvf TensorRT-${version}.${os}.${arch}-gnu.${cuda}.${cudnn}.tar.gz
    
  2. 路径设置
    具体路径根据自己实际设置

     vim ~/.bashrc
     export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/xxx/xxx/TensorRT-7.0.0.11/lib
     source ~/.bashrc
    
  3. 依赖包安装:Python TensorRT
    依赖包都在下载的包中,根据自己python版本情况安装

     cd python
     sudo pip3 install tensorrt-7.0.0.11-cp36-none-linux_x86_64.whl
    
  4. 依赖包安装:Python UFF

     cd uff
     sudo pip3 install uff-0.6.5-py2.py3-none-any.whl
    
  5. 依赖包安装:Python Graphsurgeon

     cd graphsurgeon
     sudo pip3 install graphsurgeon-0.4.1-py2.py3-none-any.whl
    

3 测试

  1. 测试

     #下载测试数据
     cd data/mnist
     python3 download_pgms.py
    
     #编译测试
     cd samples/sampleMNIST
     make
    
     #运行
     cd ../../bin
     ./sample_mnist
    
  2. 正常情况下,输出:
    在这里插入图片描述

  3. 若报出链接库问题:
    如:
    ./sample_mnist: error while loading shared libraries: libnvrtc.so.10.0: cannot open shared object file: No such file or directory

    解决:

     	#链接库,可以先查找下该库在什么位置:sudo find / -name 'libnvrtc.so.10.0*'
         vim ~/.bashrc
     	export LD_PRELOAD=$LD_PRELOAD:/usr/local/cuda-10.0/lib64/libnvrtc.so.10.0
     	
     	#更新
     	source ~/.bashrc
     	sudo ldconfig
    
自编译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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值