安装前提
CUDA 10.2或11.0 RC,cudnn8.0,以上都安装完成的情况下开始安装tensorrt。
怎么安装cuda和cudnn参考之前安装pytorch的教程。
安装步骤
先去nvidia官网下载Windows版本匹配的TensorRT zip文件。https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html#downloading
解压zip文件
1.7.x.x.x(含TensorRT版本)
2.cuda-x.x和cuda版本,以及
3.cudnnx.x和cuDNN版本供您下载。
将TensorRT库文件添加到系统路径中。
将DLL文件从/lib复制到CUDA安装目录,例如C:\Program files\NVIDIA GPU Computing Toolkit\CUDA\vX.Y\bin,其中vX.Y是CUDA版本。(CUDA路径要添加到环境变量下)
验证安装前的准备
若要验证安装是否正常,应打开VisualStudio解决方案文件的示例,比如“Hello World” For TensorRT (sampleMNIST),并确认您能够生成和运行该示例。
打开visual studio的项目>属性,确认以下已被添加
1.<tensorrt安装目录>/lib 已被加到 PATH variable 并且在visual studio的VC++目录 > 可执行目录下.
2.<tensorrt安装目录>/include 在C/C++ > 常规 > 附加包含目录.
3.nvinfer.lib 和其他所有需要的 LIB文件 都在 链接器 > 输入 > 附加依赖项
注意:为了构建包含的示例,要先安装VisualStudio2017(https://visualstudio.microsoft.com/downloads/)。
直接选社区版就足够用于运行项目了。
如果使用的是TensorFlow,先安装uff和graphsurgeon 的whl文件。(在tensorrt文件夹下找到这俩whl文件,然后直接pip install 安装就行)
验证安装
打开tensorrt解压后文件夹下的sample
随便找一个运行一下
点击.sln的文件,自动打开visualstudio运行,这时会出现如下报错,其实说白了就是没找到mnist数据集
去tensorrt目录下的data文件夹找到对应数据集的download_pgms.py,然后运行就可以了,运行的时候没输出,等一会看到文件夹下有了x.pgm文件就说明下载好了
这时候再运行,已然是成了
以下是官方文档原文
4.4. Zip File Installation
This section contains instructions for installing TensorRT from a zip file.
Before you begin
Ensure that you have the following dependencies installed.
About this task
This section contains instructions for installing TensorRT from a zip package on Windows 10.
Procedure
- Download the TensorRT zip file that matches the Windows version you are using.
- Choose where you want to install TensorRT. The zip file will install everything into a subdirectory called TensorRT-7.x.x.x. This new subdirectory will be referred to as <installpath> in the steps below.
- Unzip the TensorRT-7.x.x.x.Windows10.x86_64.cuda-x.x.cudnnx.x.zip file to the location that you chose. Replace:
- 7.x.x.x with the TensorRT version
- cuda-x.x with the CUDA version, and
- cudnnx.x with the cuDNN version for your particular download.
- Add the TensorRT library files to your system PATH. There are two ways to accomplish this task:
- Leave the DLL files where they were unzipped and add <installpath>/lib to your system PATH. You can add a new path to your system PATH using the steps below.
- Press the Windows key and search for "environment variables" which should present you with the option Edit the system environment variables and click it.
- Click Environment Variables… at the bottom of the window.
- Under System variables, select Path and click Edit….
- Click either New or Browse to add a new item that contains <installpath>/lib.
- Continue to click OK until all the newly opened windows are closed.
- If your cuDNN libraries were not copied to the CUDA installation directory and instead left where they were unzipped, then repeat the above steps for the cuDNNbin directory.
- Copy the DLL files from <installpath>/lib to your CUDA installation directory, for example, C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\vX.Y\bin, where vX.Y is your CUDA version. The CUDA installer should have already added the CUDA path to your system PATH.
- Leave the DLL files where they were unzipped and add <installpath>/lib to your system PATH. You can add a new path to your system PATH using the steps below.
- To verify that your installation is working you should open a Visual Studio Solution file from one of the samples, such as “Hello World” For TensorRT (sampleMNIST), and confirm that you are able to build and run the sample. If you want to use TensorRT in your own project, ensure that the following is present in your Visual Studio Solution project properties:
- <installpath>/lib has been added to your PATH variable and is present under VC++ Directories > Executable Directories.
- <installpath>/include is present under C/C++ > General > AdditionalDirectories.
- nvinfer.lib and any other LIB files that your project requires are present under Linker > Input > Additional Dependencies.Note: In order to build the included samples, you should have Visual Studio 2017 (https://visualstudio.microsoft.com/downloads/) installed. The community edition is sufficient to build the TensorRT samples.
- If you are using TensorFlow install the uff and graphsurgeon wheel packages. You must prepare the Python environment before installing uff and graphsurgeon.If using Python 2.7:python -m pip install <installpath>\graphsurgeon\graphsurgeon-0.4.5-py2.py3-none-any.whl python -m pip install <installpath>\uff\uff-0.6.9-py2.py3-none-any.whl If using Python 3.x:python3 -m pip install <installpath>\graphsurgeon\graphsurgeon-0.4.5-py2.py3-none-any.whl python3 -m pip install <installpath>\uff\uff-0.6.9-py2.py3-none-any.whl