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

描述

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 29 Created pull request, commit 2b1d2c84
huangbolinhuangbolinCollaborators
Sep 29 Associated issue: [Bug-Report|缺陷反馈]:
atomgit-bot
atomgit-bot
Sep 29 Comments:

变更摘要

本 PR 修复 JIT 编译时因头文件搜索路径顺序导致的“新 dtype 枚举不可见”编译报错。问题根因在于 torch_npu 自带的 third_party/acl 版本较旧,且与新版 CANN 头文件共用同名 include guard,一旦在 -I 搜索顺序中先命中旧副本,环境上实际安装的 CANN 头文件(包含 ACL_FLOAT8_E5M2、ACL_FLOAT4_E2M1 等新枚举)就会被 include guard 抑制,从而编译失败。改动主要在 OpBuilder.include_paths() 中将 CANN 路径调整到 torch_npu 路径之前,并同步补充相关注释说明。

主要改动

  • 调整 JIT 编译的 include 搜索顺序: 在 torch_extension/cann_ops_transformer/op_builder/builder.py 的 include_paths() 中,将 os.path.join(self._cann_path, "include") 与 os.path.join(self._cann_path, "include/aclnnop") 移动到 torch_npu 相关路径之前,使 <acl/acl_base.h> 优先解析到环境实际安装的新版 CANN 头文件,修复新 dtype 枚举不可见报错。
  • 明确 vendor 路径优先级: 保留 vendor op_api/include 为最高优先级,使 run 包中增强算子的 aclnn 头文件仍能覆盖 CANN 同名头。
  • 重构 get_cann_path() 实现: 由原先的 ASCEND_HOME_PATH in os.environ and os.path.exists(...) 组合判断改为 os.environ.get(ASCEND_HOME_PATH) 后再判空与存在性,行为语义不变但写法更简洁。
  • 补充 aclnn_common.h 的依赖说明注释: 说明仅调整 include 顺序只是必要条件之一,还需依赖编译期 -I 搜索顺序由 OpBuilder.include_paths() 将 CANN 排在 torch_npu 之前,两者缺一不可。
likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Sep 29 Added label: cann-cla/yes
huangbolin
huangbolinCollaborators
Sep 29 Comments:

compile

likedislike
CANN-robot
CANN-robotCollaborators
Sep 29 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
sig-ops-transformer ✅ 蒋礼锐, 马兵 (2/2) ✅ 蒋礼锐, 马兵 (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)
likedislike
CANN-robot
CANN-robotCollaborators
Sep 29 Comments:

CLA Signature Pass

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

likedislike
huangbolinhuangbolinCollaborators
Sep 29 Pre merge succeeded (commit_id: c25e9fd57bd80c13a657f7cee46370fc380747f1)
CANN-robotCANN-robotCollaborators
Sep 29 Set monologue815,jiang-lirui,Allan_Yu,liudan12,mabing1118 as approver
CANN-robotCANN-robotCollaborators
Sep 29 Set monologue815,jiang-lirui,Allan_Yu,liudan12,mabing1118 as approver
CANN-robot
CANN-robotCollaborators
Sep 29 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Sep 29 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 29 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 29 Added label: ci-pipeline-passed
shaneCollaborators
Sep 29 Comments:

/lgtm
/approve

likedislike
jiang-liruiCollaborators
Sep 29 Comments:

/approve
/lgtm

likedislike
CANN-robotCANN-robotCollaborators
Sep 29 Added label: approved
mabingCollaborators
Sep 29 Comments:

/approve
/lgtm

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: hanxiaolong
/lgtm: hanxiaolong

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