Pull Request已成功合入, 合并人@CANN-robot
(感谢 liu-wei 的贡献)变更摘要
本 PR 为 AICPU built-in 整包编译(--pkg)引入准入机制:新增 aicpu_builtin_package_manifest.cmake 策略文件,通过 AICPU_BUILTIN_PACKAGE_MANIFEST 清单与 AICPU_BUILTIN_PACKAGE_FORCE_ALL 开关控制哪些 AICPU 算子被打包 device 侧 .so 与 json 配置。默认清单为空(所有算子不进入 built-in 整包),在 cmake/func.cmake 的 add_all_modules_sources 中统一控制 AICPU 的 OpDef/JSON/cust_obj 三条路径,并在 cmake/symbol.cmake 的 gen_norm_symbol 中联动生成 AICPU 符号;不新增编译选项或命令参数,且不影响自定义包模式(--ops/--vendor_name)行为。
主要改动
- 新增 manifest 策略文件: 新增
cmake/config/aicpu_builtin_package_manifest.cmake,定义默认OFF的AICPU_BUILTIN_PACKAGE_FORCE_ALL与默认空的AICPU_BUILTIN_PACKAGE_MANIFEST,作为整包准入的配置入口(CMakeLists.txt中include该文件)。 - 准入判断逻辑: 在
cmake/func.cmake的add_all_modules_sources中新增_AICPU_BUILTIN_PKG_ALLOWED计算:FORCE_ALL为ON或 manifest 中存在匹配^${OP_NAME}=ON$的条目时准入,否则OFF。 - 统一控制三条打包路径:
AICPU_OP_DEF_SRCS与AICPU_JSON_FILES的收集条件改为ENABLE_CUSTOM OR _AICPU_BUILTIN_PKG_ALLOWED;AICPU 源文件打包逻辑重构为按ENABLE_CUSTOM与准入结果分流,built-in 路径仅当准入且依赖 CANN 安装包时调用add_aicpu_cust_kernel_modules。 - 符号生成联动: 在
cmake/symbol.cmake的gen_norm_symbol中新增gen_aicpu_json_symbol(TRUE)与gen_aicpu_kernel_symbol(TRUE)调用,无准入算子时自动跳过,保证整包产物与准入结果一致。


