【ONNXRuntime】Win10 GPU环境 ONNXRuntime下载与VS开发配置

ONNXRuntime下载

        下载地址:Releases · microsoft/onnxruntime (github.com)

        在下载地址找到对应版本,历史版本在Assets点开折叠后可以看到,可下载内容如下,如果需要支持GPU需要下载对应版本。

         也可以通过指定版本的地址直接定位到想要的版本,例如1.8.0

https://github.com/microsoft/onnxruntime/releases/tag/v1.8.0

GPU环境准备

        因为onnxruntime官方不支持windows编译(编译需要的Nvidia NCCL不支持widows),所以使用release包时需要使用比较严格对应的CUDA和cudnn,参考安装说明。但实际测试发现也并非严格对应,比如1.10.0可以用1.8.0的环境,但不能用1.6.0的环境。

Please reference table below for official GPU packages dependencies for the ONNX Runtime inferencing package. Note that ONNX Runtime Training is aligned with PyTorch CUDA versions; refer to the Training tab on https://onnxruntime.ai/ for supported versions.

Note: Because of CUDA Minor Version Compatibility, Onnx Runtime built with CUDA 11.4 should be compatible with any CUDA 11.x version. Please reference Nvidia CUDA Minor Version Compatibility.

ONNX RuntimeCUDAcuDNNNotes
1.1011.48.2.4 (Linux)
8.2.2.26 (Windows)
libcudart 11.4.43
libcufft 10.5.2.100
libcurand 10.2.5.120
libcublasLt 11.6.1.51
libcublas 11.6.1.51
libcudnn 8.2.4
1.911.48.2.4 (Linux)
8.2.2.26 (Windows)
libcudart 11.4.43
libcufft 10.5.2.100
libcurand 10.2.5.120
libcublasLt 11.6.1.51
libcublas 11.6.1.51
libcudnn 8.2.4
1.811.0.38.0.4 (Linux)
8.0.2.39 (Windows)
libcudart 11.0.221
libcufft 10.2.1.245
libcurand 10.2.1.245
libcublasLt 11.2.0.252
libcublas 11.2.0.252
libcudnn 8.0.4
1.711.0.38.0.4 (Linux)
8.0.2.39 (Windows)
libcudart 11.0.221
libcufft 10.2.1.245
libcurand 10.2.1.245
libcublasLt 11.2.0.252
libcublas 11.2.0.252
libcudnn 8.0.4
1.5-1.610.28.0.3CUDA 11 can be built from source
1.2-1.410.17.6.5Requires cublas10-10.2.1.243; cublas 10.1.x will not work
1.0-1.110.07.6.4CUDA versions from 9.1 up to 10.1, and cuDNN versions from 7.1 up to 7.4 should also work with Visual Studio 2017

For older versions, please reference the readme and build pages on the release branch.

        以CUDA11.0.3和cudnn8.0.2.39下载环境安装,CUDA只安装runtime和development,cudnn解压放到cuda安装目录即可。

VS开发配置

工程属性

C/C++ -> Additional Include Directories添加:

D:\libs\onnxruntime-win-x64-gpu-1.10.0\include

Linker -> Additional Library Directories添加:

D:\libs\onnxruntime-win-x64-gpu-1.10.0\lib

Linker -> Input -> Additional

onnxruntime.lib

使用时

#include <onnxruntime_cxx_api.h>

如果cuda/cudnn环境与onnxruntime不适配,在session.run()时会报错,例如:

Unhandled exception at 0x00007FF84C9D313C (cudnn64_8.dll) in onnx.exe: Fatal program exit requested.

### Windows 10 上编译 ONNX Runtime 的方法 要在 Windows 10 上成功编译 ONNX Runtime,可以按照以下方式完成环境配置和具体操作: #### 环境准备 确保安装并配置好所需的开发工具和依赖项。以下是必要的组件及其版本需求: - **Git**: 安装最新版 Git 工具用于克隆仓库。 - **Visual Studio (VS)**: 推荐使用 Visual Studio 2019 或更高版本[^3]。需启用 C++ 开发工作负载以及相关选项(如 MSBuild 和 vcpkg 支持)。 - **Python**: Python 版本应为 3.7 至 3.10 范围内的稳定版本。 #### 克隆源码库 通过命令行执行如下指令获取最新的 ONNX Runtime 源代码,并同步子模块文件: ```bash git clone -b rel-1.11.1 --recursive https://github.com/microsoft/onnxruntime.git cd onnxruntime git submodule update --init --recursive ``` #### 配置构建参数 进入管理员权限下的 `x64 Native Tools Command Prompt for VS` 命令窗口,切换至项目目录后运行脚本来设置目标平台架构和其他特性开关。例如针对 CPU 构建可采用默认设定;如果计划集成 TensorRT,则需要额外指定路径及相关标志位处理可能遇到的编码错误问题[^2]: ```cmd .\build.bat --config RelWithDebInfo --use_tensorrt --tensorrt_home "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\vXX.X" set PYTHONIOENCODING=utf8 ``` 这里设置了 UTF-8 编码来规避潜在字符集冲突引发异常情况的发生。 #### 启动实际编译过程 当上述准备工作完成后即可正式开始编译动作,在同一终端继续输入下面这句启动整个流程: ```cmd msbuild /p:Configuration=RelWithDebInfo ./windows/build/ONNXRuntime.sln ``` 等待一段时间直至全部任务结束即代表顺利完成本地化定制版本生成作业。 --- ### 注意事项 对于部分特殊场景可能会碰到一些棘手状况比如提到过的 UnicodeEncodeError 错误消息显示无法转换某些特定字符串到 GBK 字符集中去解决办法已经在前面有所提及调整 python io 默认编码形式从而绕过该障碍物。 另外值得注意的是官方文档里给出的例子往往基于较新发行号所以最好参照当前所处分支标签选取恰当指南资料以免因API变更造成不必要的麻烦同时也可以关注社区反馈寻找更贴近实际情况解决方案[^1]。 ---
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值