Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
问题描述:
当使用以下 CMAKE 参数:
同时设置以下环境变量:
通常,这个时候无论我们自定义的 ONNX 是链接静态 ONNX 还是动态 ONNX, DML 都应该由选项
DSHERPA_ONNX_ENABLE_DIRECTML
决定,一旦 DML 开启,现有的 cmake 文件onnxruntime-win-x64-directml.cmake
会强制下载一个 onnruntime (包含 DML),而不再遵循SHERPA_ONNXRUNTIME_INCLUDE_DIR
和SHERPA_ONNXRUNTIME_INCLUDE_DIR
(自定义路径将无效)。这个 PR 优先考虑用户自定义 onnxruntime 路径, 两种情况:
如果自定义路径中是动态链接库,那么仅下载 DIRECTML 包,由于 DML 包的 .lib 兼容性良好,链接库的版本影响不大(测试 1.0-1.15 都可以使用同一个 .lib 来链接 C++ 符号),最终用户可以选择自己发布自己 onnxruntime 并附加任意版本的 directml.dll 来得到想要的输出,而不是被强制覆盖到
onnxruntime-win-x64-directml.cmake
,这个 PR 可以 fix 掉问题。如果自定义路径中是静态链接库(例如使用我这里提供的预编译静态库),那么情况会变得复杂。
编译一个带有 DML 的 ONNX 静态链接后,使用时候还需要链接系统中的 D3D 符号和 directml.lib 文件,解决这个问题,添加一个选项
SHERPA_ONNX_LINK_D3D
让用户自行控制是否连接 D3D 相关符号,同时,sherpa-onnx\csrc\CMakeList.txt
中添加代码:以上代码检查,目标 directml (onnxruntime-win-x64-directml.cmake 生效时) 存在时,core 依赖 dicrectml, 我相信无论静态编译还是动态编译这个代码都不会有副作用,已经编译动态库并测试成功。
PS: 通过连接一个预编译的 ORT 静态库(带 DML ), 可以让整个 sharpa onnx 仅依赖 directml.dll, 减少 onnxruntime.dll 依赖,这样避免复杂项目中 onnxruntime 库冲突问题。