代码审查
评审总结
各变更文件复核结论
- CMakeLists.txt:发现 1 个 P1 问题 —— manifest 的
include()位于所有add_subdirectory()(算子处理)之后,导致准入变量在消费点未定义,本 PR 的核心机制静默失效。 - cmake/config/aicpu_builtin_package_manifest.cmake:文件本身写法正常(
FORCE_ALL/MANIFEST的默认值符合设计),但其中文档化的条目格式(math/new_op=ON)与 func.cmake 的实现不匹配,问题见 func.cmake 的 P2 发现。 - cmake/func.cmake:发现 2 个问题 —— P2:manifest 条目格式与
OP_NAME(叶子目录名)不匹配,按文档书写永远无法准入;P3:OP_NAME未转义拼入MATCHES正则,含元字符的算子名会误匹配/漏匹配。 - cmake/symbol.cmake:发现 1 个 P3 问题 —— 新增的
gen_aicpu_json_symbol(TRUE)使 built-in 模式首次消费 OpDef/JSON 收集,但该收集未受DISABLE_AICPU约束,DISABLE_AICPU开启时会出现"json 已安装而 device .so 未编译"的不一致打包。
发现统计
- P0:0
- P1:1
- P2:1
- P3:2
总体风险判断
本变更的核心问题在于 CMakeLists.txt 中 manifest include 的放置顺序:add_all_modules_sources 读取 manifest 变量的时机早于变量的定义,导致"manifest 准入"机制在按文档使用(编辑 manifest 文件)时完全不会生效,属于新增功能不可用的功能性缺陷(P1)。此外 manifest 条目格式与实现所用标识符不一致(P2)也会在使用时造成静默失败。P3 项为边界/一致性隐患,风险有限。建议在合入前优先修复 P1 的顺序问题并统一 manifest 条目格式,否则该特性实际不可用。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 2 |
| 🟡 建议 | 1 |
⛔ 需要修改


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 |
|---|---|---|
| math/lin_space | ✅ 王瑞, yue-ma (2/2) | ✅ 王瑞, yue-ma (2/1) |
| math/tan | ✅ 王瑞, yue-ma (2/2) | ✅ 王瑞, yue-ma (2/1) |
| repo-cann/ops-math | ✅ 王瑞, yue-ma (2/2) | ✅ 王瑞, yue-ma (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
liu-wei, thanks for your pull request. All authors of the commits have signed the CLA. 👍


The MR can not be merged, because of CodeReview discussion not resolved
If you want to solve this problem, you can click here to do it in the FAQs.


描述
新增aicpu_builtin_package_manifest.cmake策略文件,控制哪些AICPU算子在整包编译(--pkg)时打包device侧.so和json配置。
设计要点
改动文件
cmake/config/aicpu_builtin_package_manifest.cmake(新增):manifest策略文件CMakeLists.txt:在add_subdirectory之前include manifest文件cmake/func.cmake:add_all_modules_sources中增加manifest准入判断,统一控制AICPU的OpDef/JSON/cust_obj三条路径cmake/symbol.cmake:gen_norm_symbol中在ENABLE_PACKAGE且非DISABLE_AICPU时调用gen_aicpu_json_symbol和gen_aicpu_kernel_symbol(无准入算子时自动跳过)manifest使用方式
# cmake/config/aicpu_builtin_package_manifest.cmake set(AICPU_BUILTIN_PACKAGE_FORCE_ALL OFF) set(AICPU_BUILTIN_PACKAGE_MANIFEST # 新增算子想进入built-in整包时在此添加 # "new_op=ON" ) # 全量放开: set(AICPU_BUILTIN_PACKAGE_FORCE_ALL ON)关联的Issue
https://gitcode.com/cann/ops-math/issues/3194
测试
一、已有功能回归测试(manifest为空,验证不影响已有功能)
TC-01: 整包编译(manifest为空)
命令: bash build.sh --pkg --soc=ascend910_93 -j16
预期: 编译成功;libopconstant_folding_math.so 生成;libmath_aicpu_kernels.so 不生成;aicpu_math.json 不生成;AI Core 产物不变
TC-02: 自定义算子包编译(--ops=cumsum)
命令: bash build.sh --pkg --soc=ascend910_93 --ops=cumsum --vendor_name=custom -j16
预期: 编译成功;libmath_aicpu_kernels.so 生成(含cumsum + identity等);cust_aicpu_kernel.json 生成;与改动前行为一致
TC-03: AI Core 算子不受影响
命令: bash build.sh --pkg --soc=ascend910_93 --ops=add -j16
预期: AI Core kernel binary 正常编译,不涉及 aicpu 逻辑
TC-04: UT 编译不受影响
命令: bash build.sh -u --noexec --soc=ascend910_93 -j16
预期: UT 编译成功,aicpu kernel UT 可执行文件生成
TC-05: host常量折叠库不受manifest影响
命令: bash build.sh --pkg --soc=ascend910_93 -j16
预期: libopconstant_folding_math.so 生成且包含全部已有aicpu算子,manifest为空不影响host_const_obj收集
TC-06: 静态库编译不受影响
命令: bash build.sh --pkg --static --soc=ascend910_93 -j16
预期: 静态库编译成功,产物与改动前一致
二、manifest准入功能测试
TC-07: manifest为空时整包不产出device aicpu产物
前置: manifest中 AICPU_BUILTIN_PACKAGE_MANIFEST 为空
命令: bash build.sh --pkg --soc=ascend910_93 -j16
预期: libmath_aicpu_kernels.so 不生成;aicpu_math.json 不生成
TC-08: manifest指定单个算子ON(cumsum)
前置: manifest中 "cumsum=ON"
命令: bash build.sh --pkg --soc=ascend910_93 -j16
预期: libmath_aicpu_kernels.so 生成(仅含cumsum);aicpu_math.json 生成(仅含cumsum);libopconstant_folding_math.so 照常生成(含全部算子)
TC-09: manifest指定多个算子ON
前置: manifest中 "cumsum=ON" 和 "log=ON"
命令: bash build.sh --pkg --soc=ascend910_93 -j16
预期: libmath_aicpu_kernels.so 生成(含cumsum和log);aicpu_math.json 生成(含cumsum和log)
TC-10: AICPU_BUILTIN_PACKAGE_FORCE_ALL=ON全量放开
前置: manifest中 set(AICPU_BUILTIN_PACKAGE_FORCE_ALL ON)
命令: bash build.sh --pkg --soc=ascend910_93 -j16
预期: libmath_aicpu_kernels.so 生成(含全部aicpu算子);aicpu_math.json 生成(含全部aicpu算子)
TC-11: manifest中写ON但算子不存在
前置: manifest中 "nonexistent_op=ON"
命令: bash build.sh --pkg --soc=ascend910_93 -j16
预期: 编译成功(不报错);libmath_aicpu_kernels.so 不生成;aicpu_math.json 不生成
TC-12: --noaicpu仍然完全关闭aicpu
前置: manifest中 "cumsum=ON"
命令: bash build.sh --pkg --soc=ascend910_93 --noaicpu -j16
预期: DISABLE_AICPU=TRUE;不编译任何aicpu .o;不生成libmath_aicpu_kernels.so;不生成aicpu_math.json;不生成libopconstant_folding_math.so
三、manifest匹配准确性测试
TC-13: manifest key使用算子名
前置: manifest中 "cumsum=ON"
命令: bash build.sh --pkg --soc=ascend910_93 -j16
预期: 匹配成功,cumsum进入整包
TC-14: manifest key写错不匹配(大小写敏感)
前置: manifest中 "Cumsum=ON"(大写C)
命令: bash build.sh --pkg --soc=ascend910_93 -j16
预期: 不匹配(STREQUAL大小写敏感),cumsum不进入整包
TC-15: manifest value非ON不匹配
前置: manifest中 "cumsum=OFF"
命令: bash build.sh --pkg --soc=ascend910_93 -j16
预期: 不匹配(STREQUAL要求精确"=ON"),cumsum不进入整包
四、安装卸载测试
TC-16: 整包安装(manifest为空)
命令: bash build.sh --pkg --soc=ascend910_93 -j16 && bash build_out/*.run --quiet --full
预期: 安装成功无ERROR;opp/built-in/op_impl/host_cpu/libopconstant_folding_math.so 存在;opp/built-in/op_impl/aicpu/ 下无 aicpu_math.json 和 libmath_aicpu_kernels.so
TC-17: 整包安装(manifest指定ON)
前置: manifest中 "cumsum=ON"
命令: bash build.sh --pkg --soc=ascend910_93 -j16 && bash build_out/*.run --quiet --full
预期: 安装成功;opp/built-in/op_impl/aicpu/config/aicpu_math.json 存在;opp/built-in/op_impl/aicpu/kernel/libmath_aicpu_kernels.so 存在;opp/built-in/op_impl/host_cpu/libopconstant_folding_math.so 存在
TC-18: 整包卸载
命令: bash build_out/*.run --quiet --uninstall
预期: 卸载成功,所有aicpu相关文件被清理
五、4个特殊算子回归测试(topk/tan/lin_space/identity)
TC-19: 自定义包模式下4个算子行为不变
命令: bash build.sh --pkg --soc=ascend910_93 --ops=cumsum --vendor_name=custom -j16
预期: 4个算子在自定义包模式下仍被收入AICPU_CUST_OBJ_TARGETS;libmath_aicpu_kernels.so 包含 identity;cust_aicpu_kernel.json 包含 identity;与改动前行为一致
TC-20: 整包模式下4个算子受manifest控制
前置: manifest为空
命令: bash build.sh --pkg --soc=ascend910_93 -j16
预期: 4个算子不被收入AICPU_CUST_OBJ_TARGETS;libmath_aicpu_kernels.so 不生成;identity 不出现在任何产物中
TC-21: 整包模式下manifest指定topk=ON
前置: manifest中 "topk=ON"
命令: bash build.sh --pkg --soc=ascend910_93 -j16
预期: libmath_aicpu_kernels.so 生成(仅含topk);aicpu_math.json 生成(含topk);identity 不在产物中
TC-22: 整包模式下manifest指定identity=ON
前置: manifest中 "identity=ON"
命令: bash build.sh --pkg --soc=ascend910_93 -j16
预期: libmath_aicpu_kernels.so 生成(含identity);aicpu_math.json 生成(含identity,JSON文件正确收集);topk 不在产物中
六、pre-commit检查
TC-23: pre-commit通过
命令: pre-commit run --files <所有修改的文件>
预期: 全部 Passed
文档更新
无
类型标签