Pull Request has been successfully merged by CANN-robot.
(Thank you for huangbolin's contribution.)变更摘要
本 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之前,两者缺一不可。


compile


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
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)


| 🚀 CI 流水线已启动 |
|---|
| 📋 执行详情: 点击查看流水线 |


/approve
/lgtm


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


描述
fix: JIT编译include路径CANN优先于torch_npu修复新dtype枚举不可见报错
关联的Issue
https://gitcode.com/cann/ops-transformer/issues/5221
测试
文档更新
类型标签