Merged
feat: 构建与CI流程适配 npuArch 算子注册(AddConfigByArch) #6990
esok11Add on 9 days ago
feat: 构建与CI流程适配 npuArch 算子注册(AddConfigByArch) #6990
Merged
esok11Add on 9 days ago
esok11Collaborators
9 days ago

描述

ops-math 算子注册方式正在从 AddConfig("<socVersion>") 迁移到 ArchConfigHelper::AddConfigByArch(Ops::Base::DAV_xxx)(npuArch 注册),但仓库内构建与 CI 侧的“算子是否支持某芯片”判定仍只识别 AddConfig("<socVersion>")。这会将只用 AddConfigByArch 注册的算子误判为“不支持当前芯片”,进而影响 tiling 目录收集、ops-info 生成、CI 算子筛选、本地自检与 cannsim 选算子。本 PR 为 soc/npuArch 构建适配,补齐上述链路的 arch 识别能力。

改动方法

  • cmake/func.cmake(add_all_modules_sources):NPU_ARCH 与 TILING_DIR 仍按位置一一配对,但当前构建芯片的匹配 key 改为统一先换算为 npuArch 再匹配;仅当声明列表中查不到该 npuArch(即列表里全是 socVersion 的老写法)时,回退为按 socVersion 字面值匹配,保持对旧配置的兼容。
  • cmake/gen_ops_info.cmake(check_op_supported):在原有 \.AddConfig(\s*"${COMPUTE_UNIT}" 之外增加 AddConfigByArch ... <ARCH_UPPER> 备选匹配分支(主模块与 MODULE_EXT 两处 grep 同步),get_npu_arch_by_soc_version 可用且能换算时才启用,避免非 arch 芯片误匹配。
  • scripts/ci/gen_ci_cmd.py:新增 SOC_TO_ARCH 映射与 soc_to_arch(),check_op_supports_soc 在原有 AddConfig("{soc}") 字符串判断外,增加 AddConfigByArch + 对应 DAV_xxx 的正则判定。
  • scripts/ci/gen_ops_soc.py:新增 SOC_TO_ARCH 及由其反向推导的 ARCH_TO_SOC_NAMES;新增 extract_add_config_by_arch_configs() 解析 AddConfigByArch 调用中的 DAV_xxx 并映射回 socVersion,汇入 extract_ai_core_configs(),使算子分组(grouped)能正确识别 arch 注册的算子;另含引号/格式整理(无逻辑变化)。
  • scripts/ci/local_check.sh:内置 SOC_TO_ARCH 关联数组与 soc_to_npu_arch(),op_supports_soc 增加 AddConfigByArch[^;]*DAV_xxx 判断;cannsim 跳过提示补充 AddConfigByArch(DAV_3510) 说明;其余为行尾空白清理(无逻辑变化)。
  • cmake/opbuild.cmake:gen_op_host_* 目标链接 opbase_util_objs(存在时)并加入 OPBASE_INC_DIRS 头文件搜索路径,满足 op def 侧依赖 opbase 公共实现/头文件的编译需求。
  • cmake/third_party/opbase.cmake:OPBASE_TAG_ID 由 f09beaf70dd62c9c089c237cbfcdc2bd2cb757d6 升级到 ab014585877c660db1f024a04b43650867556fbc,与 opbase 侧配套改动对齐。

关联的Issue

测试

本 PR 为构建与 CI 脚本、CMake 配置适配,不涉及算子功能与精度,未新增算子用例。建议验证:

  • 按 arch 注册的算子构建:bash build.sh --pkg --soc=<soc_version> -j<n>,确认 tiling 目录能被 NPU_ARCH/TILING_DIR 正确收集;
  • ops-info 生成阶段,确认 check_op_supported 对 AddConfigByArch 注册算子返回支持;
  • CI 算子筛选与分组:scripts/ci/gen_ci_cmd.py、scripts/ci/gen_ops_soc.py 对含 AddConfigByArch 的 *_def.cpp 能输出对应 socVersion;
  • 本地自检:scripts/ci/local_check.sh --soc=<soc_version> 的编译/LLT/cannsim 流程能正确选中 arch 注册的算子。

文档更新

无文档变更。

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for esok11's contribution.)
Eesok11Collaborators
9 days ago Created pull request, commit 3f1597ff
atomgit-bot
atomgit-bot
9 days ago Comments:

变更摘要

本次改动主要围绕 Addr 算子的架构配置与 BOOL 输出处理展开:一方面将原先按 ascend950/ascend350 分别注册的 AICore 配置和二进制编译配置,统一改为通过 opbase::ArchConfigHelper::AddConfigByArch 与 dav_3510 架构标识进行注册;另一方面把 BOOL 类型结果的 0/1 归一化逻辑从 aclnn_addr.cpp 的 host 侧 Cast 链路下沉到 addr_dag.h 的 Kernel 实现中,从而简化 addrOutHandle 的职责。

主要改动

  • 架构配置统一注册:addr_def.cpp 引入 op_common/op_host/util/op_arch_helper.h,用 opbase::ArchConfigHelper::AddConfigByArch(this->AICore(), Ops::Base::DAV_3510, aicoreConfig) 替代原来对 ascend950 与 ascend350 的两次 AddConfig 调用。
  • 二进制编译配置调整:ascendc_config.json 中 Addr 的 compute_units 由 ["ascend950", "ascend350"] 改为 ["dav_3510"],与算子侧新的架构标识保持一致。
  • Kernel 侧 BOOL 归一化:addr_dag.h 在 AndFF 中引入 <type_traits>,当 DTYPE_X1 为 bool 时,对 And 结果执行 Mins(dst, dst, static_cast<T>(1), count),将 [0, 255] 的结果收敛为 BOOL 语义的 0/1。
  • Host 侧输出处理简化:aclnn_addr.cpp 的 addrOutHandle 去掉 hightDtype 入参以及先 Cast 到 DT_INT8 再 Cast 回 DT_BOOL 的归一化步骤,仅保留向 out 数据类型的 l0op::Cast,并同步更新 addrStub 与 addrProc 中的调用处。

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

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

代码审查

我已完成对全部 5 个变更文件的审查,结果如下:

审查结论

按优先级统计的发现:P0 0 项、P1 0 项、P2 3 项、P3 0 项。

各变更文件审查情况

文件 结论
math/addr/CMakeLists.txt 1 项(P2):SUPPORT_COMPUTE_UNIT 改为 dav_3510,并且全仓其他算子都使用 soc 名,op_host/config 下也无 dav_3510 目录,因此在 ascend950/ascend350 上存在 kernel 或二进制配置找不到的风险
math/addr/op_api/aclnn_addr.cpp 无独立缺陷:3 处 addrOutHandle 调用点均已同步去掉 hightDtype 形参(229 行定义、279/291/334 行调用一致);删除 BOOL 双重 Cast 的语义依赖 kernel 侧归一化,已合并到 addr_dag.h 的发现中
math/addr/op_host/addr_def.cpp 无独立缺陷:ascend950/ascend350 两处 AddConfig 被 ArchConfigHelper::AddConfigByArch(DAV_3510) 单点替换,与 CMakeLists 的三项配置数量一致,未见漏改的调用点(头文件与符号无法在受限工作区验证,风险已并入 CMakeLists 那条)
math/addr/op_kernel/arch35/addr_dag.h 1 项(P2):BOOL 的 0/1 归一化改为只依赖 DTYPE_X1 == bool,而 host 侧兜底已被删除;若 kernel 以 int8 实例化,BOOL 输出会出现字节值 2
scripts/kernel/binary_config/ascendc_config.json 1 项(P2):compute_units 改为 ["dav_3510"],但 compile_options 的 key 仍是 ascend950/ascend350,全文件唯一一处两者不相交,-mllvm -cce-aicore-dcci-before-kernel-end=false 可能被静默丢弃

整体风险判断

本次改动属于“npuarch 化”命名迁移 + BOOL 归一化从 host 移至 kernel 的行为搬迁,逻辑意图自洽;主要风险集中在构建/配置识别层:dav_3510 这一名称在仓库的 CMake 与二进制配置消费链路中没有其他先例,一旦构建或配置查找未做 arch→soc 映射,addr 在 ascend950/ascend350 上会丢失内核或丢失编译选项(P2 级的生产回归)。其次,BOOL 归一化失去 host 兜底后,正确性完全系于 DTYPE_X1 的 dtype 宏映射,且未见对应 UT 覆盖。建议合并前在 ascend950/ascend350 上实跑一次 kernel 编译与 BOOL dtype 用例确认。

类型 数量
🔴 阻塞 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
repo-cann/ops-math ✅ 王瑞, zhanw_coding (2/2) ✅ 王瑞 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
107 messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
7 days ago Added label: lgtmapproved
CANN-robot
CANN-robotCollaborators
7 days ago Comments:

The MR can not be merged, because of this MR is work in process.

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

likedislike
Eesok11Collaborators
7 days ago Draft state has been cancelled
CANN-robotCANN-robotCollaborators
7 days ago Closed associated issue
CANN-robotCANN-robotCollaborators
7 days ago Merged pull request