Files
TorchNPU/test/cpp_extensions/setup.py
T
zhucehw 3de4e3fb0d [Inductor] master branch support AOTI and cpp_wrapper
Co-authored-by: qiaoyaodan888<qiaoyaodan@huawei.com>
Co-authored-by: zhuceHW<zhuce@huawei.com>



# message auto-generated for no-merge-commit merge:
!42521 merge main-0720 into master

[Inductor] master branch support AOTI and cpp_wrapper

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

# 【合入来源】
https://gitcode.com/Ascend/pytorch/issues/2526?ref=&did=4121203#tid-4121203

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

# 【修改方案】
1. add cpp_wrapper and AOTI support for master branch
2. sync files from torch2.13 aoti_runtime and aoti_torch
3. format c++ file whitespace num
4. skip lazy compile for cpp_wrapper

# 【资料变更】
不涉及

# 【接口变更】
不涉及

# 【功能验证】
CI PASS

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

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


See merge request: Ascend/pytorch!42521
2026-07-25 09:42:55 +08:00

45 lines
1.5 KiB
Python

import os
from setuptools import setup
from torch.utils.cpp_extension import BuildExtension
from torch_npu.utils.cpp_extension import NpuExtension
from torch_npu.testing.common_utils import set_npu_device
set_npu_device()
CXX_FLAGS = ['-g', '-DUSE_NPU']
USE_NINJA = os.getenv('USE_NINJA') == '1'
REPO_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
SHIM_SOURCE = os.path.join(
REPO_ROOT, "torch_npu", "csrc", "inductor", "aoti_torch", "shim_npu.cpp"
)
ext_modules = [
NpuExtension(
'torch_test_cpp_extension.npu', ['extension.cpp'],
extra_compile_args=CXX_FLAGS),
NpuExtension(
'torch_test_cpp_extension.npu_from_blob', ['test_from_blob.cpp'],
extra_compile_args=CXX_FLAGS),
NpuExtension(
'torch_test_cpp_extension.npu_external_stream', ['external_stream_test.cpp'],
extra_compile_args=CXX_FLAGS),
NpuExtension(
'torch_test_cpp_extension.stable_libtorch', ['test_stable_libtorch.cpp'],
extra_compile_args=CXX_FLAGS),
NpuExtension(
'torch_test_cpp_extension.npu_aoti_shim',
['npu_aoti_shim_extension.cpp', SHIM_SOURCE],
include_dirs=[REPO_ROOT],
extra_compile_args=CXX_FLAGS),
]
setup(
name='torch_test_cpp_extension',
packages=['torch_test_cpp_extension'],
ext_modules=ext_modules,
include_dirs='self_compiler_include_dirs_test',
cmdclass={'build_ext': BuildExtension.with_options(use_ninja=USE_NINJA)})