已合并
refactor: decouple Runtime from ApiImplMbuf #4265
refactor: decouple Runtime from ApiImplMbuf #4265
已合并
zhangpengpeng8创建于 23 天前
zhangpengpeng8成员
23 天前

Pull Request

描述

在最新 master 基线上,结合 PR4254 已验证的实现方式,解除 Runtime 生命周期对具体 ApiImplMbuf 类型的直接依赖:

  • api_impl_creator.hpp 仅前置声明 ApiMbuf,不再包含 api_mbuf.hpp,并提供统一的创建/销毁接口声明。
  • CreateImplMbufAndGet()DestroyImplMbuf()、能力探针及 ApiImplMbuf 分配日志收敛到 src/runtime/api/impl/api_impl_mbuf.cc
  • runtime.cc 通过工厂创建和销毁 Mbuf 实现,不再包含 api_impl_mbuf.hpp,也不再使用 sizeof(ApiImplMbuf)
  • v100/v200 的 runtime_adapt.cc 均通过 DestroyImplMbuf() 完成销毁,不再依赖具体 Mbuf 实现头文件。
  • IsImplMbufSupported() 当前仍返回 true,所有平台继续编译并创建完整 Mbuf 实现,本 PR 不改变现有功能和路由行为。
  • ApiMbuf::Instance() 继续保留在 API 侧 api.cc,不改变单例符号归属。
  • 补充创建成功、分配失败和初始化失败传播 UT,覆盖新增生命周期路径。
  • 删除无生产调用的 NpuDriver::GetIpcNotifyPeerPhyDevId 声明和实现,同时删除仅直接验证该冗余入口的 910B UT。

本 PR 是 arch5162 隔离 Mbuf 组件的第 2 步:只建立 Runtime 与可选 Mbuf 实现之间的工厂边界,不在本步骤关闭任何平台能力。该变更不依赖 Mbuf driver 源文件拆分,可以独立合入和独立回退。

变更类型

关联的Issue

无。

如何测试

当前补丁集:7b7b869c3e13977f6eb1b2e74f3e061f38055956,已合入 master@e17790bf85dc2d2275784975c9cd2bbaf60702b3

  1. 普通构建:runtimeruntime_v200runtime_utestruntime_utest_api_910Bruntime_utest_task_910Bruntime_utest_xpu_910B 编译通过。
  2. arch5162 构建:runtimeruntime_utest_arch5162 编译通过;该 target 仍编译 Mbuf API、实现和 driver,符合本步骤边界。
  3. RuntimeTest.*:74/74 通过。
  4. 910B CloudV2IpcApiTest.*:删除冗余入口 UT 后,剩余 22/22 通过。
  5. arch5162 全量 UT:104/104 通过。
  6. 普通 libruntime.solibruntime_v200.so 和 arch5162 libruntime.so 执行 ldd -r,无未解析符号。
  7. 构建依赖确认 runtime.cc、v100/v200 runtime_adapt.cc 均不再依赖 api_impl_mbuf.hpp
  8. 当前 PR 差异执行 clang-format 与 OAT pre-commit 检查,均通过。
  9. 最终补丁集线上编译/UT 流水线 66e0f329f3ad4a5dbbe9b2b37fd74d58:27/27 成功,其中 UT_Test_rts_commonUT_Test_camodel_checkUT_Test_rts_report 均通过。
  10. 最终补丁集线上静态检查流水线 2a217099f0cb4caba9a77e047e690ca6:11/11 成功。

核对清单

其他信息

  • 基线刷新:已合入 master@e17790bf8,当前 PR 无冲突。
  • 合入顺序:建议在步骤 1(PR4264,已合入)之后合入;代码上不依赖 PR4264。
  • 回退方式:单独回退本 PR,即可恢复 Runtime 直接管理 ApiImplMbuf 生命周期的原逻辑,不影响 driver 文件拆分。
  • 后续步骤:arch5162 专属实现将把能力探针改为 false,并从其 target 中移除 Mbuf API、实现和 driver 源文件。
likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 zhangpengpeng8 的贡献)
Zzhangpengpeng8成员
23 天前 创建了 pull request,commit 658ae160
atomgit-bot
atomgit-bot
23 天前 评论:

变更摘要

本 PR 旨在解除 Runtime::InitApiImplies() 对具体 ApiImplMbuf 类型的直接依赖,将 Mbuf 实现的创建逻辑下沉到 api_impl_mbuf.cc。通过新增 IsImplMbufSupported() 能力探针(当前所有平台均返回 true),runtime.cc 仅依据该探针决定是否创建 Mbuf 实现,不再包含 api_impl_mbuf.hpp,也不再直接使用 sizeof(ApiImplMbuf);Mbuf 的分配、失败日志和大小日志统一移至 api_impl_mbuf.cc 中的 CreateImplMbufAndGet() 内,为后续 arch5162 隔离 Mbuf 组件保留扩展点。

主要改动

  • 新增能力探针 IsImplMbufSupported(): 在 api_impl_creator.hpp 中声明、在 api_impl_mbuf.cc 中定义为始终返回 true,当前不改变任何平台的 Mbuf 能力。
  • 移动 CreateImplMbufAndGet() 实现: 将其从 api_impl_creator.cc 移到 api_impl_mbuf.cc,并在该函数内完成 ApiImplMbuf 分配、nullptr 失败日志(EE1013)以及 Runtime_alloc_size 大小日志。
  • runtime.cc 不再直接依赖 ApiImplMbuf: 移除 api_impl_mbuf.hpp 头文件引用,改用 IsImplMbufSupported() 条件包裹 CreateImplMbufAndGet() 调用,失败时仅返回 RT_ERROR_API_NEW,原失败/大小日志逻辑交由 api_impl_mbuf.cc 处理。
  • api_impl_creator.cc 精简依赖: 删除 api_impl_mbuf.hpp 头文件及 Mbuf 创建函数,api_impl_creator 不再感知具体 Mbuf 实现类型。
  • 收尾规范化: api_impl_mbuf.cc 末尾补充换行,并新增 api_impl_creator.hpp 头文件以声明工厂接口。
likedislike
不准确?
atomgit-bot
atomgit-bot
23 天前 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
CANN-robotCANN-robot成员
23 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
23 天前 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
src/runtime Henry_ascend, YzQnWyx (2/2) Henry_ascend (1/1)
tests/ut/runtime Henry_ascend, YzQnWyx (2/2) Henry_ascend (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

zhangpengpeng8, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
此处折叠了157条消息 查看更多
Zzhangpengpeng8成员
17 天前 修改了pull request 的描述
YzQnWyx
YzQnWyx成员
17 天前 评论:

/lgtm

likedislike
Henry_ascend成员
17 天前 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
17 天前 添加了label:lgtmapproved
CANN-robotCANN-robot成员
17 天前 合入了pull request