已合并
fix(build): 跳过仅有信息库无 op_kernel 的算子的 kernel 编译 #4900
fix(build): 跳过仅有信息库无 op_kernel 的算子的 kernel 编译 #4900
已合并
songkai111创建于 15 天前
songkai111成员
15 天前

描述

--pkg 出包模式下编译仅定义算子信息库、没有 kernel 实现的算子(如 bitcast)时,kernel 编译链路会报错。本次修改在 kernel 二进制编译阶段跳过这类算子,并补充缺失的算子信息格式支持:

改动原因

  • cmake/gen_ops_info.cmake 按 SoC 编译算子的循环中,对不存在 op_kernel 目录的算子执行 find ${OP_DIR}/op_kernel 会报"目录不存在"。
  • scripts/util/parse_ini_to_json.pyFORMAT_LIST 缺少 FRACTAL_NZ_C0_8(CANN 原生支持的 ACL_FORMAT_FRACTAL_NZ_C0_8),使用该格式的算子 ops-info 校验不通过。
  • scripts/kernel/binary_script/gen_opcinfo_from_opinfo.pyopFile.value=Null(仅有信息库、无 kernel 实现)的算子会残留 dynamic/Null.py 条目导致编译失败。

改动方法

  1. cmake/gen_ops_info.cmake:按 SoC 编译算子的循环中,对不存在 op_kernel 目录的算子直接 continue 跳过 kernel 二进制编译,与 get_op_type_and_validate 中已有的 op_kernel 目录判断保持一致,避免 find ${OP_DIR}/op_kernel 报目录不存在,并与 cann/ops-nn 仓的既有行为对齐。
  2. scripts/util/parse_ini_to_json.pyFORMAT_LIST 补充 FRACTAL_NZ_C0_8;同时按 ruff 格式重排文件(修复 pre-commit trailing-whitespace/ruff)。
  3. scripts/kernel/binary_script/gen_opcinfo_from_opinfo.pyopFile.value=Null/None 表示算子无 kernel 实现,不再写入 kernel 编译 csv,避免残留 dynamic/Null.py 条目;同时按 ruff 格式重排(修复 pre-commit ruff)。

关联的Issue

测试

本机 CANN 9.1.0 验证:

# 仅 bitcast(无 op_kernel)→ 构建成功,包内 ops-info 正常注册 Bitcast,无 kernel 二进制
$ bash build.sh --pkg --ops=bitcast --soc=ascend950 -j16
构建成功

# bitcast + abs 混合 → 构建成功,abs kernel 二进制正常生成,混合编译不受影响
$ bash build.sh --pkg --ops=bitcast,abs --soc=ascend950 -j16
构建成功

# pre-commit 全量 hook 通过

文档更新

类型标签

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

变更摘要

该 PR 旨在修复构建流程:对于仅有信息库(op info)定义、没有 op_kernel 目录实现(如 bitcast)的算子,跳过其 kernel 二进制编译,避免生成无效的 kernel 编译产物(如 dynamic/Null.py)导致编译失败,并与 get_op_type_and_validate 中关于 op_kernel 目录的判断保持一致。改动同时覆盖 CMake 编译脚本、kernel 二进制清单生成脚本,并顺带补充了格式列表中的一项。

主要改动

  • CMake 编译链路跳过无 kernel 算子cmake/gen_ops_info.cmake):在 gen_ops_info_and_python 遍历 COMPILED_OP_DIRS 时,若 ${OP_DIR}/op_kernel 目录不存在,则打印 INFO 日志并 continue() 跳过该算子的 kernel 二进制编译。
  • kernel 编译清单过滤空实现算子scripts/kernel/binary_script/gen_opcinfo_from_opinfo.py):在 get_res_from_file 中,当 op_fileNone 或取值 "null"/"none" 时,打印 INFO 日志并 continue 跳过,避免将仅有信息库定义的算子写入 kernel 二进制编译清单。
  • 补充 format 列表项scripts/util/parse_ini_to_json.py):在 FORMAT_LIST 中新增 "FRACTAL_NZ_C0_8",使格式枚举与新增格式保持一致。
likedislike
atomgit-bot
atomgit-bot
15 天前 评论:

代码审查

✅ 未发现问题

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

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 张磊, 周奇龙 (2/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

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

likedislike
此处折叠了45条消息 查看更多
CANN-robotCANN-robot成员
14 天前 添加了label:approved
zl_hw成员
13 天前 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
13 天前 添加了label:lgtm
CANN-robotCANN-robot成员
13 天前 关闭了关联的issue
CANN-robotCANN-robot成员
13 天前 合入了pull request