Pull Request已成功合入, 合并人@CANN-robot
(感谢 lizhuolong 的贡献)变更摘要
本次 PR 对 aicpu device 侧通信域管理代码进行了结构性重构,核心变更是:移除中间层静态方法类 AicpuIndopProcess,将 CollCommAicpuMgr 从"每通信域一实例"的辅助类改造为管理全局通信域注册表单例,并从 CollCommAicpu 中抽取线程、notify、channel 等资源管理职责到独立的 CommEngineResAicpuMgr、ThreadAicpuMgr、NotifyAicpuMgr、ChannelAicpuMgr 子模块中。同时新增 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全局变量)。原AicpuIndopProcess的AcquireAicpuCommMgr/AicpuGetCommMgrbyGroup/AicpuReleaseCommMgrbyGroup/AicpuDestroyCommbyGroup等操作均迁移至此;thread_local当前通信域指针从CollCommAicpuMgr* g_hcclComm改为CollCommAicpu* g_currentComm_。 -
新增 kernel 适配层
coll_comm_aicpu_kernel_adpt:提供CollCommAicpuKernelAdptInitThreads、CollCommAicpuKernelAdptInitChannel、CollCommAicpuKernelAdptUpdateChannel、CollCommAicpuKernelAdptInitNotify四个自由函数,内部统一通过CollCommAicpuMgr::GetInstance().AcquireCommForUse()获取通信域、操作后调用ReleaseComm()释放,替代原来直接调用AicpuIndopProcess静态方法的方式。 -
CollCommAicpu精简并引入资源管理器:删除了原CollCommAicpu内的InitThreads、AllocChannelResource、NotifyAlloc/NotifyFree、InitIndopEnv、InitBackGroundThread等方法以及threads_、notifys_、ubTransportMap_等成员;新增CommEngineResAicpuMgr(组合ThreadAicpuMgr和NotifyAicpuMgr)和ChannelAicpuMgr两个成员指针,通过GetCommEngineResMgr()和GetChannelMgr()对外暴露。 -
DFX 和 profiling 函数迁移至
CollCommAicpuMgr:原AicpuIndopProcess中的AicpuDfxOpInfoInit、ProfilingReportDeviceOp、UpdateTask转为CollCommAicpuMgr的成员方法InitDfxOpInfo、ProfilingReportDeviceOp、UpdateTask,并通过g_currentComm_访问当前线程通信域;RunAicpuDfxOpInfoInitV2kernel 入口从aicpu_ts_urma_dfx_kernel.cc移至independent_op_aicpu_interface.cc。


代码审查
审查总结
共发现 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 |
⛔ 需要修改


/approve


/approve


描述
本次提交对 AICPU 侧通信域(IndependentOp)资源管理进行模块化重构,将原先集中在
AicpuIndopProcess单文件中的资源管理逻辑拆分为独立的resorce_mgr子模块,通信域方法归一,通信域管理、通信域对标host分层,并整理c_adptC 适配层封装 kernel 接口。AicpuIndopProcess(~325 行)和CollCommAicpu(~360 行)承担了通信域线程、Notify、Channel、EngineRes 等多类资源的管理,职责边界模糊,难以独立测试和维护。CollCommAicpuMgr是每个 group 一个的薄代理(unique_ptr<CollCommAicpu>+isUsed_+ 纯委托),重构后直接变成进程级单例 Manager。isUsed_等元数据作为 map entry 的一部分。c_adpt目录,将 kernel 入口函数与 Manager 实现解耦,使 C 侧 kernel launch 路径更清晰。InitBackGroundThread、InitIndopEnv、RegisterProfCallBack等用call_once包裹但寄生在CollCommAicpu中的全局逻辑,上提到 Mgr。变更类型
请选择本次引入的变更类型:
关联的Issue
测试
已完成的测试用例和场景:
新增 UT(4 个文件,覆盖新增的 4 个 Manager)
ut_comm_engine_res_aicpu_mgr.cc(+89 行)CommEngineResAicpuMgrut_notify_aicpu_mgr.cc(+56 行)NotifyAicpuMgrut_thread_aicpu_mgr.cc(+64 行)ThreadAicpuMgrut_channel_aicpu_mgr.cc(+70 行)ChannelAicpuMgr修改已有 UT(6 个文件,适配重构)
ut_aicpu_indop_process_test.ccAicpuIndopProcess接口变化,更新 mock 和断言ut_coll_comm_aicpu.ccCollCommAicpu委托 Manager 后的新调用路径测试ut_coll_comm_aicpu_destroy_func.ccut_hcclCommTaskExceptionLite.ccut_ns_recovery_func_lite.ccut_engine_aicpu_interface.cc文档更新
合入检查
[feat],[fix])