Pull Request已成功合入, 合并人@ascend-robot
(感谢 rich 的贡献)变更摘要
该 PR 新增了 aclnnReselectStaticKernelWithPath 接口,在静态编译场景下支持通过指定路径来重新选择静态 Kernel,实现按进程隔离的静态 Kernel 生效路径。变更涉及底层 C++ 动态加载封装、Python 绑定以及模块初始化层的暴露。
主要改动
- 新增
ReselectStaticKernelWithPath函数:在OpInterface.cpp中动态加载aclnnReselectStaticKernelWithPath符号并封装调用,接受const std::string &path参数,失败时报错NOT_FOUND;对应的声明与注释添加在OpInterface.h中。 - 新增 Python 绑定函数
THNPModule_aclnn_reselect_static_kernel_with_path:在Module.cpp中对传入路径进行严格校验(非空字符串、无空字节、路径存在且为目录),调用前后均执行emptyAllNPUStream清空 NPU 任务队列,并适配task_queue_enable == 2模式通过OpCommand::RunOpApiV2执行。 - 注册 Python 方法
_aclnn_reselect_static_kernel_with_path:在Module.cpp的方法表THNPModule_methods中以METH_O形式注册,使 Python 层可调用该接口。 - Python 层封装
_aclnn_reselect_static_kernel_with_path:在__init__.py中添加对_lazy_init()的调用,确保 NPU 初始化后调用底层 C 函数。


代码审查
现在我对所有四个文件都有了全面的了解。让我总结分析结果。
最终分析
经过对整个代码变更的详细分析,我得出以下结论:
OpInterface.cpp 和 OpInterface.h
- 新增的
ReselectStaticKernelWithPath函数完美遵循了现有ReselectStaticKernel的模式,包括函数加载、空指针检查和错误报告。 - 头文件新增了正确的包含(
<string>)和声明。
Module.cpp
- 新增的
THNPModule_aclnn_reselect_static_kernel_with_path函数严格遵循现有THNPModule_aclnn_reselect_static_kernel的模式。 - 路径验证是最佳实践:字符串类型检查、空字节检查、存在性检查、目录检查。
- 新增代码在
task_queue_enable == 2lambda 中正确返回aclnnStatus(而现有代码总是返回 0),改进了错误传播。 else分支使用NPU_CHECK_ERROR正确检查返回码(现有代码完全忽略它)。METH_O用法与PyObject* self, PyObject* arg签名匹配。- 通过
HANDLE_TH_ERRORS/END_HANDLE_TH_ERRORS正确处理异常。
init.py
- Python 包装器严格遵循现有
_aclnn_reselect_static_kernel的模式,在调用 C++ 函数之前调用_lazy_init()。
无发现
经过彻底审查(包括与所有相关现有模式的对比、边界值分析、异步任务队列生命周期检查和错误处理验证),此 diff 中没有引入任何真实问题。新增代码的所有错误路径都有适当保护,并且它遵循现有代码库的模式。
结束总结
- 各文件发现数:
torch_npu/csrc/core/npu/interface/OpInterface.cpp:无问题torch_npu/csrc/core/npu/interface/OpInterface.h:无问题torch_npu/csrc/npu/Module.cpp:无问题torch_npu/npu/__init__.py:无问题
- P0 发现:0
- P1 发现:0
- P2 发现:0
- P3 发现:0
- 整体风险评估:低 — 这是一个干净、结构良好的新增内容,正确复制了现有模式,并改进了现有代码忽略返回码的相关返回码处理方式。没有引入正确性、安全性、可靠性或破坏性变更问题。
⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。


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 |
|---|---|---|
| repo-Ascend/pytorch | ✅ htchu, luochao60 (2/2) | ✅ htchu (1/1) |
| torch_npu/npu | ✅ htchu, luochao60 (2/2) | ✅ htchu (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
rich9527, thanks for your pull request. All authors of the commits have signed the CLA. 👍


当前仓库存在以下 保护分支 :
| Protected Branch | Version | Release |
|---|---|---|
| master | ||
| v2.10.0 | ||
| v2.7.1-26.1.0 | ||
| v2.9.0-26.1.0 | ||
| v2.10.0-26.1.0 | ||
| v2.11.0-26.1.0 | ||
| v2.12.0-26.1.0 | ||
| v2.12.0 | ||
| v2.11.0 | ||
| v2.9.0 | ||
| v2.7.1 | ||
| ci-test |
评论 /sync <branch1> <branch2> ... 可将当前 PR 修改同步到其它分支(创建同步 PR):
a) 如果当前 PR 是 Open 状态,同步操作将延迟到 PR 被合并时执行
b) 如果当前 PR 已经 Merged,将立即执行同步操作
注意:
- /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
- 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭


ascend docs pipeline is running...


