Merged
kernel编译配置compute unit支持npu arch混合编译 #14324
丛吉钰Add on 9 days ago
kernel编译配置compute unit支持npu arch混合编译 #14324
Merged
丛吉钰Add on 9 days ago
丛吉钰
丛吉钰Collaborators
9 days ago

描述

本变更聚焦于 kernel 编译配置中的芯片过滤逻辑,在 cmake/func.cmake 的 add_kernel_sources 函数中,将原先分离的 NPU_ARCH 与 COMPUTE_UNITS 两套参数体系合并为单一 COMPUTE_UNITS 参数,使其同时支持 soc 版本(如 ascend950)与 npuArch 版本(如 dav_3510)混合配置。函数内部逐项将 soc 转换为 npuArch,再统一按 arch 进行过滤匹配。

主要改动

参数接口收敛: 从 cmake_parse_arguments 的 multiValueArgs 中移除 NPU_ARCH,只保留 COMPUTE_UNITS 作为芯片过滤入口,NPU_ARCH 不再作为独立配置项。
混合编写支持: COMPUTE_UNITS 的每个条目先经 get_npu_arch_by_soc_version 尝试转换为 npuArch,转换失败时按小写原值作为 arch 候选,从而支持 soc 与 npuArch 混配。
去重与统一匹配: 转换后的 arch 列表通过 list(REMOVE_DUPLICATES) 去重,再与当前构建芯片转换得到的 _cur_arch 做 IN_LIST 匹配,未命中则提前 return()。
原有分支简化: 删除原先 MODULE_NPU_ARCH 优先、MODULE_COMPUTE_UNITS 回退的两段式判断逻辑,统一为单一路径;未配置时仍回退到 MODULE_COMPUTE_UNITS "ALL"。
注释与语义说明更新: 函数头部注释与内部注释同步改为描述「soc/npuArch 混配、逐项转 arch、同 arch 的 soc 共享过滤结果(如 ascend950 与 ascend350 同为 dav_3510)」。

关联的Issue

#8861

测试

文档更新

类型标签

AI/Agent生成声明

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for 丛吉钰's contribution.)
丛吉钰丛吉钰Collaborators
9 days ago Created pull request, commit 2eee90ee
atomgit-bot
atomgit-bot
9 days ago Comments:

变更摘要

本变更聚焦于 kernel 编译配置中的芯片过滤逻辑,在 cmake/func.cmake 的 add_kernel_sources 函数中,将原先分离的 NPU_ARCH 与 COMPUTE_UNITS 两套参数体系合并为单一 COMPUTE_UNITS 参数,使其同时支持 soc 版本(如 ascend950)与 npuArch 版本(如 dav_3510)混合配置。函数内部逐项将 soc 转换为 npuArch,再统一按 arch 进行过滤匹配。

主要改动

  • 参数接口收敛: 从 cmake_parse_arguments 的 multiValueArgs 中移除 NPU_ARCH,只保留 COMPUTE_UNITS 作为芯片过滤入口,NPU_ARCH 不再作为独立配置项。
  • 混合编写支持: COMPUTE_UNITS 的每个条目先经 get_npu_arch_by_soc_version 尝试转换为 npuArch,转换失败时按小写原值作为 arch 候选,从而支持 soc 与 npuArch 混配。
  • 去重与统一匹配: 转换后的 arch 列表通过 list(REMOVE_DUPLICATES) 去重,再与当前构建芯片转换得到的 _cur_arch 做 IN_LIST 匹配,未命中则提前 return()。
  • 原有分支简化: 删除原先 MODULE_NPU_ARCH 优先、MODULE_COMPUTE_UNITS 回退的两段式判断逻辑,统一为单一路径;未配置时仍回退到 MODULE_COMPUTE_UNITS "ALL"。
  • 注释与语义说明更新: 函数头部注释与内部注释同步改为描述「soc/npuArch 混配、逐项转 arch、同 arch 的 soc 共享过滤结果(如 ascend950 与 ascend350 同为 dav_3510)」。

🧩 本次 Review 已使用自定义 Skill:

likedislike
Incorrect?
atomgit-bot
atomgit-bot
9 days ago Comments:

代码审查

审查结论(PR #14324,共 3 个发现,全部 P2)

逐文件确认

  • cmake/func.cmake:已逐行检视(文档注释 991-993、参数表 1004、过滤逻辑 1016-1038,并交叉核对 get_npu_arch_by_soc_version 1231-1245、add_modules_sources 706-716、soc_arch_variables.cmake 映射表、opbuild.cmake 消费方)→ 3 个问题,见下。
  • matmul/mat_mul_v3/CMakeLists.txt:已核对第 29 行的等价性 —— 原 ascend950/ascend350/ascend960dt/ascend960pr 映射为 dav_3510/dav_3510/dav_9201/dav_9202,新写法 dav_3510 dav_9201 ascend960pr(ascend960pr→dav_9202)得到同一 arch 集合,且与本文件其余 4 个调用(arch22/arch31/mc62)无 arch 重叠 → no issues。

发现清单(按优先级)

  1. P2 cmake/func.cmake:1023-1033 — COMPUTE_UNITS 统一按 arch 比较后,同 arch 兄弟 soc 互相命中;quant_batch_matmul_v3、quant_batch_matmul_inplace_add、gemm_syrk、fused_linear_cross_entropy_loss_grad 这些按 soc 拆分的调用会在单次构建下同时生效,产生重复且内容冲突(-Werror、SIMPLIFIED_KEY 1 外溢)的 kernel/option 注册记录。
  2. P2 cmake/func.cmake:1026-1029 — 映射表外 soc(如注释所列 ascend910_55)使 _cur_arch 恒为空,IN_LIST 恒假 → kernel 静默不编译、不打包;小写兜底分支对未映射 soc 实为死分支,丢失旧的 soc 精确匹配能力。
  3. P2 cmake/func.cmake:1004 — 删除 NPU_ARCH 关键字但未校验 MODULE_UNPARSED_ARGUMENTS,残留调用会静默把过滤退化为 ALL(全 soc 编译),并与仍保留 NPU_ARCH 的 add_modules_sources 契约分叉。

整体风险判断:改动方向(kernel 侧支持 soc/arch 混配)本身合理,mat_mul_v3 的调用改写语义等价;主要风险集中在 add_kernel_sources 过滤语义由「soc 精确」改为「arch 等价」引入的跨算子副作用与静默失败路径,建议合入前至少处理第 1、2 项,避免 950/350 构建出现重复或选项串台的 kernel 注册。

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

💬 仅评论


🧩 本次 Review 已使用自定义 Skill:

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
9 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
9 days ago 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.
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
cmake ✅ 陈琦, 杨阳 (2/2) ✅ 陈琦, 杨阳 (2/1)
matmul ✅ 杨阳, 陈琦, 王子韬 (3/2) ✅ 杨阳, 陈琦 (2/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
104 messages are collapsed here。 See more
yangyang016
yangyang016Collaborators
4 days ago Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
4 days ago Added label: lgtm
CANN-robotCANN-robotCollaborators
4 days ago Closed associated issue
CANN-robotCANN-robotCollaborators
4 days ago Merged pull request
CANN-robot
CANN-robotCollaborators
4 days ago Comments:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike