feat: 开放 webgpu 推理配置 - #4
Merged
Merged
Conversation
There was a problem hiding this comment.
您好——我发现了 1 个问题
面向 AI Agent 的提示
请处理本次代码审查中的评论:
## 具体评论
### 评论 1
<location path="fastdeploy/runtime/backends/ort/ort_backend.cc" line_range="571" />
<code_context>
AdaptivePool2dOp* adaptive_pool2d =
new AdaptivePool2dOp{"CoreMLExecutionProvider"};
custom_operators_.push_back(adaptive_pool2d);
+ } else if (option_.device == Device::WEBGPU) {
+ AdaptivePool2dOp* adaptive_pool2d =
+ new AdaptivePool2dOp{"WebGpuExecutionProvider"};
+ custom_operators_.push_back(adaptive_pool2d);
} else {
AdaptivePool2dOp* adaptive_pool2d =
</code_context>
<issue_to_address>
**问题 (bug_risk):** WebGPU 自适应池化自定义算子注册时使用了提供程序名称 `WebGpuExecutionProvider`,而代码检测并追加的是 `WebGPUExecutionProvider`/`WebGPU`。ONNX Runtime 会根据完全匹配的执行提供程序名称来匹配自定义内核,因此包含此算子的模型不会使用已注册的 WebGPU 内核,并会失败或报告该算子不受支持。
**触发条件:** 启用 WebGPU 的模型包含自定义 AdaptivePool2d 算子时。
**建议修复:** 使用 ONNX Runtime WebGPU 执行提供程序所使用的确切提供程序名称注册该算子,并与传递给 `AppendExecutionProvider` 的提供程序名称保持一致。
```suggestion
new AdaptivePool2dOp{"WebGPU"};
```
</issue_to_address>Original comment in English
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="fastdeploy/runtime/backends/ort/ort_backend.cc" line_range="571" />
<code_context>
AdaptivePool2dOp* adaptive_pool2d =
new AdaptivePool2dOp{"CoreMLExecutionProvider"};
custom_operators_.push_back(adaptive_pool2d);
+ } else if (option_.device == Device::WEBGPU) {
+ AdaptivePool2dOp* adaptive_pool2d =
+ new AdaptivePool2dOp{"WebGpuExecutionProvider"};
+ custom_operators_.push_back(adaptive_pool2d);
} else {
AdaptivePool2dOp* adaptive_pool2d =
</code_context>
<issue_to_address>
**issue (bug_risk):** The WebGPU adaptive-pooling custom operator is registered with the provider name `WebGpuExecutionProvider`, while the code detects and appends `WebGPUExecutionProvider`/`WebGPU`. ONNX Runtime matches custom kernels by the exact execution-provider name, so models containing this operator do not use the registered WebGPU kernel and fail or report the operator as unsupported.
**Triggers:** When a WebGPU-enabled model contains the custom AdaptivePool2d operator.
**Suggested fix:** Register the operator with the exact provider name used by the ONNX Runtime WebGPU execution provider, consistently with the provider name passed to `AppendExecutionProvider`.
```suggestion
new AdaptivePool2dOp{"WebGPU"};
```
</issue_to_address>onnxruntime 只在该 EP 参与构建时才把 <webgpu_provider_factory.h> 平铺安装出来 (cmake/onnxruntime.cmake 按 ONNXRUNTIME_PROVIDER_NAMES 逐个 provider glob), 且这个头文件只有注释、没有声明,WebGPU 走的是 generic SessionOptionsAppendExecutionProvider,因此用它做 __has_include 探测即可: - WITH_WEBGPU && __has_include(<webgpu_provider_factory.h>) => ENABLE_WEBGPU - BuildOption 的 WebGPU 分支加 #ifdef ENABLE_WEBGPU 守卫;未编入时告警并回退 CPUExecutionProvider,沿用 DML/CoreML 的软回退契约。此时 option_.device 已被 置为 CPU,后续 InitCustomOperators 会正确注册 CPU 版自定义算子 - 补齐 WebGPU 在错误信息/注释中的出现,并为 std::unordered_map 补显式 include
- install(EXPORT ... FILE fastdeploy_ppocrTargets.cmake) 搭配 configure_package_config_file 生成可编辑的 fastdeploy_ppocrConfig.cmake - find_dependency(OpenCV COMPONENTS core imgproc):导出的 target 链接 opencv_core/opencv_imgproc,下游若不先 find_package(OpenCV) 会在链接期报 ld: library 'opencv_core' not found - 静态包的 interface 带 $<LINK_ONLY:onnxruntime::onnxruntime>,故仅静态时 find_dependency(onnxruntime),并随包安装 cmake/Findonnxruntime.cmake,避免 依赖 onnxruntime 的 CMake 包恰好能被该名字找到 - $<INSTALL_INTERFACE:include>:CMAKE_INSTALL_INCLUDE 在本项目从未定义,原先 导出的 target 没有任何 include 目录 - 导出 fastdeploy_ppocr_WITH_WEBGPU 能力标记,取值与编译期探测同源
Author
|
Ready |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Sourcery 摘要
在运行时和受支持的模型中启用可配置的 ONNX Runtime WebGPU 推理。
新功能:
增强功能:
构建:
Original summary in English
Sourcery 摘要
在运行时配置、后端初始化、张量处理以及受支持的 OCR 模型中,实现可配置的 ONNX Runtime WebGPU 推理。
新功能:
错误修复:
增强功能:
构建:
Original summary in English
Sourcery 总结
支持在运行时配置、后端初始化、张量处理以及受支持的 OCR 模型中配置 ONNX Runtime WebGPU 推理。
新功能:
Bug 修复:
增强功能:
构建:
Original summary in English
Summary by Sourcery
Enable configurable ONNX Runtime WebGPU inference across runtime configuration, backend initialization, tensor handling, and supported OCR models.
New Features:
Bug Fixes:
Enhancements:
Build: