已合并
[refactor]device aicpu #4242
lizhuolong创建于 26 天前
[refactor]device aicpu #4242
已合并
lizhuolong创建于 26 天前
lizhuolong
lizhuolong
26 天前

描述

本次提交对 AICPU 侧通信域(IndependentOp)资源管理进行模块化重构,将原先集中在 AicpuIndopProcess 单文件中的资源管理逻辑拆分为独立的 resorce_mgr 子模块,通信域方法归一,通信域管理、通信域对标host分层,并整理 c_adpt C 适配层封装 kernel 接口。

  1. 职责分离:原先 AicpuIndopProcess(~325 行)和 CollCommAicpu(~360 行)承担了通信域线程、Notify、Channel、EngineRes 等多类资源的管理,职责边界模糊,难以独立测试和维护。
  2. 资源管理模块化:将本地资源(comm_engine_res、notify、thread)和远端资源(channel)分别封装为独立 Manager 类,每类 Manager 聚焦单一资源类型的生命周期。
  3. 消除 per-group 代理层:当前 CollCommAicpuMgr 是每个 group 一个的薄代理(unique_ptr<CollCommAicpu> + isUsed_ + 纯委托),重构后直接变成进程级单例 Manager。isUsed_ 等元数据作为 map entry 的一部分。
  4. kernel 接口适配:新增 c_adpt 目录,将 kernel 入口函数与 Manager 实现解耦,使 C 侧 kernel launch 路径更清晰。
  5. 通信域粒度方法上提到 MgrInitBackGroundThreadInitIndopEnvRegisterProfCallBack 等用 call_once 包裹但寄生在 CollCommAicpu 中的全局逻辑,上提到 Mgr。
  6. 旧路径处置:通信域初始化的kernel接口下,950/960 走新架构,其他设备走 legacy AicpuHcclProcess,移除 SetOldA5CommToCommMgr过渡方法,并且legacy AicpuHcclProcess中通信域管理委托至CollCommAicpuMgr。

变更类型

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

关联的Issue

测试

已完成的测试用例和场景:

  1. 基本UT测试;
  2. 950/910场景端到端单算子用例;
  3. hixl的benchmark用例;
  4. mc2的api和算子用例。

新增 UT(4 个文件,覆盖新增的 4 个 Manager)

测试文件 覆盖对象 验证要点
ut_comm_engine_res_aicpu_mgr.cc(+89 行) CommEngineResAicpuMgr 通信引擎资源的创建、获取、释放;空指针防护;重复创建幂等性
ut_notify_aicpu_mgr.cc(+56 行) NotifyAicpuMgr Notify 对象的分配/释放、数量上限校验、多线程并发安全
ut_thread_aicpu_mgr.cc(+64 行) ThreadAicpuMgr 线程池创建、thdUniqueId 唯一性、注册 DFX、线程清理
ut_channel_aicpu_mgr.cc(+70 行) ChannelAicpuMgr Channel 注册/查找(tag+engine+remoteRank+protocol 四元组 key)、参数校验(notifyNum≤64、协议白名单、engine 类型限制)

修改已有 UT(6 个文件,适配重构)

测试文件 改动 适配内容
ut_aicpu_indop_process_test.cc ±49 行 拆分后 AicpuIndopProcess 接口变化,更新 mock 和断言
ut_coll_comm_aicpu.cc +56 行 CollCommAicpu 委托 Manager 后的新调用路径测试
ut_coll_comm_aicpu_destroy_func.cc ±30 行 销毁流程改用 Manager 清理后的正确性验证
ut_hcclCommTaskExceptionLite.cc ±29 行 异常检测适配新的通信域引用路径
ut_ns_recovery_func_lite.cc ±7 行 N 秒快恢复适配新框架
ut_engine_aicpu_interface.cc ±21 行 kernel 入口适配 c_adpt 新接口

文档更新

合入检查

    • [x ] 🏷️ 标题中使用了合适的类型标签(如:[feat], [fix]
    • [x ] 📄 代码修改内容已简要描述,相关文档已更新
likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 lizhuolong 的贡献)
lizhuolonglizhuolong
26 天前 创建了 pull request,commit 53fb6f93
atomgit-bot
atomgit-bot
26 天前 评论:

变更摘要

本次 PR 对 aicpu device 侧通信域管理代码进行了结构性重构,核心变更是:移除中间层静态方法类 AicpuIndopProcess,将 CollCommAicpuMgr 从"每通信域一实例"的辅助类改造为管理全局通信域注册表单例,并从 CollCommAicpu 中抽取线程、notify、channel 等资源管理职责到独立的 CommEngineResAicpuMgrThreadAicpuMgrNotifyAicpuMgrChannelAicpuMgr 子模块中。同时新增 kernel 适配层 coll_comm_aicpu_kernel_adpt,统一对外接口的 Acquire→Operate→Release 模式。

主要改动

  • 删除 AicpuIndopProcess 静态方法类:原 aicpu_indop_process.cc/.h 中的所有通信域管理、线程/通道/notify 初始化、DFX 上报等静态方法被移除,其职责按功能拆散迁移至 CollCommAicpuMgr 单例或新的 kernel 适配层。

  • CollCommAicpuMgr 重构为全局单例:新增 GetInstance() 静态方法,内部维护 std::unordered_map<std::string, CommEntry> commMap_ 全局通信域注册表(替代原来分散在匿名命名空间的 g_commAicpuInfo 全局变量)。原 AicpuIndopProcessAcquireAicpuCommMgr/AicpuGetCommMgrbyGroup/AicpuReleaseCommMgrbyGroup/AicpuDestroyCommbyGroup 等操作均迁移至此;thread_local 当前通信域指针从 CollCommAicpuMgr* g_hcclComm 改为 CollCommAicpu* g_currentComm_

  • 新增 kernel 适配层 coll_comm_aicpu_kernel_adpt:提供 CollCommAicpuKernelAdptInitThreadsCollCommAicpuKernelAdptInitChannelCollCommAicpuKernelAdptUpdateChannelCollCommAicpuKernelAdptInitNotify 四个自由函数,内部统一通过 CollCommAicpuMgr::GetInstance().AcquireCommForUse() 获取通信域、操作后调用 ReleaseComm() 释放,替代原来直接调用 AicpuIndopProcess 静态方法的方式。

  • CollCommAicpu 精简并引入资源管理器:删除了原 CollCommAicpu 内的 InitThreadsAllocChannelResourceNotifyAlloc/NotifyFreeInitIndopEnvInitBackGroundThread 等方法以及 threads_notifys_ubTransportMap_ 等成员;新增 CommEngineResAicpuMgr(组合 ThreadAicpuMgrNotifyAicpuMgr)和 ChannelAicpuMgr 两个成员指针,通过 GetCommEngineResMgr()GetChannelMgr() 对外暴露。

  • DFX 和 profiling 函数迁移至 CollCommAicpuMgr:原 AicpuIndopProcess 中的 AicpuDfxOpInfoInitProfilingReportDeviceOpUpdateTask 转为 CollCommAicpuMgr 的成员方法 InitDfxOpInfoProfilingReportDeviceOpUpdateTask,并通过 g_currentComm_ 访问当前线程通信域;RunAicpuDfxOpInfoInitV2 kernel 入口从 aicpu_ts_urma_dfx_kernel.cc 移至 independent_op_aicpu_interface.cc

likedislike
atomgit-bot
atomgit-bot
26 天前 评论:

代码审查

审查总结

共发现 7 个问题,按优先级分布:

  • P1: 1 个 — ChannelAicpuMgr::ResumePackData 中使用 static_cast 做不安全向下转型
  • P2: 1 个 — coll_comm_aicpu_kernel_adpt.cc 四个函数中 Acquire 后提前返回未 Release
  • P3: 5 个 — 重复 include ×2、死代码字段 ×2、声明无定义 ×1

整体风险评估:中低风险。 重构的主体结构(将 AicpuIndopProcess 静态方法类迁移为 CollCommAicpuMgr 单例,将通信引擎资源拆分为 ThreadAicpuMgr / NotifyAicpuMgr / ChannelAicpuMgr)设计合理,等价性保持良好。P1 的 static_cast 问题是唯一可能在运行时导致崩溃的高风险项,但触发条件需要 resume 路径走到非 UB transport,实际概率较低。P3 项均为清理遗留,不影响功能。

逐文件审查确认

文件 结论
src/base_comm/primitives/api_c_adpt/aicpu_ts_primitives_c_adpt.cc 重复 include(已报告)
src/base_comm/resources/comm_engine_res/threads/device/aicpu_thread_kernel.cc 无问题
src/base_comm/resources/endpoint_pairs/channels/aicpu/device/aicpu_ts_urma_channel_kernel.cc 无问题
src/coll_communicator_mgr/api_c_adpt/dev/dev_coll_comm_c_adpt.cc 重复 include(已报告)
src/coll_communicator_mgr/communicator/device/CMakeLists.txt 无问题
src/coll_communicator_mgr/communicator/device/c_adpt/CMakeLists.txt 无问题
src/coll_communicator_mgr/communicator/device/c_adpt/coll_comm_aicpu_kernel_adpt.cc ReleaseComm 泄漏(已报告)
src/coll_communicator_mgr/communicator/device/c_adpt/coll_comm_aicpu_kernel_adpt.h 无问题
src/coll_communicator_mgr/communicator/device/c_adpt/independent_op_aicpu_interface.cc 无问题
src/coll_communicator_mgr/communicator/device/c_adpt/independent_op_aicpu_interface.h 无问题
src/coll_communicator_mgr/communicator/device/coll_comm_aicpu.cc 无问题
src/coll_communicator_mgr/communicator/device/coll_comm_aicpu.h 无问题
src/coll_communicator_mgr/communicator/device/coll_comm_aicpu_destroy_func.cc 无问题
src/coll_communicator_mgr/communicator/device/coll_comm_aicpu_mgr.cc 无问题
src/coll_communicator_mgr/communicator/device/coll_comm_aicpu_mgr.h 死代码 oldA5Comm + 声明无定义(均已报告)
src/coll_communicator_mgr/communicator/device/resorce_mgr/CMakeLists.txt 无问题
src/coll_communicator_mgr/communicator/device/resorce_mgr/local/my_rank/comm_engine_reses/CMakeLists.txt 无问题
src/coll_communicator_mgr/communicator/device/resorce_mgr/local/my_rank/comm_engine_reses/comm_engine_res_aicpu_mgr.cc 无问题
src/coll_communicator_mgr/communicator/device/resorce_mgr/local/my_rank/comm_engine_reses/comm_engine_res_aicpu_mgr.h 无问题
src/coll_communicator_mgr/communicator/device/resorce_mgr/local/my_rank/comm_engine_reses/notify/CMakeLists.txt 无问题
src/coll_communicator_mgr/communicator/device/resorce_mgr/local/my_rank/comm_engine_reses/notify/notify_aicpu_mgr.cc 死代码 NOTIFY_SIZE_EIGHT(已报告)
src/coll_communicator_mgr/communicator/device/resorce_mgr/local/my_rank/comm_engine_reses/notify/notify_aicpu_mgr.h 无问题
src/coll_communicator_mgr/communicator/device/resorce_mgr/local/my_rank/comm_engine_reses/threads/CMakeLists.txt 无问题
src/coll_communicator_mgr/communicator/device/resorce_mgr/local/my_rank/comm_engine_reses/threads/thread_aicpu_mgr.cc 无问题
src/coll_communicator_mgr/communicator/device/resorce_mgr/local/my_rank/comm_engine_reses/threads/thread_aicpu_mgr.h 无问题
src/coll_communicator_mgr/communicator/device/resorce_mgr/remote/CMakeLists.txt 无问题
src/coll_communicator_mgr/communicator/device/resorce_mgr/remote/channel_aicpu_mgr.cc static_cast 不安全(已报告)
src/coll_communicator_mgr/communicator/device/resorce_mgr/remote/channel_aicpu_mgr.h 无问题
src/coll_communicator_mgr/dfx/ns_recovery/aicpu/ns_recovery_func_lite.cc 无问题
src/coll_communicator_mgr/dfx/profiling/aicpu/CMakeLists.txt 无问题
src/coll_communicator_mgr/dfx/taskException/aicpu/hcclCommTaskExceptionLite.cc 无问题
src/coll_communicator_mgr/dfx/taskException/aicpu/hcclCommTaskExceptionLite.h 无问题
src/legacy/ascend950/framework/communicator/aicpu/kernel_entrance.cc 无问题
类型 数量
🔴 阻塞 4
🟡 建议 4

⛔ 需要修改

likedislike
CANN-robotCANN-robot成员
26 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
26 天前 评论:

CLA Signature Pass

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

likedislike
此处折叠了462条消息 查看更多
ZhanPhil成员
11 天前 评论:

/approve

likedislike
57_Viking
57_Viking成员
11 天前 评论:

/approve

likedislike
temper7620成员
11 天前 评论:

/approve

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