Merged
torch extension support custom path #8023
丛吉钰Add on Jul 28
torch extension support custom path #8023
Merged
丛吉钰Add on Jul 28
丛吉钰
丛吉钰Collaborators
Jul 28

描述

变更摘要
此 PR 为 OpBuilder 类新增了对自定义算子包(OPP)路径的支持,允许用户通过环境变量 ASCEND_CUSTOM_OPP_PATH 指定额外的算子包安装目录,同时自动扫描 CANN 内置的 vendors 目录。这些自定义路径的头文件和库文件会被自动纳入编译的 include 路径和链接参数中,从而支持子包级别的算子扩展安装。

主要改动

新增 _custom_opp_paths() 方法:在 OpBuilder 类中新增私有方法,通过读取环境变量 ASCEND_CUSTOM_OPP_PATH(支持 os.pathsep 分隔的多路径)并扫描 <cann_path>/opp/vendors/ 下的子目录,汇总所有自定义算子包路径。
扩展 include_paths() 方法:在原有 include 路径列表末尾追加每个自定义路径下的 op_api/include 子目录(若存在),使自定义算子的头文件可被编译发现。
扩展链接参数(extra_ldflags):在链接参数中追加每个自定义路径下的 op_api/lib 目录,添加 -L 库搜索路径,确保自定义算子库可被正确链接和加载。

关联的Issue

#4238

测试

主线CANN包+新算子自行编译子包安装,成功找到算子。

文档更新

类型标签

AI/Agent生成声明

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for 丛吉钰's contribution.)
丛吉钰丛吉钰Collaborators
Jul 28 Created pull request, commit 06854e4c
atomgit-bot
atomgit-bot
Jul 28 Comments:

变更摘要

此 PR 为 OpBuilder 类新增了对自定义算子包(OPP)路径的支持,允许用户通过环境变量 ASCEND_CUSTOM_OPP_PATH 指定额外的算子包安装目录,同时自动扫描 CANN 内置的 vendors 目录。这些自定义路径的头文件和库文件会被自动纳入编译的 include 路径和链接参数中,从而支持子包级别的算子扩展安装。

主要改动

  • 新增 _custom_opp_paths() 方法:在 OpBuilder 类中新增私有方法,通过读取环境变量 ASCEND_CUSTOM_OPP_PATH(支持 os.pathsep 分隔的多路径)并扫描 <cann_path>/opp/vendors/ 下的子目录,汇总所有自定义算子包路径。
  • 扩展 include_paths() 方法:在原有 include 路径列表末尾追加每个自定义路径下的 op_api/include 子目录(若存在),使自定义算子的头文件可被编译发现。
  • 扩展链接参数(extra_ldflags):在链接参数中追加每个自定义路径下的 op_api/lib 目录,添加 -L 库搜索路径和 -Wl,-rpath 运行时库搜索路径,确保自定义算子库可被正确链接和加载。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Jul 28 Comments:

代码审查

现在我已经完成了对该差异的全面审查。以下是总结。


审查总结

审查文件: torch_extension/cann_ops_nn/op_builder/builder.py — 已审查,发现 2 个问题。

优先级 数量
P0 0
P1 0
P2 1
P3 1

总体风险评估:低风险。 该变更引入了一个新的 _custom_opp_paths() 辅助方法并在 include_paths() 和 extra_ldflags() 中使用,以支持通过 ASCEND_CUSTOM_OPP_PATH 环境变量和 <cann_path>/opp/vendors 目录加载自定义算子包路径。核心逻辑正确,两个已报告的问题均为可修复的工程健壮性问题,不影响当前正常使用场景下的功能正确性。

⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Jul 28 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Jul 28 Comments:

CLA Signature Pass

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

likedislike
77 messages are collapsed here。 See more
丛吉钰丛吉钰Collaborators
Jul 29 Modify description of pull request
tangweiwei2
tangweiwei2Collaborators
Jul 29 Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
Jul 29 Added label: lgtm
CANN-robotCANN-robotCollaborators
Jul 29 Merged pull request
CANN-robot
CANN-robotCollaborators
Jul 29 Comments:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike