已合并
[v2.11.0-26.1.0][bugfix]cann and pta header mixing bulid bugfix #44999
Dring创建于 6 天前
[v2.11.0-26.1.0][bugfix]cann and pta header mixing bulid bugfix #44999
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 Dring 的贡献)ascend-robot
6 天前 评论:
6 天前 评论:
atomgit-bot
6 天前 评论:
6 天前 评论:
变更摘要
本 PR 修复 CANN 与 PTA 头文件混用导致的构建问题:将 ACL 头文件从按仓库物理路径 third_party/acl/inc/... 引用的方式,改为构建时把 ACL 头文件树整体复制到公共 include 根目录,并让全部源码统一使用 <acl/...>、<aml/...>、<graph/...>、<experiment/msprof/...> 等公共 include 形式,同时让 stub 库构建脚本支持外部传入 ACL include 目录,避免安装后头文件路径错位。
主要改动
- 构建脚本递归复制 ACL 头文件树:
setup.py与build_libtorch_npu.py删除原先按固定层级复制third_party/acl/inc/*/*.h、*/*/*.h的规则,改为用glob.glob(..., recursive=True)递归复制整个 ACL include 树到build/packages/torch_npu/include/libtorch_npu/include,使源码可统一使用<acl/...>、<aml/...>、<profiling/...>、<graph/...>引用。 - 全仓 include 路径统一:大量核心头文件/源文件(如
AclInterface.h、NPUStream.h、NPUCachingAllocator.cpp、NpuUtils.h、hccl.h、NPUDefinition.h、cpp_common.h等)将third_party/acl/inc/...形式的 include 改为<acl/acl.h>、<acl/acl_rt.h>、<graph/operator.h>、<aml/aml_fwk_detect.h>、<experiment/msprof/toolchain/prof_api.h>等公共路径。 - stub 构建脚本参数化:
third_party/acl/libs/build_stub.sh新增ACL_INCLUDE_DIR参数(默认../inc),所有 gcc 编译 stub 库命令改用-I"${ACL_INCLUDE_DIR}";test/test_npu_expandable_segments.py、test/allocator/test_pluggable_allocator_extensions.py、test/test_sanitizer_pluggable_allocator.py调用该脚本时传入安装后的include目录,并移除原先追加的include/third_party/acl/incinclude 路径。 - include 路径与细节清理:
torch_npu/utils/cpp_extension.py、torch_npu/_inductor/cpp_builder.py、torch_npu/_inductor/ascend_npu_ir/npu/utils.py、ci/access_control_test.py等移除指向include/third_party/acl/inc的 include 目录(cpp_extension.py同时删除未使用的import torch);另修正了若干文件末尾缺换行及注释拼写(discrepency→discrepancy)问题。


atomgit-bot
6 天前 评论:
6 天前 评论:
6 天前 添加了label:ascend-cla/yes
此处折叠了84条消息 查看更多
5 天前 添加了label:approved
5 天前 添加了label:lgtm
5 天前 合入了pull request
ascend-robot
4 天前 评论:
4 天前 评论:
流水线 pytorch_gitcode_PR_multiVersion#14423 [ commitID:622e84d5 ] 已完成


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