Closed
[Bug-Report|缺陷反馈]: 910C(A3) 按《源码构建》执行 add_example 的 kernel UT 无任何用例运行(AddOpTestCase 未注册) #8321
HuangRZzzzAdd on  15 days agoClosed at  12 days ago
HuangRZzzz
HuangRZzzzCollaborators
15 days ago Create

Describe the current behavior / 问题描述

在 910C(Atlas A3,--soc=ascend910_93)按《源码构建》(docs/zh/install/compile.md「本地验证」)执行 add_example 的 kernel 侧 UT:

bash build.sh -u --opkernel --ops=add_example --soc=ascend910_93 -j40

构建成功(Built target nn_op_kernel_ut),但没有任何用例被执行(无 gtest 输出、build 目录下无 UT 可执行文件),fastOpTestSocVersions 为空。

根因分析

  1. AddOpTestCase 实际未注册(提前 return):cmake/func.cmake 的 add_category_subdirectory() 中,examples 相关目录是在算子循环之外通过 add_subdirectory(examples) 加载的;此时宏作用域内 OP_DIR/OP_NAME 仍残留循环最后一次迭代的算子(实测为 control/update_tensor_desc)。examples 下的 AddOpTestCase(add_example ...) 因而走 OP_NAME_DIR=${OP_DIR} 分支,list(FIND ASCEND_OP_NAME update_tensor_desc) 在 --ops=add_example 过滤下得到 INDEX=-1,直接 return(),用例注册被静默跳过(该问题对所有 SOC 均存在)。
  2. SOC 注册缺失:examples/add_example/tests/ut/op_kernel/CMakeLists.txt 仅注册 ascend910B1;而 examples/add_example/op_host/add_example_def.cpp 的 AddConfig 与 README 均声明支持 A2(ascend910b)/A3(ascend910_93)/950(ascend950)。即使问题 1 修复,A3/950 上仍无法命中用例。

复现与证据(CANN 9.2.0 / aarch64 / master b5949092)

bash build.sh -u --opkernel --ops=add_example --soc=ascend910_93 -j40
grep fastOpTestSocVersions build/CMakeCache.txt      # 为空
find build -name "nn_op_kernel_ut*"                   # 无 UT 可执行文件
# 在 examples/add_example/tests/ut/op_kernel/CMakeLists.txt 增加调试打印可见残留值:
# OP_NAME=update_tensor_desc OP_DIR=.../control/update_tensor_desc

Describe the expected behavior / 预期结果

  • --soc=ascend910_93(910C/A3)上能注册并执行 add_example 的 kernel UT 用例;
  • 注册范围与 add_example_def.cpp/README 声明的 A2/A3/950 支持范围一致。

修复建议

  1. cmake/func.cmake 的 add_category_subdirectory() 在 add_subdirectory(examples) 前 unset(OP_DIR) / unset(OP_NAME);
  2. examples/add_example/tests/ut/op_kernel/CMakeLists.txt 的注册补齐 A3/950(注意 tikicpulib 目标名大小写):AddOpTestCase(add_example "ascend910B1;Ascend910_9391;ascend950pr_9599" "")。

本地验证(已按上述修复):

  • --soc=ascend910_93 → fastOpTestSocVersions=Ascend910_9391,[ PASSED ] 1 test;
  • --soc=ascend910b → ascend910B1,PASS;--soc=ascend950 → ascend950pr_9599,PASS。

(若某算子确实不支持当前硬件,建议在 UT 注册处或文档显式说明;本 issue 中 add_example 属于“支持但未注册”。)

likedislike
HuangRZzzzHuangRZzzzCollaborators
15 days ago Associated pull request
HuangRZzzz
HuangRZzzzCollaborators
15 days ago Comments:

已提交修复 PR:#13839(https://gitcode.com/cann/ops-nn/pulls/13839)——`cmake/func.cmake` 在加载 examples 前清理残留的 OP_DIR/OP_NAME;examples/add_example/tests/ut/op_kernel/CMakeLists.txt 注册补齐 Ascend910_9391(A3)与 ascend950pr_9599(950)。本地验证:--soc=ascend910_93/ascend910b/ascend950 均 [ PASSED ] 1 test。

likedislike
HuangRZzzzHuangRZzzzCollaborators
15 days ago Modify description of issue
yuning_chenyuning_chenCollaborators
15 days ago Assign HuangRZzzz as responsible person
CANN-robotCANN-robotCollaborators
12 days ago Close issue
CANN-robotCANN-robotCollaborators
12 days ago changed custom state from 进行中 to 已完成
CANN-robotCANN-robotCollaborators
12 days ago Added label: resolved
丛吉钰丛吉钰Collaborators
5 days ago Deleted associated pull request: fix(cmake): 修复 examples 下 AddOpTestCase 未注册并补齐 add_example UT 的 SOC