已合并
[feat]ccu resource management compatibility new impl #4420
[feat]ccu resource management compatibility new impl #4420
已合并
guoziqi创建于 24 天前
guoziqi
guoziqi成员
24 天前

描述

本 PR 实现 CCU 资源按需申请的兼容性方案,去除 hcomm 侧对 hccl 包版本的检查,改为通过运行时标记位区分新旧 CCU 实例创建路径,并新增对外接口 HcclCommQueryAssignedCcuIns,使新旧版本的其它包能各自调用对应的查询接口。

改动原因:原方案中 MyRank::TryInitCcuInstance()CcuKernelMgr::BuildKernel 两处通过查询 hccl 包版本号走不同分支,版本耦合侵入多、维护成本高。现改为:去掉版本检查,由 CCU 实例自身的创建方式标记位在运行时决定分支,并通过两个语义清晰的对外查询接口分别服务新旧调用方。

所采取的方法

  1. 新增对外接口 HcclCommQueryAssignedCcuIns(与 HcclCommQueryCcuIns 放在一起,include/hccl/hccl_ccu_res.h),查询通过新方式(HcommCcuInsCreate + HcclCommAssignCcuIns)绑定的 CCU 实例句柄;未绑定时返回 HCCL_E_UNAVAIL,不按需创建。
  2. HcclCommQueryCcuIns 语义改为查询"通信域自有的 ccuInsHandle"(旧方式):为 0 时按 GetOpExpansionMode()HcommCcuInsCreateByInsType 按需创建并回写后返回;非 0 直接返回。
  3. HcommCcuInsCreateLegacy 改名为 HcommCcuInsCreateByInsType(保留内部 pub_inc 头)。
  4. MyRank 新增 assignedCcuInsHandle_ 成员存放新方式绑定句柄;HcclCommAssignCcuIns 改为写该成员(不再写 ccuInsHandle_);ccuInsHandle_ 语义变为通信域自有句柄。MyRank init 不再创建 ccu instance,TryInitCcuInstance 简化为只走 TryInitCcuInstanceOnDemand 分支。
  5. CcuInstance 新增 bool isCreateByInsType_{false} + IsCreateByInsType()InitByInsType 置 true,InitByResDescs/InitByAllRes 保持 false。
  6. CcuKernelMgr::BuildKernel/Register 签名末参加 bool isCreateByInsType,据标记位分支:true→ApplyDieFromChannels(),false→ValidateAndApplyDie(dieId)
  7. 完全删除两处 hccl 版本检查代码(MyRank::InitGetHcclVersion/useCcuResStaticAlloc_/常量;CcuKernelMgr::BuildKernelGetHcclVersionForCcuKernelMgr/版本比较/常量)。

变更类型

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

关联的Issue

NA

测试

补充的UT用例:

  • HcclCommQueryCcuIns 新语义(已存在直返不创建 / 为 0 按需创建+回写 / mode 未使能返回 UNAVAIL / 创建失败透传 / 非 v2 / 空指针 / 幂等)
  • HcclCommQueryAssignedCcuIns(已绑定返回 / 未绑定 UNAVAIL 不创建 / 非 v2 / 空指针)
  • HcclCommAssignCcuIns 新语义(写 assignedCcuInsHandle_ 且 ccuInsHandle_ 不变 / 未 Assign 直接 QueryAssigned)
  • CcuInstance::IsCreateByInsType(InitByInsType=true / InitByResDescs=false / ByInsType 空指针 / 非法 insType / 多 insType 覆盖)
  • CcuKernelMgr::BuildKernel 分支(true→ApplyDieFromChannels / false→ValidateAndApplyDie)

文档更新

  • 修改 docs/zh/.../comms_domain_resource_mgmt/HcclCommQueryCcuIns.md:功能说明改为"查询通信域自有的 CCU 实例(为 0 时按需创建)",更新返回值/约束,补充与 HcclCommQueryAssignedCcuIns 的关系。
  • 新增 docs/zh/.../comms_domain_resource_mgmt/HcclCommQueryAssignedCcuIns.md:新接口完整 API 参考(产品支持/功能/原型/参数/返回值/约束/调用示例)。
  • 修改 HcclCommAssignCcuIns.md:绑定后查询指向改为 HcclCommQueryAssignedCcuIns,并发约束补充新接口,调用示例同步。
  • 修改 comms_domain_resource_mgmt/README.md:索引新增 HcclCommQueryAssignedCcuIns
  • 修改 ccu_kernel_launch_execution/README.md:绑定流程中查询已绑定实例改用 HcclCommQueryAssignedCcuIns,补充 HcclCommQueryCcuIns 用于查询通信域自有实例的说明。

