已合并
[v2.7.1][bugfix]cann and pta header mixing bulid bugfix #44991
Dring创建于 8月20日
[v2.7.1][bugfix]cann and pta header mixing bulid bugfix #44991
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 Dring 的贡献)atomgit-bot
8月20日 评论:
8月20日 评论:
变更摘要
本 PR(v2.7.1 bugfix)修复 CANN 与 PTA(torch_npu)头文件混用导致的构建问题:将全仓 C++ 源码中对 ACL 头文件的 third_party/acl/inc/... 相对路径引用统一改为 <acl/...> 形式,并同步调整 setup.py、build_libtorch_npu.py 等构建打包脚本及测试用例中的头文件拷贝与 include 路径逻辑,使 ACL 头文件以独立目录结构被正确拷贝、安装和引用。
主要改动
- ACL 头文件引用统一为尖括号形式: 涉及
CopyMemoryKernel.cpp、NPUCachingAllocator.cpp、AclInterface.h、NPUStorageImpl.h、NpuUtils.h、NPUGraph.h、ProcessGroupHCCL.cpp、cpp_common.h、npu_profiler.h等数十个文件,将"third_party/acl/inc/acl/acl.h"、acl_base.h、acl_rt.h、acl_op_compiler.h、super_kernel.h、graph/operator.h、profiling/prof_api.h、aml/aml_fwk_detect.h等改为<acl/...>、<graph/operator.h>、<profiling/...>、<aml/...>形式;third_party/hccl/inc/hccl/hccl.h中的#include "third_party/acl/inc/acl/acl.h"也同步改为<acl/acl.h>。 - 构建脚本改为递归拷贝 ACL 头文件:
setup.py的get_src_py_and_dst()与build_libtorch_npu.py的copy_hpp()移除原先非递归的third_party/acl/inc/*/*.h、third_party/acl/inc/*/*/*.h通配规则,改用glob.glob(..., recursive=True)递归收集third_party/acl/inc下全部*.h,并按os.path.relpath保留相对目录结构拷贝到include(build/packages/torch_npu/include/libtorch_npu/include)下,保证<acl/acl.h>等引用可解析。 - include 路径与安装布局适配:
torch_npu/_inductor/cpp_builder.py的include_paths()将 ACL 头文件路径由include/third_party/acl/inc改为include;torch_npu/utils/cpp_extension.py、torch_npu/_inductor/ascend_npu_ir/npu/utils.py移除include/third_party/acl/inc相关 include;ci/access_control_test.py的fetch_acl_headers()将安装目录下的 ACL 头文件来源由include/third_party/acl/inc/acl改为include/acl。 build_stub.sh支持外部 ACL 头文件目录:third_party/acl/libs/build_stub.sh新增ACL_INCLUDE_DIR参数(默认../inc)并传给各gcc编译命令,同时添加set -e;test/allocator/test_pluggable_allocator_extensions.py、test/npu/test_allocator_trace_tracker.py、test/test_npu_expandable_segments.py、test/test_sanitizer_pluggable_allocator.py调用build_stub.sh时传入PYTORCH_NPU_INSTALL_PATH/include作为头文件目录,并移除各自的include/third_party/acl/inc额外 include 路径;test/cpp_extensions/external_stream_test.cpp与pluggable_allocator_extensions.cpp也改用<acl/acl.h>等尖括号引用。


不准确?
ascend-robot
8月20日 评论:
8月20日 评论:
atomgit-bot
8月20日 评论:
8月20日 评论:
8月20日 添加了label:ascend-cla/yes
此处折叠了188条消息 查看更多
25 天前 添加了label:approvedlgtm
25 天前 合入了pull request
ascend-robot
25 天前 评论:
25 天前 评论:
流水线 pytorch_gitcode_PR_multiVersion#14589 [ commitID:9964a409 ] 已完成


【合入来源】
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】