✅ 跳过 docs ci 检查,没有需要检查的文档文件


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| Build_LibTorch_x86 | ✅ | >>> | |
| Build_LibTorch_ARM | ✅ | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| patch_test | 🛑 | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | CodeCheck | ✅ | >>> |
| check_error | ✅ | >>> | |
| CodeCheck_lintrunner | ✅ | >>> | |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | UT_X86_Part_01 | 🛑 | >>> |
| UT_X86_Part_02 | 🛑 | >>> | |
| UT_ARM_A3_Part_01 | 🛑 | >>> | |
| UT_ARM_A3_Part_02 | 🛑 | >>> | |
| UT_ARM_A2_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Part_02 | ✅ | >>> | |
| UT_ARM_A2_Part_03 | ❌ | >>> | |
| UT_inductor_Part_01 | 🛑 | >>> | |
| UT_inductor_Part_02 | 🛑 | >>> | |
| UT_inductor_Part_03 | 🛑 | >>> | |
| UT_inductor_Part_04 | 🛑 | >>> | |
| UT_DIST_ARM_Part_01 | 🛑 | >>> | |
| UT_DIST_ARM_Part_02 | 🛑 | >>> | |
| UT_DIST_ARM_Part_03 | 🛑 | >>> | |
| UT_DIST_ARM_Part_04 | 🛑 | >>> | |
| UT_ARM_A2_Select_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Select_Part_02 | ✅ | >>> | |
| 流水线 | PR-pipeline_pytorch | ❌ | >>> |
- compile、compile_inductor、compile_torchair : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| Build_LibTorch_x86 | ✅ | >>> | |
| Build_LibTorch_ARM | ✅ | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| patch_test | 🛑 | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | CodeCheck | ✅ | >>> |
| check_error | ✅ | >>> | |
| CodeCheck_lintrunner | ✅ | >>> | |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | UT_X86_Part_01 | 🛑 | >>> |
| UT_X86_Part_02 | 🛑 | >>> | |
| UT_ARM_A3_Part_01 | 🛑 | >>> | |
| UT_ARM_A3_Part_02 | 🛑 | >>> | |
| UT_ARM_A2_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Part_02 | ✅ | >>> | |
| UT_ARM_A2_Part_03 | ❌ | >>> | |
| UT_inductor_Part_01 | 🛑 | >>> | |
| UT_inductor_Part_02 | 🛑 | >>> | |
| UT_inductor_Part_03 | 🛑 | >>> | |
| UT_inductor_Part_04 | 🛑 | >>> | |
| UT_DIST_ARM_Part_01 | 🛑 | >>> | |
| UT_DIST_ARM_Part_02 | 🛑 | >>> | |
| UT_DIST_ARM_Part_03 | 🛑 | >>> | |
| UT_DIST_ARM_Part_04 | 🛑 | >>> | |
| UT_ARM_A2_Select_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Select_Part_02 | ✅ | >>> | |
| 流水线 | PR-pipeline_pytorch | ❌ | >>> |
- compile、compile_inductor、compile_torchair : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


compile


ascend docs pipeline is running...


✅ 跳过 docs ci 检查,没有需要检查的文档文件


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| Build_LibTorch_x86 | ✅ | >>> | |
| Build_LibTorch_ARM | ✅ | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| patch_test | 🛑 | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | CodeCheck | ✅ | >>> |
| check_error | ✅ | >>> | |
| CodeCheck_lintrunner | ✅ | >>> | |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | UT_X86_Part_01 | 🛑 | >>> |
| UT_X86_Part_02 | 🛑 | >>> | |
| UT_ARM_A3_Part_01 | 🛑 | >>> | |
| UT_ARM_A3_Part_02 | 🛑 | >>> | |
| UT_ARM_A2_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Part_02 | ✅ | >>> | |
| UT_ARM_A2_Part_03 | ✅ | >>> | |
| UT_inductor_Part_01 | 🛑 | >>> | |
| UT_inductor_Part_02 | 🛑 | >>> | |
| UT_inductor_Part_03 | 🛑 | >>> | |
| UT_inductor_Part_04 | 🛑 | >>> | |
| UT_DIST_ARM_Part_01 | 🛑 | >>> | |
| UT_DIST_ARM_Part_02 | 🛑 | >>> | |
| UT_DIST_ARM_Part_03 | 🛑 | >>> | |
| UT_DIST_ARM_Part_04 | 🛑 | >>> | |
| UT_ARM_A2_Select_Part_01 | ✅ | >>> | |
| UT_ARM_A2_Select_Part_02 | ✅ | >>> | |
| 流水线 | PR-pipeline_pytorch | ✅ | >>> |
- compile、compile_inductor、compile_torchair : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


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.


这个check应该可以放到if (aclnnReselectStaticKernelWithPathFunc == nullptr)内部


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.




【合入来源】
【修改方案】
【资料变更】
【接口变更】
【功能验证】
【CheckList】