已合并
kernel ut 增加防卡死超时,快速模式,覆盖率控制 #8187
chenqi317创建于 27 天前
kernel ut 增加防卡死超时,快速模式,覆盖率控制 #8187
已合并
chenqi317创建于 27 天前
chenqi317成员
27 天前

描述

提交总结:kernel ut 增加防卡死超时、快速模式、覆盖率控制

修改背景:Kernel UT 存在单测卡死导致整套测试挂起、运行慢(addr2line 符号化耗时)、gcov 覆盖率始终链接带来不必要开销等问题。

修改方案

  1. 防卡死超时:新增 run_kernel_ut.sh,按 case 逐个执行并用 timeout 限时(默认 120s,--ut_timeout 可配),超时即标记失败并继续,避免单点卡死阻塞全流程。
  2. 快速模式:新增 --ut_mode=fast/debug。fast 模式关闭符号化(注入 fake addr2line 跳过慢解析)、改用 -g0 -O2,用于快速验证;debug 模式保留 -g 与符号化,用于开发调试。
  3. 覆盖率控制:将 ut.cmake 中 gcov 的无条件链接改为 $<$<BOOL:${ENABLE_COVERAGE}>:gcov> 条件链接,仅在开启覆盖率时引入;
  4. 修复失败的kernel ut:TensorFlow 依赖替换为md_dtypes, 修复部分block 越界,缺少SetKernelMode 设置导致核获取错误等问题

关联的Issue

https://gitcode.com/cann/ops-nn/issues/4606

测试

通过kernel ut 测试,bash build.sh -u --opkernel --ut_mode=fast --ut_timeout=60

文档更新

类型标签

AI/Agent生成声明

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

变更摘要

此 PR 主要围绕 Kernel UT(单元测试)构建与运行流程,新增了防卡死超时机制、快速模式(跳过符号化并优化编译)以及覆盖率条件化控制。通过 build.sh 新增 --ut_mode--ut_timeout 选项,将相关参数透传至 CMake;CMake 中将原本硬编码的覆盖率选项和调试符号改为条件化控制;同时新增 run_kernel_ut.sh 脚本实现逐用例超时执行与结果汇总。

主要改动

  • 新增 --ut_mode--ut_timeout 构建选项:在 build.sh 中新增两个 long option,--ut_mode 支持 debug(启用符号化、-g-O0)和 fast(禁用符号化、-g0-O2)两种模式,--ut_timeout 指定每用例超时秒数(默认 30),并透传为 CMake 变量 ENABLE_UT_SYMBOLIZEUT_CASE_TIMEOUTUT_DEBUG_FLAG

  • 覆盖率选项条件化控制:在 cmake/intf_pub_llt_gccnative.cmake 中,将四个接口目标(intf_llt_pubintf_llt_pub_asanintf_llt_pub_asan_cxx14intf_llt_pub_asan_cxx17)中原本硬编码的 --coverage-fprofile-arcs-ftest-coverage 编译选项及 gcov 链接库统一改为 $<$<BOOL:${ENABLE_COVERAGE}>:...> 条件生成器表达式,同时移除了硬编码的 -g 调试标志。

  • UT 编译调试标志可配置化:在 cmake/ut.cmakeAddOpTestCase 函数中,将 operator kernel 用例及其辅助源文件的编译选项从固定 -g 替换为 ${UT_DEBUG_FLAG},使调试信息级别可由 build.sh--ut_mode 控制。

  • 新增 Kernel UT 逐用例超时运行脚本:新增 tests/ut/op_kernel/scripts/run_kernel_ut.sh,通过 timeout --foreground 逐用例执行 gtest 测试,支持禁用 addr2line 符号化(fake addr2line 脚本)、ASAN 预加载、禁用 core dump,并输出 pass/fail/timeout 汇总结果。

  • 移除 classify_rule.yaml 中的重复匹配规则:删除了 matmul@ops-nnmatmul-quant@ops-nn 分类规则中重复的 - ops/ops-nn/matmul/*/op_kernel/ 条目。

likedislike
atomgit-bot
atomgit-bot
27 天前 评论:

代码审查

审查总结

按文件逐一确认:

文件 审查结论
CMakeLists.txt 发现问题 — P1: ENABLE_UT_SYMBOLIZE 的 ON/OFF vs TRUE/FALSE 不匹配
build.sh 无问题 — ccache 配置新增和 ut_mode/ut_timeout 参数处理均正确
classify_rule.yaml 无问题 — 移除 matmul op_kernel 排除规则是合法的 YAML 变更
cmake/intf_pub_llt_gccnative.cmake 无问题 — coverage 标志条件化改造正确;尾随空格清理无害
cmake/ut.cmake 无问题 — -g${UT_DEBUG_FLAG}gcov 条件化均正确一致
tests/ut/op_kernel/CMakeLists.txt 发现问题 — P2: ASAN_OPTIONS=detect_leaks=0 丢失
tests/ut/op_kernel/scripts/run_kernel_ut.sh 发现问题 — P2: 缺少 set -e/-u;P3: bash -c 拼接潜在风险

按优先级统计:

  • P0: 0
  • P1: 1(ENABLE_UT_SYMBOLIZE 值不匹配 → fast 模式符号化无法关闭)
  • P2: 2(ASAN_OPTIONS 丢失、脚本鲁棒性不足)
  • P3: 1(bash -c 命令拼接,低风险可选改进)

整体风险判断:中等。 P1 问题导致 --ut_mode=fast 的核心目的之一(禁用符号化以加速/防卡死)在当前代码路径下无法生效,需要修复后才能达到 PR 描述的"快速模式"效果。P2 的 ASAN_OPTIONS 丢失可能在实际 ASAN 测试中产生噪音或误报。

类型 数量
🔴 阻塞 1
🟡 建议 2

⛔ 需要修改

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

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
activation 汤平川, 查建青, 范其瑞 (3/2) 汤平川, 查建青 (2/1)
cmake 商晓波, 汤平川, 范其瑞 (3/2) 商晓波 (1/1)
foreach 范其瑞, 汤平川, 查建青 (3/2) 查建青, 汤平川 (2/1)
index 汤平川, 范其瑞 (2/2) 汤平川 (1/1)
loss 汤平川, 范其瑞 (2/2) 汤平川 (1/1)
norm 汤平川, 查建青, 范其瑞 (3/2) 汤平川, 查建青 (2/1)
repo-cann/ops-nn 汤平川, 范其瑞 (2/2) 汤平川 (1/1)
tests 查建青, 范其瑞, 汤平川 (3/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

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

likedislike
此处折叠了173条消息 查看更多
sxb154714
sxb154714成员
23 天前 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
23 天前 添加了label:approved
CANN-robotCANN-robot成员
23 天前 关闭了关联的issue
CANN-robotCANN-robot成员
23 天前 合入了pull request
CANN-robot
CANN-robot成员
23 天前 评论:

Pull Request 已合并或已关闭。

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

likedislike