Pull Request已成功合入, 合并人@CANN-robot
(感谢 yang-di52 的贡献)变更摘要
该 PR 旨在解决 ophost 单元测试在 910b 平台上全量执行失败的问题。核心思路是清理项目中的冗余 CMakeLists.txt 文件,并完整移除已废弃的 ophost_metric_manager 和 ophost_metric_loader 模块。变更涉及 20 个文件,均为删除操作(共删除 224 行,无新增),主要包括:删除 ophost_metric_manager 的所有源文件(.cpp、.h、.proto)及其 CMake 构建入口;删除 ophost_metric_loader 插件及其构建配置;清理 operators/python/plugins/ 下多个子目录的冗余 CMakeLists.txt;从 collect_data.c 中移除 ophost_metric_loader 的动态加载与初始化逻辑;同步调整 Python 单元测试用例以适配上述模块的移除。
主要改动
-
移除
ophost_metric_manager模块:完整删除source/managers/host/internal/ophost_metric_manager/目录下的 6 个文件(collect_metric_data.cpp/.h、host_metric_data.cpp/.h、ophost_metric_manager.cpp/.h、ophost_metric_manager.proto)以及source/managers/host/ophost_metric_manager/下的CMakeLists.txt和ophost_metric_manager.h,同时从source/managers/host/internal/CMakeLists.txt中移除对应的add_subdirectory指令。 -
移除
ophost_metric_loader插件:删除operators/python/plugins/ophost_metric_loader/CMakeLists.txt构建文件,并从父级operators/python/plugins/CMakeLists.txt中移除add_subdirectory(ophost_metric_loader)调用,彻底解除该插件的编译。 -
清理
collect_data.c中的 metric 集成逻辑:在source/manager/host/collect_data.c中删除ophost_metric_manager.h头文件引用、ophost_metric_loader动态库的加载代码以及对OphostMetricInit/OphostMetricDestroy的调用,同时移除source/manager/host/CMakeLists.txt中与ophost_metric_loader相关的链接配置和安装步骤。 -
清理
operators/python/plugins/下的冗余 CMakeLists:删除tf_adapter、cmytf_adapter、ophost、hv_mmu_gda四个子目录的独立CMakeLists.txt文件,并精简父级CMakeLists.txt中的add_subdirectory条目;同步从ascend_npu/CMakeLists.txt中移除add_subdirectory(ophost)。 -
调整 Python 单元测试用例:在
tests/ut/test_ascend_npu/下的多个测试文件中移除'ophost'相关测试参数、删除ophost_metric相关测试用例,并调整test_npu_profile.py中部分测试的预期行为(如将assertRaises替换为直接断言),以适配上述模块的删除。


代码审查
我已经完成了全面的分析。以下是审查摘要。
审查摘要
发现的问题
| 优先级 | 数量 | 说明 |
|---|---|---|
| P2 | 1 | 五个操作符的 arch35 tiling 单元测试因 CMakeLists.txt 删除而永久丢失 |
详细分析
删除分类:
-
15 个文件:删除操作安全。这些文件要么是真正的冗余文件(父级
add_modules_ut_sources已处理),要么已经是死代码(父级无add_subdirectory遍历导致从未被包含),要么是空/无操作文件。 -
5 个文件存在问题(已报告的 P2 发现项):
norm/lp_norm_update、optim/apply_adam_v2、optim/fused_mul_apply_momentum、optim/inplace_apply_keras_momentum和loss/soft_margin_loss_grad。这些操作符的父级op_host/CMakeLists.txt没有调用add_modules_ut_sources(),完全依赖add_subdirectory遍历来包含其 arch35 测试。删除后,这些测试将永远不会被编译——即使在显式设置ASCEND_COMPUTE_UNIT=ascend950的情况下也是如此。
总体风险评估
对于修复 910b 上 ophost UT 全部执行失败的主要目标,此更改是正确且有效的。根本原因是:当在未设置 ASCEND_COMPUTE_UNIT 的情况下构建时,add_subdirectory 遍历会无条件地包含所有 arch 目录的 CMakeLists.txt 文件,导致仅适用于 ascend950 的 arch35 测试在 910b(arch22)上编译并运行,从而引发空指针崩溃。删除这些 CMakeLists.txt 文件后,arch35 测试仅在通过父级 add_modules_ut_sources 的 target_dir glob 机制显式设置 ASCEND_COMPUTE_UNIT 时才会被包含。
然而,有五个操作符的 tiling 测试没有通过父级的 add_modules_ut_sources 覆盖——它们将完全丢失。这些测试需要在父级 CMakeLists.txt 中恢复,并添加合适的架构守卫,或者恢复其 arch35 CMakeLists.txt 并添加 ASCEND_COMPUTE_UNIT 守卫。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 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
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| matmul | ✅ 范其瑞, 陈琦 (2/2) | ✅ 范其瑞, 陈琦 (2/1) |
| repo-cann/ops-nn | ✅ 范其瑞, 陈琦 (2/2) | ✅ 范其瑞, 陈琦 (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
yang-di52, thanks for your pull request. All authors of the commits have signed the CLA. 👍


流水线任务触发成功
任务链接 [805947498d984cf4bf76b39034516924][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_experimental | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Pre | ✅ SUCCESS | >>>>> | |
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_950_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_950_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_classify | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_mobile_station_9030_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| UT_Test_ophost | ✅ SUCCESS | ||
| UT_Test_opapi | ✅ SUCCESS | ||
| UT_Test_kernel | ✅ SUCCESS | ||
| UT_Test_opgraph | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| API_Check | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> | |
| UT_Test_harmony-infer-chs-nn | ✅ SUCCESS | ||
| UT_Test_harmony-infer-chs-nn-1 | ✅ SUCCESS | ||
| UT_Test_harmony-infer-cpro-nn | ✅ SUCCESS | ||
| UT_Test_report_lcov | ✅ SUCCESS | >>>>> |
[2026-08-12 10:41:49] CI执行结束


流水线任务触发成功
任务链接 [bcbd6c9178fc454db8e7442fb1c0c26e][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_checkpr | ✅ SUCCESS | ||
| StaticCheck_codespell | ✅ SUCCESS | ||
| StaticCheck_link_validity | ✅ SUCCESS | ||
| StaticCheck_resource_existence | ✅ SUCCESS | ||
| StaticCheck_tag_closed | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_precommit | ✅ SUCCESS | >>>>> | |
| SCA | ✅ SUCCESS | >>>>> |
[2026-08-12 10:20:57] CI执行结束


/lgtm
/approve


描述
关联的Issue
#4734
测试
文档更新
类型标签
AI/Agent生成声明