Merged
[feat]: ccu res alloc dynamic #1998
zhongyuAdd on Jul 15
[feat]: ccu res alloc dynamic #1998
Merged
zhongyuAdd on Jul 15
zhongyu
zhongyuCollaborators
Jul 15

描述

关联的Issue

测试

文档更新

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for zhongyu's contribution.)
atomgit-bot
atomgit-bot
Jul 15 Comments:

变更摘要

此 PR 为 CCU 资源管理引入了动态资源申请能力。在 CANN 9.1.0+ 环境下,新流程支持算子按需创建 CcuIns 并绑定到通信域,首算子根据"算子诉求与 1/5 资源量取最大"的原则申请资源,后续算子复用已有 CcuIns 并校验资源容量是否充足;资源不足或旧版 hcomm 包时自动回退到原有预分配流程。为此新增了 HcommCcuInsResDescCreate 等 8 个动态资源接口的弱符号声明与支持标记,以及对应的类型回退定义。

主要改动

  • 新增动态 CCU 资源接口层:在 ccu_res_dl.h/ccu_res_dl.cc 中声明并定义了 HcommCcuInsResDescCreate、HcommCcuInsResDescDestroy、HcommCcuInsResDescSetNum、HcommCcuInsResDescQueryNum、HcommCcuInsCreate、HcommCcuInsDestroy、HcommCcuInsQueryResDesc、HcommCcuKernelQueryResReq 共 8 个弱符号函数及对应支持标记,用于运行时检测新接口可用性;同时在 hccl_ccu_res_dl.h/hccl_ccu_res_dl.cc 中新增 HcclCommAssignCcuIns 弱符号及支持标记。

  • 新增类型回退定义文件:添加 ccu_res_defs_dl.h,在旧版 hcomm 包缺少 ccu_res_defs.h 时,提供本地 fallback 的 HcommCcuResDescHandle 类型(uint64_t)和 HcommCcuResType 枚举(涵盖 Loop、CCU Buffer、Variable、Address、Event、CCU Thread、Instruction 七种资源类型)。

  • 实现动态资源申请新流程:在 op_common.cc 中新增 HcclGetCcuKernelDynamic 函数,实现三步逻辑——调用 CalcKernelsAggregatedResReq 按 resGroup 聚合所有 kernel 资源诉求(同 group 相加、跨 group 取最大);查询通信域现有 CcuIns,若存在则调用 IsResCapSufficient 逐项比较资源容量是否满足诉求;若为首算子则通过 CalcMaxResReqWithDefault 取 max(算子诉求, 1/5 固定资源量) 后调用 HcommCcuInsCreate 创建新实例并 HcclCommAssignCcuIns 绑定。

  • 重构 HcclGetCcuKernel 入口:原函数改为根据 IsCcuDynamicResApiSupported 检测结果分流——新接口全部可用时走 HcclGetCcuKernelDynamic 动态流程,否则回退到旧有的通信域预分配 + 直接 query insHandle 模式;同时将原有 kernel 注册逻辑抽取为 RegisterCcuKernels 供新旧流程复用,并移除了 CCU_E_UNAVAIL 的分散处理,统一由上层判断回退。

likedislike
Incorrect?
atomgit-bot
atomgit-bot
Jul 15 Comments:

代码审查

Based on my thorough review of all 6 changed files, I find the diff to be well-implemented. The dynamic CCU resource allocation logic is correct, resource cleanup is comprehensive on all code paths, and the fallback behavior (HCCL_E_UNAVAIL) is properly preserved throughout. The RegisterCcuKernels function correctly reuses the extracted kernel registration logic, and the CCU_E_UNAVAIL → HCCL_E_UNAVAIL conversion via ConvertCcuToHccl ensures the old fallback contract is maintained. No correctness, security, reliability, or breaking-change issues were identified.


Closing Summary

Priority Count
P0 0
P1 0
P2 0
P3 0

Per-file review confirmation:

  • src/common/hcomm_dlsym/ccu/ccu_res_defs_dl.h — reviewed, no issues
  • src/common/hcomm_dlsym/ccu_res_dl.cc — reviewed, no issues
  • src/common/hcomm_dlsym/ccu_res_dl.h — reviewed, no issues
  • src/common/hcomm_dlsym/hccl_ccu_res_dl.cc — reviewed, no issues
  • src/common/hcomm_dlsym/hccl_ccu_res_dl.h — reviewed, no issues
  • src/ops/op_common/op_common.cc — reviewed, no issues

Overall risk judgment: 低风险。变更结构清晰,资源管理完整,回退路径正确保留,新增的动态资源申请流程与旧流程隔离良好。

⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。

likedislike
Incorrect?
zhongyuzhongyuCollaborators
Jul 15 Modify description of pull request
CANN-robotCANN-robotCollaborators
Jul 15 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Jul 15 Comments:

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


PR Approval Progress

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

Module Approval Details

module lgtm status approve status
src ✅ chengym, chenyia (2/2) ✅ chengym (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
113 messages are collapsed here。 See more
atomgit-bot
atomgit-bot
Jul 30 Comments:

代码审查

审查总结

逐文件确认

文件 审查结果
src/common/hcomm_dlsym/ccu/ccu_res_defs_dl.h ✅ 无问题
src/common/hcomm_dlsym/ccu_res_dl.cc ✅ 无问题
src/common/hcomm_dlsym/ccu_res_dl.h ✅ 无问题
src/common/hcomm_dlsym/hccl_ccu_res_dl.cc ✅ 无问题
src/common/hcomm_dlsym/hccl_ccu_res_dl.h ✅ 无问题
src/ops/op_common/inc/alg_param.h ✅ 无问题
src/ops/op_common/op_common.cc ⚠️ 1 个 P3 问题
src/ops/op_common/op_common.h ✅ 无问题

按优先级统计

  • P0: 0
  • P1: 0
  • P2: 0
  • P3: 1

上一轮审查问题回查

上一轮的三个资源泄漏问题均已修复:

  1. BuildAggregatedResReq 中 HcommCcuInsResDescCreate 失败时已通过 DestroyAllDescs(reqDescs) 清理 ✅
  2. 同上(重复问题)✅
  3. HcclGetCcuKernelDynamic 中 BuildAggregatedResReq 失败时已通过 DestroyAllDescs(reqDescs) 防御性清理 ✅

整体风险评估

低风险。本次改动整体质量较高:新增的 CCU 动态资源申请流程设计清晰,资源生命周期管理(DestroyAllDescs、RAII 风格的句柄销毁)严谨;头文件类型定义与 dlsym 弱符号声明一致;上一轮审查的资源泄漏问题全部修复。唯一发现的问题是 RegisterCcuKernels 共享函数中对 CCU_E_UNAVAIL 的日志级别从 WARNING 变为 ERROR —— 返回值语义不变、回退行为不变,仅影响旧路径的可观测性,属于低优先级的回归。

⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。

likedislike
Incorrect?
chenyia
chenyiaCollaborators
Jul 31 Comments:

/lgtm

likedislike
ChengYM
ChengYM
Aug 1 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Aug 1 Added label: lgtmapproved
CANN-robotCANN-robotCollaborators
Aug 1 Merged pull request