Files
TorchNPU/generate_code.sh
T
Dring 121d44edf1 [master][refactor]CANN ACL headers decouple
Co-authored-by: Dring<17737727613@163.com>



# message auto-generated for no-merge-commit merge:
!36009 merge master into master

[master][refactor]CANN ACL headers decouple

Created-by: Dring
Commit-by: Dring
Merged-by: ascend-robot
Description: <!--
PR描述模板更新日期:20260203
-->

# 【合入来源】
> <font color="red">**如有社区issue,请关联issue链接**</font>\
https://gitcode.com/Ascend/pytorch/issues/2042
> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font>

- [✓ ] 需求
- [ ] 问题单
- [ ] issue/工单
- [✓ ] 重构优化
- [ ] 资料更新

# 【修改方案】
> 请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列\
> 如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)
cann已开源,PTA在编译过程中动态获取CANN头文件,避免本地保存的头文件与CANN开源版本存在差异导致上层应用编译异常。
![image.png](https://raw.gitcode.com/user-images/assets/7404318/b3364c14-c598-475f-a7ca-d9336bbe6e53/image.png 'image.png')
核心逻辑:
2.10以下分支保留开源头文件中没有的头文件,2.10以上分支原头文件全部删除,拉取的开源头文件进行复制覆盖
2.10以上分支检查 third_party/acl/inc/acl/ 是否已有内容,有则跳过(幂等)
按优先级复制头文件到 third_party/acl/inc/acl/(先 runtime,后 ge 覆盖,再super_kernel.h)
删除临时目录

# 【资料变更】
> 请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”
不涉及

# 【接口变更】
> 请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”
不涉及

# 【功能验证】
> 说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤\
> 新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
编包成功,没有本地文件找不到的头文件符号
![image.png](https://raw.gitcode.com/user-images/assets/7404318/75916028-66e1-4d24-ba7f-ed0bb2d7ab25/image.png 'image.png')
安装成功
初始化无报错:
![image.png](https://raw.gitcode.com/user-images/assets/7404318/77803f3f-3f69-4594-9460-dc0118f4c0b8/image.png 'image.png')

# 【CheckList】
> PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

- [✓ ] 代码注释完备,正确记录错误日志
- [✕ ] 代码实现进行了返回值、空指针等校验
- [✓ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等
- [✓ ] PR持续集成流水线(CI)执行通过,代码检查无异常


See merge request: Ascend/pytorch!36009
2026-05-21 19:18:31 +08:00

82 lines
2.6 KiB
Bash

#!/bin/bash
set -e
CDIR="$(cd "$(dirname "$0")" ; pwd -P)"
cd $CDIR
python_execute="$1"
pytorch_version="$2"
IFS='.' read -ra version_parts <<< "$pytorch_version"
pytorch_dir="v${version_parts[0]}r${version_parts[1]}"
# Fetch ACL headers from submodule paths
ACL_DEST="$CDIR/third_party/acl/inc/acl"
echo " --- Fetching ACL headers from submodules..."
ACL_SRC="$CDIR/third_party/acl_src"
# Copy runtime headers (lower priority, copied first)
if [ -d "$ACL_SRC/runtime/include/external/acl" ]; then
mkdir -p "$ACL_DEST"
cp -r "$ACL_SRC/runtime/include/external/acl/"* "$ACL_DEST/"
echo " --- Copied runtime acl headers"
fi
# Copy ge headers (higher priority, overwrites runtime)
if [ -d "$ACL_SRC/ge/inc/external/acl" ]; then
mkdir -p "$ACL_DEST"
cp -r "$ACL_SRC/ge/inc/external/acl/"* "$ACL_DEST/"
echo " --- Copied ge acl headers"
fi
# Copy super_kernel.h from graph-autofusion
SUPER_KERNEL_SRC="$ACL_SRC/graph-autofusion/super_kernel/include/super_kernel/super_kernel.h"
if [ -f "$SUPER_KERNEL_SRC" ]; then
cp "$SUPER_KERNEL_SRC" "$ACL_DEST/super_kernel.h"
echo " --- Copied super_kernel.h"
fi
# Clean up submodule working directories
rm -rf "$ACL_SRC"
echo " --- Cleaned up acl_src submodule directories"
echo " --- ACL headers fetched successfully"
file=$CDIR/third_party/op-plugin/gencode.sh
if [ -f "${file}" ]; then
bash ${file} ${pytorch_version} ${python_execute}
fi
op_plugin_config_path=$CDIR/third_party/op-plugin/op_plugin/config/$pytorch_dir
source_yaml="$CDIR/torch_npu/csrc/aten/npu_native_functions.yaml"
testing_source_yaml="$CDIR/test/ops_unsupport_list.yaml"
op_plugin_functions_yaml_path="$op_plugin_config_path/npu_native_functions.yaml"
${python_execute} -m torchnpugen.gen_backend_stubs \
--output_dir="torch_npu/csrc/aten" \
--source_yaml="$source_yaml" \
--impl_path="$CDIR/torch_npu/csrc/aten" \
--op_plugin_impl_path="$CDIR/third_party/op-plugin/op_plugin/ops" \
--op_plugin_yaml_path="$op_plugin_config_path/op_plugin_functions.yaml"
${python_execute} -m torchnpugen.autograd.gen_autograd \
--out_dir="$CDIR/torch_npu/csrc/aten" \
--autograd_dir="$CDIR/torchnpugen/autograd" \
--npu_native_function_dir="$source_yaml"
${python_execute} -m torchnpugen.codegen_ops_info
if [ -f $CDIR/third_party/op-plugin/codegen/templates/_op_plugin_docs.py ]; then
if [ -f $CDIR/torch_npu/_op_plugin_docs.py ]; then
# remove _op_plugin_docs.py
rm $CDIR/torch_npu/_op_plugin_docs.py
echo "Existing _op_plugin_docs.py in torch_npu deleted."
fi
cp -f $CDIR/third_party/op-plugin/codegen/templates/_op_plugin_docs.py $CDIR/torch_npu/_op_plugin_docs.py
fi