Closed
[Bug-Report|缺陷反馈]: #5221
einspiAdd on  Sep 11Closed at  Sep 29
einspi
Sep 11 Create

Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.

Describe the current behavior / 问题描述 (Mandatory / 必填)

为自定义算子开发torch extension时,安装完run包和whl包执行python测试时,JIT编译阶段出现多处数据枚举类型不可见的报错。

Environment Information / 环境信息 (Mandatory / 必填)

CANN 8.5.1
升腾910B
python版本3.11.14

Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)

5b47fbe246244e6d95d22c4397141e91.zip

此为我开发的自定义算子源码包,可按照教程正确出run包,可正确出whl包,在环境上安装whl包以后,运行测试时,JIT编译报错
6680071c4c68452697d45777ba45088c.txt

疑似和最新aclnn_common.h中的一些注释强关联
https://gitcode.com/cann/ops-transformer/blob/master/torch_extension/cann_ops_transformer/common/aclnn_common.h#L23

我之前老版本确实没有把<acl/acl_base.h>提前,但提前以后仍然有同样的问题!

Describe the expected behavior / 预期结果 (Mandatory / 必填)

预期应该能正确感知到位于环境中的 /usr/local/Ascend/cann-8.5.1/include/acl/acl_base.h,然后导入 /usr/local/Ascend/cann-8.5.1/include/acl/acl_base_rt.h,这里面明确写了那些枚举!

86c381f51c304993bf3bafb9282c1609.txt

Special notes for this issue/备注 (Optional / 选填)

likedislike
游震Collaborators
Sep 11 Comments:

已收到反馈,正在处理

likedislike
einspi
Sep 11 Comments:

已收到反馈,正在处理

@youzhen5418

本bug已暂时被解决(绕开),解决方法:
在算子源码的torch_extension\received_attention.py的class ReceivedAttentionOpBuilder(OpBuilder):中,覆盖OpBuilder的include_paths方法如下:
def include_paths(self):
"""Prefer the active CANN ACL headers over torch_npu's bundled copy."""
paths = super().include_paths()
if not self._cann_path:
return paths
cann_include = os.path.normpath(os.path.join(self._cann_path, "include"))
remaining_paths = [
path
for path in paths
if os.path.normpath(path) != cann_include
]
return [cann_include, *remaining_paths]

本方法通过提前cann包含路径,让试图包含<acl/acl_base.h>包含到正确文件,如果不修改,-I优先级会导致包含的是torch_npu第三方包含路径下的一篇同名文件,该文件中不存在我们需要的枚举所以报错。
但本修改显然是一个绕行。共有代码OpBuilder明显期望torch_npu第三方包含路径下的那篇acl_base.h声明了那些枚举。但因版本问题,我的这些枚举不在这个位置。希望官方能够更清晰正确澄清版本问题

likedislike
游震Collaborators
Sep 11 Comments:

/assign @youzhen5418

likedislike
CANN-robotCANN-robotCollaborators
Sep 11 Assign youzhen5418 as responsible person
Wweihao18Collaborators
Sep 21 Associated pull request
Wwang-minboCollaborators
Sep 28 Assign hblnb as responsible person
huangbolinhuangbolinCollaborators
Sep 28 Associated pull request
huangbolinhuangbolinCollaborators
Sep 29 Removed responsible person hblnb
huangbolinhuangbolinCollaborators
Sep 29 Assign hblnb as responsible person
huangbolinhuangbolinCollaborators
Sep 29 Associated pull request
shaneCollaborators
Sep 29 Comments:

/lgtm
/approve

likedislike
Wwang-minboCollaborators
Sep 29 changed custom state from 进行中 to 已完成
Wwang-minboCollaborators
Sep 29 Close issue
周云飞
周云飞Collaborators
26 days ago Comments:

您好,感谢反馈!您给出的提前 CANN include 路径的绕行对应了实际修正方向。这里有两层顺序:源文件应先包含 acl/acl_base.h;编译器的 -I 搜索顺序也应先命中当前 CANN 的 ACL 头文件。只改源文件中的 include 位置,仍可能从 TorchNPU 的第三方路径选到同名旧头文件,同名 include guard 会使后续新版头文件被跳过。

关联 PR !13176 已合入 master,PR !13155 已合入 9.2.0 分支;两者将公共 OpBuilder 的 CANN include 路径前移至 TorchNPU 路径之前,同时保留 vendor 的 op_api/include 优先级,并补充上述顺序说明。cann/ops-transformer 提交 29f3b8185af2ce772af1ba7b9ddf2b47f2100a01 中,可核对 公共 include_paths 和 头文件说明。

这解决的是头文件选择顺序,不会为旧 CANN 新增本来不存在的枚举,也不等同于声明 CANN 8.5.1 与任意 TorchNPU/当前扩展源码兼容。实际选择的 CANN 来自有效的 ASCEND_HOME_PATH,未指定有效路径时源码会回退推导路径;因此使用该修正时仍需对应当前 CANN 的真实头文件。报告中的 8.5.1 环境和附件未在本次重新编译验证,不能给出其全套版本兼容保证。

likedislike