Pull Request已成功合入, 合并人@ascend-robot
(感谢 ffmh 的贡献)变更摘要
该 PR 修复 PTA 26.1.0(内置 CANN 9.1.0 头文件)与编译环境 CANN 9.0.0 头文件混用的构建问题(关联 issue #3991)。根因是源码中大量使用 #include "third_party/acl/inc/..." 仓库物理路径,导致首层头文件命中 PTA 内置版本、传递头文件按 -I 顺序命中环境 CANN 版本,形成混合查找。修改方案为:源码统一改为从 include root 按 <acl/...>、<aml/...>、<graph/...>、<profiling/...> 方式查找 CANN 头文件,打包/安装时将 third_party/acl/inc 下头文件按原相对结构复制到安装产物公共 include 根目录,并保留旧路径的转发头文件以兼容历史 include 写法;同时顺带调整了部分 32GB 芯片上的测试用例。
主要改动
- 统一 CANN 头文件查找方式:在
torch_npu/csrc下约 60 个源文件中,将"third_party/acl/inc/acl/acl.h"、"third_party/acl/inc/acl/acl_base.h"、"third_party/acl/inc/acl/acl_rt.h"等物理路径写法批量改为<acl/acl.h>、<acl/acl_base.h>、<acl/acl_rt.h>形式(含acl_mdl.h、acl_prof.h、acl_op_compiler.h、super_kernel.h、error_codes/rt_error_codes.h,以及aml/aml_fwk_detect.h、graph/operator.h、profiling/prof_api.h等),third_party/hccl/inc/hccl/hccl.h中的#include "third_party/acl/inc/acl/acl.h"同步改为<acl/acl.h>。 - 打包与安装产物头文件布局调整:
setup.py与build_libtorch_npu.py不再按third_party/acl/inc/*/*.h等固定 glob 复制 ACL 头文件,改为递归收集third_party/acl/inc下全部*.h,按相对路径复制到安装产物include/根目录,并为每个头文件在旧路径include/third_party/acl/inc/...生成仅含#pragma once与#include <...>的转发头文件,保证旧 include 路径兼容。 - 构建工具与扩展编译的 include 路径统一:
torch_npu/csrc/inductor/cpp_builder.py的include_paths、torch_npu/utils/cpp_extension.py的NpuExtension、torch_npu/_inductor/ascend_npu_ir/npu/utils.py均移除include/third_party/acl/inc这一独立 include 目录,统一使用公共include根目录;third_party/acl/libs/build_stub.sh新增ACL_INCLUDE_DIR参数(默认../inc),stub 编译与 Extension 编译共用同一安装头文件根目录,并加set -e;ci/access_control_test.py中安装 ACL 头文件查找路径由include/third_party/acl/inc/acl改为include/acl。 - 相关测试用例适配:
test/allocator/test_pluggable_allocator_extensions.py、test/test_npu_expandable_segments.py、test/test_sanitizer_pluggable_allocator.py在build_stub中传入安装 include 路径并移除third_party/acl/incinclude 目录,pluggable_allocator_extensions.cpp同步改用<acl/acl_base.h>、<acl/acl_rt.h>。 - 32GB 芯片测试用例调整:
test/distributed/rpc/test_single_machine_multi_devices.py中test_async_call_for_cpu的 tensor 由torch.rand(1024, 1024, 1024)调小为torch.rand(1024, 1024, 4),test/test_npu_expandable_segments.py中test_pluggable_allocator的 tensor 由(7500, 1024, 1024)调小为(5000, 1024, 1024),test/distributed/test_fault_mode.py移除了对"wait for compute device to finish failed"错误文案的断言。


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.
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| ci | ✅ chujinjin, liangsongwei (2/2) | ✅ chujinjin, liangsongwei (2/1) |
| repo-Ascend/pytorch | ✅ chujinjin, liangsongwei (2/2) | ✅ chujinjin, liangsongwei (2/1) |
| test | ✅ chujinjin, liangsongwei (2/2) | ✅ chujinjin, liangsongwei (2/1) |
| torch_npu/_inductor | ✅ chujinjin, liangsongwei (2/2) | ✅ chujinjin, liangsongwei (2/1) |
| torch_npu/csrc/distributed | ✅ chujinjin, liangsongwei (2/2) | ✅ chujinjin, liangsongwei (2/1) |
| torch_npu/csrc/inductor | ✅ liangsongwei, chujinjin (2/2) | ✅ chujinjin, liangsongwei (2/1) |
| torch_npu/csrc/profiler | ✅ chujinjin, liangsongwei (2/2) | ✅ chujinjin, liangsongwei (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
ffmh, thanks for your pull request. All authors of the commits have signed the CLA. 👍


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


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | Build_X86 | ✅ | >>> |
| Build_ARM | ✅ | >>> | |
| Build_X86_torchair | 🛑 | >>> | |
| Build_ARM_torchair | 🛑 | >>> | |
| patch_test | 🛑 | >>> | |
| Build_X86_213 | 🛑 | >>> | |
| Build_ARM_213 | 🛑 | >>> | |
| 恶意代码检查 | Antipoison | ✅ | >>> |
| 编码安全与规范检查 | codecheck_pre-commit | ✅ | >>> |
| check_error | ✅ | >>> | |
| lintrunner | ✅ | >>> | |
| 开源片段检查 | SCA | ✅ | >>> |
| 开发者测试 | 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 | ✅ | >>> | |
| UT_ARM_A2_Part_01_213 | 🛑 | >>> | |
| UT_ARM_A2_Part_02_213 | 🛑 | >>> | |
| UT_ARM_A2_Part_03_213 | 🛑 | >>> | |
| UT_inductor_Part_01_213 | 🛑 | >>> | |
| UT_inductor_Part_02_213 | 🛑 | >>> | |
| UT_inductor_Part_03_213 | 🛑 | >>> | |
| UT_inductor_Part_04_213 | 🛑 | >>> | |
| UT_DIST_ARM_Part_01_213 | 🛑 | >>> | |
| UT_DIST_ARM_Part_02_213 | 🛑 | >>> | |
| UT_DIST_ARM_Part_03_213 | 🛑 | >>> | |
| UT_DIST_ARM_Part_04_213 | 🛑 | >>> | |
| UT_ARM_A2_Select_Part_01_213 | 🛑 | >>> | |
| UT_ARM_A2_Select_Part_02_213 | 🛑 | >>> | |
| 流水线 | PR-pipeline_pytorch | ✅ | >>> |
- compile、compile_inductor、compile_torchair : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线


/approve




【合入来源】
https://gitcode.com/Ascend/pytorch/issues/3991
【修改方案】
问题现象:
PTA 26.1.0 仓库中的 third_party/acl 头文件来自 CANN 9.1.0,而编译环境安装的是 CANN 9.0.0。当同一个编译单元同时包含两套版本的 ACL 头文件时,会出现类似以下错误:aclmdlRITask 未声明、未定义或类型不匹配
aclmdlRITask 是 CANN 9.1.0 头文件所依赖的定义,但 CANN 9.0.0 对应头文件中不存在该定义或定义不兼容。
根因分析:
1 当前头文件查找路径不统一:PTA 源码中大量使用以下写法
#include "third_party/acl/inc/acl/acl_mdl.h"
因为编译命令中包含 PTA 项目根目录,这种写法会直接命中 PTA 26.1.0 仓库内由 CANN 9.1.0 导入的头文件:torch_npu/third_party/acl/inc/acl/acl_mdl.h
但该头文件内部使用的是标准 SDK 相对路径:#include "acl/acl_base.h"
编译器无法相对 acl_mdl.h 所在目录找到 acl/acl_base.h,因此转而按照全部 -I 目录依次搜索。如果 CANN 9.0.0 的 include 路径排在 PTA 内置 ACL 路径前面,就会命中:CANN-9.0.0/include/acl/acl_base.h
同一个翻译单元最终形成:
acl_mdl.h -> PTA third_party 中的 CANN 9.1.0 版本
acl_base.h -> 环境 CANN 9.0.0 版本
这是一种“首层头文件由源码路径固定版本、传递头文件由 -I 顺序选择版本”的混合查找模式。
2 问题不局限于 acl_mdl.h
同样风险存在于所有能够继续 include 其他 CANN 头文件的入口,包括:
acl/...
aml/...
profiling/...
graph/...
ge/...
op_proto/...
因此不能只修复出现错误的某一个头文件,也不能只替换 acl_mdl.h。必须统一整个 CANN 头文件族的查找规则。
修改目标:
修改后需要满足
源码不再包含 third_party/acl/inc/... 这种仓库物理路径。
ACL、AML、profiling 等头文件全部通过统一 include root 查找。
一个编译 target 对 CANN 头文件只选择一套版本。
CANN 9.0.0 环境构建时,首层和传递头文件必须全部命中 CANN 9.0.0。
使用 PTA 内置头文件构建时,首层和传递头文件必须全部命中 PTA 内置的同一套版本。
wheel、libtorch_npu、C++ Extension 和 Inductor/AOT 使用同一目录契约
修改方案:
1、代码中使用 PTA 内置 ACL 头文件的地方,删除 third_party/acl/inc/ 物理路径前缀,统一改成从 include root 查找
2、打包或安装时,把 third_party/acl/inc 下需要公开的目录按原相对结构复制到安装产物的公共 include 根目录
【资料变更】
不涉及
【接口变更】
不涉及
【功能验证】
cann 9.0.0 + pta 26.1.0的vllm-ascend安装验证成功

【CheckList】