Merged
fix: JIT编译include路径CANN优先于torch_npu修复新dtype枚举不可见报错 #13155
fix: JIT编译include路径CANN优先于torch_npu修复新dtype枚举不可见报错 #13155
Merged
huangbolinAdd on Sep 28
huangbolin
huangbolinCollaborators
Sep 28

描述

fix: JIT编译include路径CANN优先于torch_npu修复新dtype枚举不可见报错

关联的Issue

https://gitcode.com/cann/ops-transformer/issues/5221

测试

文档更新

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for huangbolin's contribution.)
huangbolinhuangbolinCollaborators
Sep 28 Created pull request, commit af0eac11
atomgit-bot
atomgit-bot
Sep 28 Comments:

变更摘要

本 PR 修复 JIT 编译时 include 路径顺序问题:torch_npu 自带的 third_party/acl 版本较旧,与新版 CANN 头文件共用同名 include guard,若在 -I 搜索顺序中排在前面,会导致环境上实际安装的 CANN 头文件(含 ACL_FLOAT8_E5M2、ACL_FLOAT4_E2M1 等新 dtype 枚举)被抑制而编译报错。改动通过让 CANN 路径优先于 torch_npu 路径,并与 aclnn_common.h 的 include 顺序调整互相配合,确保新枚举可见。

主要改动

  • 调整 OpBuilder.include_paths() 的搜索顺序:将 os.path.join(self._cann_path, "include") 与 include/aclnnop 前移到 torch_npu 各路径之前,保证编译期 -I 顺序先命中环境上安装的 CANN 头文件;vendor 的 op_api/include 仍保持最优先,以覆盖 CANN 同名 aclnn 头。
  • 简化 get_cann_path() 取值逻辑:由先判断 ASCEND_HOME_PATH in os.environ 再读取环境变量,改为通过 os.environ.get 取值并校验路径存在,无法获取时仍回退到 torch_npu 所在目录的上级。
  • 补充 aclnn_common.h 的注释说明:明确该文件仅调整 include 顺序属必要条件之一,<acl/acl_base.h> 能否解析到实际安装的 CANN 头文件还取决于 -I 搜索顺序,需与 OpBuilder.include_paths() 的改动共同生效。
  • 整理 builder.py 的导入风格:将 torch、torch.library.Library、torch.utils.cpp_extension.load 的 import 重新分组排序,无行为影响。
likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Sep 28 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Sep 28 Comments:

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.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
9.2.0 ✅ hanxiaolong, 蒋礼锐 (2/2) ✅ hanxiaolong (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

hblnb, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
huangbolinhuangbolinCollaborators
Sep 28 Associated issue: [Bug-Report|缺陷反馈]:
CANN-robotCANN-robotCollaborators
Sep 28 Set monologue815,jiang-lirui,Allan_Yu,TianXL,liudan12,jiangtao_rts,gitcode-chenjiao,hanxiaolong,mabing1118,gcw_kUomxQ2l,Andy-lb as approver
CANN-robotCANN-robotCollaborators
Sep 28 Set TianXL,jiangtao_rts,gitcode-chenjiao,hanxiaolong,gcw_kUomxQ2l,Andy-lb as approver
huangbolinhuangbolinCollaborators
Sep 28 Modify description of pull request
huangbolin
huangbolinCollaborators
Sep 28 Comments:

compile

likedislike
huangbolinhuangbolinCollaborators
Sep 28 Pre merge succeeded (commit_id: 2470dce7f5070dce74500ad751a389e2eade546f)
CANN-robot
CANN-robotCollaborators
Sep 28 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Sep 28 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 28 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 28 Added label: ci-pipeline-passed
jiang-liruiCollaborators
Sep 29 Comments:

/approve
/lgtm

likedislike
shaneCollaborators
Sep 29 Comments:

/lgtm
/approve

likedislike
CANN-robot
CANN-robotCollaborators
Sep 29 Comments:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
/approve: 蒋礼锐

likedislike
CANN-robotCANN-robotCollaborators
Sep 29 Added label: lgtmapproved
CANN-robotCANN-robotCollaborators
Sep 29 Merged pull request