已合并
feat: OM2 so C 接口整改 #4559
fary86创建于 4 天前
feat: OM2 so C 接口整改 #4559
已合并
fary86创建于 4 天前
fary86
4 天前

Pull Request

描述

本 PR(feat: remove Om2Tensor)将 OM2 模型的对外加载/运行接口从旧的 Om2ModelCreate/Om2ModelLoad/Om2ModelRun/Om2ModelRunAsync/Om2ModelDestroy 一套分离式 API,重构为统一使用 Config/Output 结构体的 GertModelLoad/GertModelRun/GertModelRunAsync/GertModelUnload 新接口,模型句柄类型 om2::Om2ModelHandle 相应更名为 GertModelHandle;codegen 代码生成、Om2ModelExecutor 执行器及对应单元/集成测试的 mock 接口均同步适配。

主要改动

  • 接口重构为统一 Config/Output 结构体: 新增 GertModelLoadConfigGertModelRunConfigGertModelUnloadConfigGertModelLoadOutputGertModelRunOutputGertModelUnloadOutput 六个结构体,首字段均为 struct_size 版本号,将原 Om2ModelCreate 的众多分散参数合并到 GertModelLoadConfig 中;GertModelLoad 将原 Create+Load 两步合并,GertModelUnload 取代 Om2ModelDestroy
  • 句柄类型重命名: om2::Om2ModelHandle 全局替换为 GertModelHandle(仍为 void * 类型别名),同时移除 interface_file_code_generator 中的 BuildOm2ModelHandleAliasBuildOm2ProfInfosStruct 等构造函数及 program_generator.cc 中对应生成逻辑。
  • Om2ProfInfos 结构调整: model_dump_c_api.h 中将 version/count 字段由 uint32_t 改为 uint64_t struct_size/uint64_t count,并补充默认初始化值。
  • Om2ModelExecutor 适配新接口: runtime/om2/om2_model_executor.ccResolveSymbols 改为按新符号名 GertModelLoad/GertModelRun/GertModelRunAsync/GertModelUnload 解析,加载流程用 GertModelLoadConfig 组装参数并通过 GertModelLoadOutput 回传 rt_model_handle,同步/异步运行改为传入 config/output 结构体,资源释放改用 unload_func,并移除独立的 LoadModel() 方法。
  • codegen 生成内容与测试同步更新: stable_part_provider.cc 中新增生成 GertModelLoad/GertModelRun/GertModelRunAsync/GertModelUnload 及上述结构体的代码(底层仍转发调用 Om2ModelCreate 等实现),多个 UT/ST 测试(如 test_om2.cccontrol_task_code_builder_unittest.ccom2_model_executor_unittest.cc 等)的 mock .so 源码与断言均改为新接口。

变更类型

请选择本次引入的变更类型:

关联的Issue

如何测试

描述测试此变更的步骤和前提条件:
1.
2.

核对清单

其他信息

在此添加任何其他关于本次 PR 的说明。

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 fary86 的贡献)
Ffary86
4 天前 添加了label:enhancement
Ffary86
4 天前 创建了 pull request,commit 611b7eb4
atomgit-bot
atomgit-bot
4 天前 评论:

变更摘要

本 PR(feat: remove Om2Tensor)将 OM2 模型的对外加载/运行接口从旧的 Om2ModelCreate/Om2ModelLoad/Om2ModelRun/Om2ModelRunAsync/Om2ModelDestroy 一套分离式 API,重构为统一使用 Config/Output 结构体的 GertModelLoad/GertModelRun/GertModelRunAsync/GertModelUnload 新接口,模型句柄类型 om2::Om2ModelHandle 相应更名为 GertModelHandle;codegen 代码生成、Om2ModelExecutor 执行器及对应单元/集成测试的 mock 接口均同步适配。

主要改动

  • 接口重构为统一 Config/Output 结构体: 新增 GertModelLoadConfigGertModelRunConfigGertModelUnloadConfigGertModelLoadOutputGertModelRunOutputGertModelUnloadOutput 六个结构体,首字段均为 struct_size 版本号,将原 Om2ModelCreate 的众多分散参数合并到 GertModelLoadConfig 中;GertModelLoad 将原 Create+Load 两步合并,GertModelUnload 取代 Om2ModelDestroy
  • 句柄类型重命名: om2::Om2ModelHandle 全局替换为 GertModelHandle(仍为 void * 类型别名),同时移除 interface_file_code_generator 中的 BuildOm2ModelHandleAliasBuildOm2ProfInfosStruct 等构造函数及 program_generator.cc 中对应生成逻辑。
  • Om2ProfInfos 结构调整: model_dump_c_api.h 中将 version/count 字段由 uint32_t 改为 uint64_t struct_size/uint64_t count,并补充默认初始化值。
  • Om2ModelExecutor 适配新接口: runtime/om2/om2_model_executor.ccResolveSymbols 改为按新符号名 GertModelLoad/GertModelRun/GertModelRunAsync/GertModelUnload 解析,加载流程用 GertModelLoadConfig 组装参数并通过 GertModelLoadOutput 回传 rt_model_handle,同步/异步运行改为传入 config/output 结构体,资源释放改用 unload_func,并移除独立的 LoadModel() 方法。
  • codegen 生成内容与测试同步更新: stable_part_provider.cc 中新增生成 GertModelLoad/GertModelRun/GertModelRunAsync/GertModelUnload 及上述结构体的代码(底层仍转发调用 Om2ModelCreate 等实现),多个 UT/ST 测试(如 test_om2.cccontrol_task_code_builder_unittest.ccom2_model_executor_unittest.cc 等)的 mock .so 源码与断言均改为新接口。
likedislike
atomgit-bot
atomgit-bot
4 天前 评论:

代码审查

审查总结

发现统计

  • P1:1 个
  • P2:1 个
  • P3:1 个

各变更文件审查结论

文件 结论
base/common/om2/codegen/emitter/stable_parts/stable_part_provider.cc P2 — 新公开 API 的 uint64_t 配置字段被静默窄化传入旧版 int/int32 型内部函数(GertModelRun 的 timeout、GertModelLoad 的 model_id/priority/bin_num 等)
base/common/om2/codegen/file_code_generator/interface_file_code_generator.cc no issues(仅重构声明;已核对函数声明顺序、GertModelHandle typedef 置于 extern "C" 内、无遗留 Om2ModelHandle 引用)
base/common/om2/codegen/file_code_generator/interface_file_code_generator.h no issues(仅删除两个方法声明,无遗留调用方)
base/common/om2/codegen/program_generator.cc no issues(仅删除两处 push;接口头中 struct 定义先于函数声明,顺序正确)
inc/framework/runtime/dump/model_dump_c_api.h P3Om2ProfInfos::count 改为 uint64_t 后,executor 日志 %u 格式不匹配(潜在 -Werror=format 编译风险)
runtime/om2/om2_model_executor.cc P1 — 三处 C++20 designated initializer({.field = ...})被引入到 C++17 代码库,存在编译失败风险
tests/ge/st/testcase/test_om2.cc no issues(fake .so 与新契约一致)
tests/ge/st/testcase/test_om2_online.cc no issues(fake .so 与新契约一致)
tests/ge/ut/ge/common/control_task_code_builder_unittest.cc no issues(期望串与生成器输出一致)
tests/ge/ut/ge/common/program_generator_unittest.cc no issues(期望串与生成器输出一致)
tests/ge/ut/ge/executor/om2_model_executor_unittest.cc no issues(mock 与 trace 断言已同步更新)
tests/ge/ut/ge/executor/om2_model_manager_unittest.cc no issues(fake .so 与新契约一致)
tests/ge/ut/ge/graph/execute/model_executor_unittest.cc no issues(fake .so 与新契约一致)

整体风险判断

本次变更把 OM2 的 create/load/run/destroy 四接口合并为 struct 化的 GertModel* 接口,运行时 executor、codegen 生成代码与各测试 mock 三侧的结构体布局保持一致,跨文件契约(GertModelLoadConfig/GertModelRunConfig/GertModelLoadOutput 等)核对无错位,主流程 create+load 合并与 unload 流程重构在逻辑上是自洽的。主要风险集中在两点:(1) runtime 源码引入 C++20 designated initializer,与仓库统一的 C++17 + -Wall -Werror 构建约定冲突,存在编译失败风险(P1);(2) 新 API 的 u64 参数与内部 int 型实现之间的静默窄化(P2)。两处都不影响当前 executor 内部调用路径的正确性,但属于可复现的边界/构建风险,建议在合入前修复。

类型 数量
🔴 阻塞 0
🟡 建议 1

💬 仅评论

likedislike
CANN-robotCANN-robot成员
4 天前 添加了label:cann-cla/yes
此处折叠了175条消息 查看更多
yangyongqiang
yangyongqiang成员
3 天前 评论:

/lgtm

likedislike
yangyongqiang
yangyongqiang成员
3 天前 评论:

/approve

likedislike
CANN-robotCANN-robot成员
3 天前 添加了label:lgtm
CANN-robotCANN-robot成员
3 天前 添加了label:approved
CANN-robotCANN-robot成员
3 天前 合入了pull request