| [feat] 支持动态注册算子后刷新 CustomOpsKernelInfoStore
Co-authored-by: thj<tanghaojie1@huawei.com>
# message auto-generated for no-merge-commit merge:
!2236 merge custom_op_adapt into develop
[feat] 支持动态注册算子后刷新 CustomOpsKernelInfoStore
Created-by: tang-haojie
Commit-by: thj
Merged-by: cann-robot
Description:
# Pull Request
## 描述
问题背景
CustomOpsKernelInfoStore 在 Initialize() 时从 CustomOpFactory 读取已注册算子并缓存到 op_info_map_。当用户通过 dlopen 动态加载新的算子 SO 文件后,这些新注册的算子无法被感知,导致编译时找不到算子信息。
解决方案
1. 基类增加 Refresh() 虚方法:在 OpsKernelInfoStore 基类添加虚方法 Refresh()(默认空实现返回 SUCCESS),仅 CustomOpsKernelInfoStore 需实现,其他子类使用默认实现。
2. OpsKernelManager 增加刷新入口:新增 RefreshOpsKernelInfo() 方法,遍历所有 OpsKernelInfoStore 调用其 Refresh()。
3. PreRun 入口触发刷新:在 graph_manager.cc 的 PreRun() 函数入口调用刷新,确保编译前能感知新注册的算子。
4. 线程安全:CustomOpsKernelInfoStore 添加 std::mutex mu_ 保护 op_info_map_,所有访问方法(Initialize、Finalize、Refresh、GetAllOpsKernelInfo、CheckSupported)均加锁。
5. 代码封装:Initialize() 和 Refresh() 的公共逻辑提取为私有方法 UpdateOpInfoMap()。
修改文件
文件 变更内容
inc/graph_metadef/common/opskernel/ops_kernel_info_store.h 添加 virtual Status Refresh() 虚方法(置于类末尾,兼容性考虑)
compiler/engines/custom_engine/custom_ops_kernel_info_store.h 添加 mutable std::mutex mu_ 成员、Refresh() override 声明、UpdateOpInfoMap() 声明
compiler/engines/custom_engine/custom_ops_kernel_info_store.cc 实现 Refresh()、UpdateOpInfoMap(),所有访问 op_info_map_ 的方法加锁
compiler/engines/manager/opskernel_manager/ops_kernel_manager.h 添加 RefreshOpsKernelInfo() 声明
compiler/engines/manager/opskernel_manager/ops_kernel_manager.cc 实现 RefreshOpsKernelInfo()
compiler/graph/manager/graph_manager.cc PreRun() 入口调用 OpsKernelManager::GetInstance().RefreshOpsKernelInfo()
使用场景
用户在模型编译前动态加载算子 SO(如插件式算子扩展),刷新机制确保编译流程能正确获取新算子的 kernel 信息。
## 变更类型
请选择本次引入的变更类型:
<!-- [x] 表示选中 -->
- [ ] 🐛 Bug 修复
- [x] ✨ 新功能
- [ ] 💄 代码风格更新(格式化,局部变量)
- [ ] ♻️ 重构(既不修复错误也不增加功能的代码变动)
- [ ] 📦 构建过程或辅助工具的变动
- [ ] 📝 文档内容更新
## 关联的Issue
<!-- 如果这个PR是为了解决特定的Issue,请在当前页面的右侧'关联Issue'部分添加相应Issue链接,并勾选'合并后关闭已关联的 Issue'选项。 -->
## 如何测试
描述测试此变更的步骤和前提条件:
1.
2.
## 核对清单
<!-- [x] 表示选中 -->
- [ ] 我的代码遵循了项目的代码风格
- [ ] 我已对代码进行了自测
- [ ] 我已更新了相关的文档
- [ ] 我在标题中使用了合适的类型标签(如:feat:, fix:)
- [ ] 我已经详细阅读了贡献指南(CONTRIBUTING.md),并遵守了其中的所有规定,包括但不限于commit message的格式、无效commit的合并等
## 其他信息
在此添加任何其他关于本次 PR 的说明。
See merge request: cann/ge!2236 | 1 个月前 |