合入检查

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 guoziqi 的贡献)
guoziqiguoziqi成员
24 天前 创建了 pull request,commit 13dcdd96
atomgit-bot
atomgit-bot
24 天前 评论:

变更摘要

此 PR 主要对 HCCL 通信域的 CCU 资源管理进行了兼容性重构,核心目标是实现新旧两种 CCU 实例绑定方式的共存与隔离。通过新增 assignedCcuInsHandle_ 成员和 isCreateByInsType_ 标记位,将"旧方式(按实例类型创建,由 QueryCcuIns 按需创建)"与"新方式(通过 HcommCcuInsCreate + HcclCommAssignCcuIns 显式绑定)"的句柄存储和 die 应用策略完全分离,同时删除了基于 HCCL 版本号的静态分支判断,简化了初始化流程。

主要改动

  • 新增 HcclCommQueryAssignedCcuIns 公共接口:在 include/hccl/hccl_ccu_res.h 中声明并通过 coll_comm_ccu_c_adpt.cc 实现,仅查询 assignedCcuInsHandle_ 且未绑定时返回 HCCL_E_UNAVAIL 而不创建实例,同时将 HcommCcuInsCreateLegacy 重命名为 HcommCcuInsCreateByInsType 以明确语义。

  • 新增 isCreateByInsType_ 标记位替代版本号分支:在 CcuInstance 类中新增 isCreateByInsType_ 成员,InitByInsType 路径置 trueInitByResDescs 路径保持 falseCcuKernelMgr::BuildKernel 据此选择 ApplyDieFromChannels(旧方式)或 ValidateAndApplyDie(新方式),同时删除了 GetHcclVersionForCcuKernelMgr 函数及 MAX_HCCL_VERSION_USING_CCU_RES_STATIC_ALLOC 常量。

  • MyRank 中新增 assignedCcuInsHandle_ 实现新旧绑定隔离HcclCommAssignCcuIns 写入 assignedCcuInsHandle_ 而不再改写 ccuInsHandle_GetAssignedCcuInstance/SetAssignedCcuInstance 提供独立访问;析构时分别销毁两种句柄,并相应调整 ResourceCleanupGuard 的清理逻辑。

  • 简化 TryInitCcuInstance 流程并删除 TryInitCcuInstanceLegacy:移除 useCcuResStaticAlloc_ 成员和 GetHcclVersion 版本判断,TryInitCcuInstance 不再在 init 时创建实例,仅拉起 CCU 驱动;HcclCommQueryCcuIns 改为当 ccuInsHandle_ 为 0 时按 opExpansionMode 调用 HcommCcuInsCreateByInsType 按需创建并回写,替代原先直接返回 HCCL_E_UNAVAIL 的行为。

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

代码审查

All 16 files have been reviewed. Here is the closing summary:


审查总结

按优先级统计

优先级 数量
P0 0
P1 0
P2 0
P3 1

各文件审查结论

文件 结论
include/hccl/hccl_ccu_res.h 无问题 — 新增 API 声明与文档完善,注释清晰
src/base_comm/primitives/api_c_adpt/ccu/ccu_launch.cc 无问题 — 透传 IsCreateByInsType() 标记位,ccuIns 已在上游校验非空
src/base_comm/primitives/api_c_adpt/ccu/ccu_res_c_adpt.cc 无问题 — 函数重命名 HcommCcuInsCreateLegacyHcommCcuInsCreateByInsType,无残留引用
src/base_comm/resources/ccu/ccu_instance/ccu_instance.cc 无问题 — InitByInsType 正确置 isCreateByInsType_=true,非重入路径
src/base_comm/resources/ccu/ccu_instance/ccu_instance.h 无问题 — 新增访问器与成员变量,默认值正确
src/base_comm/resources/ccu/ccu_kernel/ccu_kernel_mgr.cc 无问题 — 版本检查替换为标记位分支,acl/acl.h 移除后无残留 ACL 调用;GetKernelResourceRequestfalse 符合独立查询语义
src/base_comm/resources/ccu/ccu_kernel/ccu_kernel_mgr.h 无问题 — 签名变更一致
src/base_comm/resources/ccu/pub_inc/ccu_device_res.h 无问题 — 函数声明重命名,无残留引用
src/coll_communicator_mgr/api_c_adpt/coll_comm_ccu_c_adpt.cc P3OpExpansionModeToCcuInstanceTypemy_rank.cc 重复定义,存在维护性分歧风险
src/coll_communicator_mgr/resource_mgr/local/my_rank/my_rank.cc 无问题 — 析构函数正确分离 ccuInsHandle_/assignedCcuInsHandle_ 销毁路径;ResourceCleanupGuard 移除 useCcuResStaticAlloc_ 条件后正确补全了驱动反初始化;TryInitCcuInstance 简化合理
src/coll_communicator_mgr/resource_mgr/local/my_rank/my_rank.h 无问题 — 新增成员变量与访问器,删除废弃成员
test/ut/framework/next/coll_comms/api_c_adpt/ut_coll_comm_ccu_c_adpt.cc 无问题 — 测试覆盖充分,新增 QueryCcuIns/QueryAssignedCcuIns/IsCreateByInsType 用例
test/ut/framework/next/coll_comms/rank/ut_ccu_ms_per_device_exclusive.cc 无问题 — 测试适配阶段2变更,mock 从 HcommCcuInsCreateLegacy 迁移到 CcuInitFeature
test/ut/framework/next/coll_comms/rank/ut_my_rank.cc 无问题 — 测试适配阶段2变更,删除已废弃的递归 fallback 用例
test/ut/framework/next/comms/ccu/ut_HcommCcuControlApi_test.cc 无问题 — 移除版本检查 mock,新增 IsCreateByInsType/BuildKernel 分支测试
test/ut/framework/next/comms/ccu/ut_HcommCcuKernelQueryResReq_test.cc 无问题 — 移除版本检查 mock 与常量

整体风险评估:低风险

本次变更的核心逻辑是:

  1. 将 CCU 实例的 die 应用策略从"基于 HCCL 版本号判断"改为"基于实例创建方式标记位(isCreateByInsType_)判断",语义更精确;
  2. HcclCommAssignCcuIns 的绑定目标从 ccuInsHandle_ 迁移到独立的 assignedCcuInsHandle_,实现新旧两条 CCU 实例路径的完全分离;
  3. 删除已废弃的 useCcuResStaticAlloc_ 分支和 TryInitCcuInstanceLegacy 函数,简化初始化流程。

变更逻辑自洽,所有被删除的符号(HcommCcuInsCreateLegacyGetHcclVersionGetHcclVersionForCcuKernelMgrTryInitCcuInstanceLegacyuseCcuResStaticAlloc_MAX_HCCL_VERSION_USING_CCU_RES_STATIC_ALLOC)均无残留引用;测试覆盖充分且适配到位。唯一可改进点为一处代码重复(P3 维护性建议),不影响运行时正确性。

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

💬 仅评论

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

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.
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
docs 颜业峰, flyswa, laodazhao1 (3/2) 颜业峰, flyswa (2/1)
include laodazhao1, 颜业峰 (2/2) 颜业峰 (1/1)
src/base_comm 颜业峰, temper7620, laodazhao1 (3/2) temper7620, 颜业峰 (2/1)
src/coll_communicator_mgr 颜业峰, dingweiqin_57, laodazhao1 (3/2) 颜业峰, dingweiqin_57 (2/1)
test temper7620, 颜业峰, dingweiqin_57, laodazhao1 (4/2) temper7620, 颜业峰, dingweiqin_57 (3/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
此处折叠了458条消息 查看更多
temper7620成员
8 天前 评论:

/approve

likedislike
zangyan成员
8 天前 评论:

/approve

likedislike
philo
philo成员
8 天前 评论:

/approve

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